ブロックの修正+ゴーストブロックの追加
守矢諏訪子 <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[] = { | |
| 2 | 2 | 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, |
| 3 | 3 | 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, |
| 4 | 4 | 0x08, 0x03, 0x00, 0x00, 0x00, 0x44, 0xa4, 0x8a, 0xc6, 0x00, 0x00, 0x00, |
| @@ -8,19 +8,19 @@ | ||
| 8 | 8 | 0xe2, 0x2e, 0xae, 0x81, 0xff, 0x7f, 0xca, 0x15, 0xbb, 0x00, 0x00, 0x00, |
| 9 | 9 | 0x0c, 0x74, 0x52, 0x4e, 0x53, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 10 | 10 | 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 | |
| 25 | 25 | }; |
| 26 | -unsigned int __tetris_block_png_len = 265; | |
| 26 | +unsigned int __ass_tetris_block_png_len = 273; |
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | void updateBoardLayout(); |
| 17 | 17 | void drawNextPiece(); |
| 18 | 18 | void drawHoldPiece(); |
| 19 | + void drawGhostPiece(); | |
| 19 | 20 | void handleInput(); |
| 20 | 21 | bool isValidPos(i8 piece, i8 rot, i8 x, i8 y); |
| 21 | 22 |
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | Texture2D LoadTexture(const string &name, const u8 *data, i32 dataSize); |
| 13 | 13 | Texture2D GetTexture(const string &name); |
| 14 | + void DrawBackground(const string &name, Color tint = WHITE); | |
| 14 | 15 | void UnloadAll(); |
| 15 | 16 | |
| 16 | 17 | private: |
| @@ -6,6 +6,12 @@ | ||
| 6 | 6 | #include <algorithm> |
| 7 | 7 | |
| 8 | 8 | #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> | |
| 9 | 15 | |
| 10 | 16 | namespace tetris::scene { |
| 11 | 17 | Color tetrominoColors[7] = { |
| @@ -20,20 +26,13 @@ | ||
| 20 | 26 | |
| 21 | 27 | // [ピース][回転][4ブロック][x,y] |
| 22 | 28 | 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 | |
| 37 | 36 | }; |
| 38 | 37 | |
| 39 | 38 | Vector2 boardPos = { 0, 0 }; |
| @@ -56,7 +55,13 @@ | ||
| 56 | 55 | |
| 57 | 56 | board.assign(m_VSize, std::vector<i32>(m_HSize, 0)); |
| 58 | 57 | |
| 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); | |
| 60 | 65 | |
| 61 | 66 | nextPiece = GetRandomValue(0, 6); |
| 62 | 67 | spawn(); |
| @@ -90,6 +95,15 @@ | ||
| 90 | 95 | } |
| 91 | 96 | |
| 92 | 97 | 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 | + | |
| 93 | 107 | i32 titleSize = std::max(30, (i32)(m_SquareSize * 1.2f)); |
| 94 | 108 | DrawText("TETRIS", GetScreenWidth() / 2 - titleSize * 2, 30, titleSize, WHITE); |
| 95 | 109 | |
| @@ -121,6 +135,9 @@ | ||
| 121 | 135 | } |
| 122 | 136 | } |
| 123 | 137 | |
| 138 | + // ゴースト | |
| 139 | + drawGhostPiece(); | |
| 140 | + | |
| 124 | 141 | // 現在のピース |
| 125 | 142 | Color pieceCol = tetrominoColors[m_CurPiece]; |
| 126 | 143 | for (i8 i = 0; i < 4; ++i) { |
| @@ -241,9 +258,9 @@ | ||
| 241 | 258 | void GameMain::drawNextPiece() { |
| 242 | 259 | Color col = tetrominoColors[nextPiece]; |
| 243 | 260 | |
| 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; | |
| 247 | 264 | |
| 248 | 265 | Rectangle rect = { x, y, nextSquareSize, nextSquareSize }; |
| 249 | 266 | DrawTexturePro(blockTexture, { 0, 0, (f32)blockTexture.width, (f32)blockTexture.height }, rect, { 0, 0 }, 0.f, col); |
| @@ -256,13 +273,38 @@ | ||
| 256 | 273 | |
| 257 | 274 | Color col = tetrominoColors[m_Hold]; |
| 258 | 275 | |
| 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; | |
| 262 | 279 | Rectangle rect = { x, y, holdSquareSize, holdSquareSize }; |
| 263 | 280 | |
| 264 | 281 | DrawTexturePro(blockTexture, { 0, 0, (f32)blockTexture.width, (f32)blockTexture.height }, rect, { 0, 0 }, 0.f, col); |
| 265 | 282 | 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 | + } | |
| 266 | 308 | } |
| 267 | 309 | } |
| 268 | 310 |
| @@ -11,7 +11,14 @@ | ||
| 11 | 11 | return m_Textures[name]; |
| 12 | 12 | } |
| 13 | 13 | |
| 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); | |
| 15 | 22 | if (img.data == nullptr) { |
| 16 | 23 | TraceLog(LOG_WARNING, "テキスチャーの読み込みに失敗: %s", name.c_str()); |
| 17 | 24 | return Texture2D{}; |
| @@ -30,6 +37,19 @@ | ||
| 30 | 37 | auto it = m_Textures.find(name); |
| 31 | 38 | if (it != m_Textures.end()) return it->second; |
| 32 | 39 | 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); | |
| 33 | 53 | } |
| 34 | 54 | |
| 35 | 55 | void ImgMan::UnloadAll() { |