ブロックの修正+ゴーストブロックの追加

守矢諏訪子 <suwako@076.moe>、2026-07-11 20:13
コミット 3dd140a578293272fbbdc04603fb100e91555d90 ・親 726d38f ・ファイルを見る

12個のファイル、+102 -38

バイナリファイル

バイナリファイル

バイナリファイル

バイナリファイル

バイナリファイル

バイナリファイル

バイナリファイル

@@ -1,4 +1,4 @@
1-unsigned char __tetris_block_png[] = {
1+unsigned char __ass_tetris_block_png[] = {
22 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
33 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
44 0x08, 0x03, 0x00, 0x00, 0x00, 0x44, 0xa4, 0x8a, 0xc6, 0x00, 0x00, 0x00,
@@ -8,19 +8,19 @@
88 0xe2, 0x2e, 0xae, 0x81, 0xff, 0x7f, 0xca, 0x15, 0xbb, 0x00, 0x00, 0x00,
99 0x0c, 0x74, 0x52, 0x4e, 0x53, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1010 0xff, 0xff, 0xff, 0xff, 0xff, 0x09, 0xc4, 0x50, 0x26, 0x00, 0x00, 0x00,
11- 0x88, 0x49, 0x44, 0x41, 0x54, 0x38, 0x8d, 0x95, 0xcd, 0x5b, 0x0e, 0xc0,
12- 0x30, 0x08, 0x03, 0x41, 0x43, 0x9a, 0xfb, 0x5f, 0xb9, 0x4a, 0xc9, 0x03,
13- 0x08, 0x20, 0xd5, 0xbf, 0x3b, 0x92, 0xc1, 0x4f, 0x39, 0x42, 0xa7, 0xb2,
14- 0x37, 0xf4, 0x4a, 0x50, 0x1b, 0x20, 0x17, 0xd4, 0x04, 0x64, 0x62, 0x74,
15- 0x01, 0xb1, 0xf8, 0xfa, 0x04, 0x91, 0x90, 0xbe, 0xc0, 0x2d, 0x66, 0xdf,
16- 0xc0, 0x8b, 0xd5, 0x0f, 0xb0, 0x62, 0x77, 0x05, 0xb4, 0x38, 0x5d, 0x83,
17- 0x23, 0x54, 0x37, 0x60, 0x09, 0xdd, 0x2d, 0x10, 0x61, 0xba, 0x03, 0x43,
18- 0xd8, 0xee, 0x41, 0x27, 0xd7, 0x7f, 0x03, 0x62, 0x2e, 0x2f, 0x88, 0xd9,
19- 0x0b, 0x5c, 0xdd, 0x09, 0xdc, 0xdd, 0x0a, 0x04, 0xdd, 0x08, 0x44, 0x5d,
20- 0x0b, 0x84, 0x5d, 0x09, 0xc4, 0xfd, 0x08, 0x24, 0x7d, 0x0b, 0x64, 0x7d,
21- 0x09, 0xa4, 0x7d, 0x0a, 0xe4, 0x5d, 0x04, 0x8a, 0xfe, 0x09, 0x54, 0x7d,
22- 0x08, 0x94, 0x9d, 0x99, 0x5e, 0x52, 0xa1, 0x0d, 0x62, 0x4e, 0x46, 0x2d,
23- 0xb4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
24- 0x82
11+ 0x90, 0x49, 0x44, 0x41, 0x54, 0x38, 0x8d, 0x95, 0xd3, 0x49, 0x0e, 0x04,
12+ 0x31, 0x08, 0x43, 0x51, 0x93, 0x74, 0xee, 0x7f, 0xe5, 0x16, 0x45, 0x06,
13+ 0x20, 0xb8, 0xa4, 0x62, 0xfb, 0x9f, 0xc4, 0xca, 0x00, 0xf0, 0xa3, 0x87,
14+ 0xe7, 0x78, 0x37, 0x31, 0x84, 0x77, 0xe9, 0xc0, 0x18, 0x5c, 0x48, 0xef,
15+ 0x5d, 0x01, 0x13, 0xda, 0x0d, 0xd4, 0xe2, 0xe9, 0x13, 0x54, 0xc2, 0xfa,
16+ 0x02, 0xb7, 0x98, 0x7d, 0x83, 0x2c, 0x56, 0x3f, 0x20, 0x8a, 0xdd, 0x1d,
17+ 0xf0, 0xe2, 0x74, 0x0f, 0x8e, 0x70, 0x3d, 0x80, 0x25, 0x7c, 0x8f, 0xc0,
18+ 0x44, 0xe8, 0x09, 0xa8, 0x88, 0x3d, 0x83, 0x21, 0xa9, 0x7f, 0x06, 0xd2,
19+ 0xda, 0xeb, 0x0b, 0x69, 0x2d, 0x0b, 0x5c, 0x3d, 0x09, 0xdc, 0x3d, 0x0a,
20+ 0x14, 0x3d, 0x08, 0x54, 0xdd, 0x0b, 0x94, 0xdd, 0x09, 0xd4, 0xfd, 0x08,
21+ 0x90, 0xbe, 0x05, 0x58, 0x5f, 0x02, 0xb4, 0x4f, 0x01, 0xde, 0x4d, 0xe8,
22+ 0xf4, 0x58, 0x57, 0xa1, 0xe3, 0xe4, 0xbd, 0x35, 0x9b, 0xf7, 0x6b, 0xff,
23+ 0x03, 0xb9, 0xfb, 0x0d, 0x21, 0xd8, 0x3c, 0xf4, 0x98, 0x00, 0x00, 0x00,
24+ 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
2525 };
26-unsigned int __tetris_block_png_len = 265;
26+unsigned int __ass_tetris_block_png_len = 273;
@@ -16,6 +16,7 @@
1616 void updateBoardLayout();
1717 void drawNextPiece();
1818 void drawHoldPiece();
19+ void drawGhostPiece();
1920 void handleInput();
2021 bool isValidPos(i8 piece, i8 rot, i8 x, i8 y);
2122
@@ -11,6 +11,7 @@
1111
1212 Texture2D LoadTexture(const string &name, const u8 *data, i32 dataSize);
1313 Texture2D GetTexture(const string &name);
14+ void DrawBackground(const string &name, Color tint = WHITE);
1415 void UnloadAll();
1516
1617 private:
@@ -6,6 +6,12 @@
66 #include <algorithm>
77
88 #include <tetris/ass/tex_block.hh>
9+#include <tetris/ass/bg_beach.hh>
10+#include <tetris/ass/bg_city.hh>
11+#include <tetris/ass/bg_mount.hh>
12+#include <tetris/ass/bg_road.hh>
13+#include <tetris/ass/bg_sunset.hh>
14+#include <tetris/ass/bg_waterfall.hh>
915
1016 namespace tetris::scene {
1117 Color tetrominoColors[7] = {
@@ -20,20 +26,13 @@
2026
2127 // [ピース][回転][4ブロック][x,y]
2228 static const i32 tetrominoShapes[7][4][4][2] = {
23- // I
24- {{{0,0},{1,0},{2,0},{3,0}}, {{0,0},{0,1},{0,2},{0,3}}, {{0,0},{1,0},{2,0},{3,0}}, {{0,0},{0,1},{0,2},{0,3}}},
25- // O
26- {{{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}},
27- // S
28- {{{1,0},{2,0},{0,1},{1,1}}, {{0,0},{0,1},{1,1},{1,2}}, {{1,0},{2,0},{0,1},{1,1}}, {{0,0},{0,1},{1,1},{1,2}}},
29- // Z
30- {{{0,0},{1,0},{1,1},{2,1}}, {{1,0},{0,1},{1,1},{0,2}}, {{0,0},{1,0},{1,1},{2,1}}, {{1,0},{0,1},{1,1},{0,2}}},
31- // T
32- {{{1,0},{0,1},{1,1},{2,1}}, {{1,0},{1,1},{1,2},{0,1}}, {{0,1},{1,1},{2,1},{1,0}}, {{1,0},{1,1},{1,2},{2,1}}},
33- // J
34- {{{0,0},{0,1},{1,1},{2,1}}, {{0,0},{1,0},{1,1},{1,2}}, {{0,1},{1,1},{2,1},{2,0}}, {{1,0},{1,1},{1,2},{0,2}}},
35- // L
36- {{{2,0},{0,1},{1,1},{2,1}}, {{0,0},{0,1},{0,2},{1,2}}, {{0,0},{1,0},{2,0},{0,1}}, {{1,0},{1,1},{1,2},{2,0}}}
29+ {{{0,1},{1,1},{2,1},{3,1}}, {{2,0},{2,1},{2,2},{2,3}}, {{0,2},{1,2},{2,2},{3,2}}, {{1,0},{1,1},{1,2},{1,3}}}, // I
30+ {{{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}}, // O
31+ {{{1,0},{2,0},{0,1},{1,1}}, {{0,0},{0,1},{1,1},{1,2}}, {{1,0},{2,0},{0,1},{1,1}}, {{0,0},{0,1},{1,1},{1,2}}}, // S
32+ {{{0,0},{1,0},{1,1},{2,1}}, {{1,0},{0,1},{1,1},{0,2}}, {{0,0},{1,0},{1,1},{2,1}}, {{1,0},{0,1},{1,1},{0,2}}}, // Z
33+ {{{1,0},{0,1},{1,1},{2,1}}, {{1,0},{2,1},{1,2},{1,1}}, {{0,1},{1,1},{2,1},{1,2}}, {{1,0},{1,1},{1,2},{0,1}}}, // T
34+ {{{0,1},{1,1},{2,1},{2,0}}, {{0,0},{0,1},{0,2},{1,2}}, {{0,0},{1,0},{2,0},{0,1}}, {{0,0},{1,0},{1,1},{1,2}}}, // L
35+ {{{0,0},{0,1},{1,1},{2,1}}, {{0,0},{0,1},{0,2},{1,0}}, {{0,0},{1,0},{2,0},{2,1}}, {{1,0},{1,1},{1,2},{0,2}}}, // J
3736 };
3837
3938 Vector2 boardPos = { 0, 0 };
@@ -56,7 +55,13 @@
5655
5756 board.assign(m_VSize, std::vector<i32>(m_HSize, 0));
5857
59- blockTexture = sys::ImgMan::Get().LoadTexture("block", __tetris_block_png, __tetris_block_png_len);
58+ blockTexture = sys::ImgMan::Get().LoadTexture("tx_block", __ass_tetris_block_png, __ass_tetris_block_png_len);
59+ sys::ImgMan::Get().LoadTexture("bg_beach", __ass_bg_beach_png, __ass_bg_beach_png_len);
60+ sys::ImgMan::Get().LoadTexture("bg_city", __ass_bg_city_png, __ass_bg_city_png_len);
61+ sys::ImgMan::Get().LoadTexture("bg_mount", __ass_bg_mount_png, __ass_bg_mount_png_len);
62+ sys::ImgMan::Get().LoadTexture("bg_road", __ass_bg_road_png, __ass_bg_road_png_len);
63+ sys::ImgMan::Get().LoadTexture("bg_sunset", __ass_bg_sunset_png, __ass_bg_sunset_png_len);
64+ sys::ImgMan::Get().LoadTexture("bg_waterfall", __ass_bg_waterfall_png, __ass_bg_waterfall_png_len);
6065
6166 nextPiece = GetRandomValue(0, 6);
6267 spawn();
@@ -90,6 +95,15 @@
9095 }
9196
9297 void GameMain::DrawUpdate() {
98+ sys::ImgMan::Get().DrawBackground("bg_beach");
99+ Rectangle gameArea = {
100+ boardPos.x - 160,
101+ boardPos.y - 30,
102+ (f32)m_HSize *(f32)m_SquareSize + 380,
103+ (f32)m_VSize *(f32)m_SquareSize + 60,
104+ };
105+ DrawRectangleRec(gameArea, Fade(BLACK, 0.65f));
106+
93107 i32 titleSize = std::max(30, (i32)(m_SquareSize * 1.2f));
94108 DrawText("TETRIS", GetScreenWidth() / 2 - titleSize * 2, 30, titleSize, WHITE);
95109
@@ -121,6 +135,9 @@
121135 }
122136 }
123137
138+ // ゴースト
139+ drawGhostPiece();
140+
124141 // 現在のピース
125142 Color pieceCol = tetrominoColors[m_CurPiece];
126143 for (i8 i = 0; i < 4; ++i) {
@@ -241,9 +258,9 @@
241258 void GameMain::drawNextPiece() {
242259 Color col = tetrominoColors[nextPiece];
243260
244- for (int i = 0; i < 4; ++i) {
245- float x = nextPos.x + tetrominoShapes[nextPiece][0][i][0] * nextSquareSize;
246- float y = nextPos.y + tetrominoShapes[nextPiece][0][i][1] * nextSquareSize;
261+ for (i8 i = 0; i < 4; ++i) {
262+ f32 x = nextPos.x + tetrominoShapes[nextPiece][0][i][0] * nextSquareSize;
263+ f32 y = nextPos.y + tetrominoShapes[nextPiece][0][i][1] * nextSquareSize;
247264
248265 Rectangle rect = { x, y, nextSquareSize, nextSquareSize };
249266 DrawTexturePro(blockTexture, { 0, 0, (f32)blockTexture.width, (f32)blockTexture.height }, rect, { 0, 0 }, 0.f, col);
@@ -256,13 +273,38 @@
256273
257274 Color col = tetrominoColors[m_Hold];
258275
259- for (int i = 0; i < 4; ++i) {
260- float x = holdPos.x + tetrominoShapes[m_Hold][0][i][0] * holdSquareSize;
261- float y = holdPos.y + tetrominoShapes[m_Hold][0][i][1] * holdSquareSize;
276+ for (i8 i = 0; i < 4; ++i) {
277+ f32 x = holdPos.x + tetrominoShapes[m_Hold][0][i][0] * holdSquareSize;
278+ f32 y = holdPos.y + tetrominoShapes[m_Hold][0][i][1] * holdSquareSize;
262279 Rectangle rect = { x, y, holdSquareSize, holdSquareSize };
263280
264281 DrawTexturePro(blockTexture, { 0, 0, (f32)blockTexture.width, (f32)blockTexture.height }, rect, { 0, 0 }, 0.f, col);
265282 DrawRectangleLines(x, y, holdSquareSize, holdSquareSize, BLACK);
283+ }
284+ }
285+
286+ void GameMain::drawGhostPiece() {
287+ i8 ghostY = m_CurY;
288+ while (isValidPos(m_CurPiece, m_CurRot, m_CurX, ghostY + 1)) ghostY++;
289+
290+ Color ghostCol = tetrominoColors[m_CurPiece];
291+ ghostCol.a = 90;
292+
293+ for (i8 i = 0; i < 4; ++i) {
294+ i8 px = m_CurX + tetrominoShapes[m_CurPiece][m_CurRot][i][0];
295+ i8 py = ghostY + tetrominoShapes[m_CurPiece][m_CurRot][i][1];
296+
297+ if (py >= 0 && px >= 0 && px < m_HSize && py < m_VSize) {
298+ Rectangle rect = {
299+ boardPos.x + px * (f32)m_SquareSize,
300+ boardPos.y + py * (f32)m_SquareSize,
301+ (f32)m_SquareSize,
302+ (f32)m_SquareSize,
303+ };
304+
305+ DrawTexturePro(blockTexture, { 0, 0, (f32)blockTexture.width, (f32)blockTexture.height }, rect, { 0, 0 }, 0.f, ghostCol);
306+ DrawRectangleLines(rect.x, rect.y, rect.width, rect.height, Fade(BLACK, .3f));
307+ }
266308 }
267309 }
268310
@@ -11,7 +11,14 @@
1111 return m_Textures[name];
1212 }
1313
14- Image img = LoadImageFromMemory(".png", data, dataSize);
14+ string ext = ".png";
15+ if (name.find("jpg") != string::npos || name.find("jpeg") != string::npos) {
16+ ext = ".jpg";
17+ } else if (name.find("png") != string::npos) {
18+ ext = ".png";
19+ }
20+
21+ Image img = LoadImageFromMemory(ext.c_str(), data, dataSize);
1522 if (img.data == nullptr) {
1623 TraceLog(LOG_WARNING, "テキスチャーの読み込みに失敗: %s", name.c_str());
1724 return Texture2D{};
@@ -30,6 +37,19 @@
3037 auto it = m_Textures.find(name);
3138 if (it != m_Textures.end()) return it->second;
3239 return Texture2D{};
40+ }
41+
42+ void ImgMan::DrawBackground(const string &name, Color tint) {
43+ Texture2D tx = GetTexture(name);
44+ if (tx.id == 0) {
45+ DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
46+ return;
47+ }
48+
49+ DrawTexturePro(tx,
50+ { 0, 0, (f32)tx.width, (f32)tx.height },
51+ { 0, 0, (f32)GetScreenWidth(), (f32)GetScreenHeight() },
52+ { 0, 0 }, 0.f, tint);
3353 }
3454
3555 void ImgMan::UnloadAll() {