ラインクリア

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

8個のファイル、+39 -3

大き過ぎるので表示しません

大き過ぎるので表示しません

大き過ぎるので表示しません

大き過ぎるので表示しません

大き過ぎるので表示しません

大き過ぎるので表示しません

@@ -17,6 +17,7 @@
1717 void drawNextPiece();
1818 void drawHoldPiece();
1919 void drawGhostPiece();
20+ void clearLines();
2021 void handleInput();
2122 bool isValidPos(i8 piece, i8 rot, i8 x, i8 y);
2223
@@ -99,8 +99,8 @@
9999 Rectangle gameArea = {
100100 boardPos.x - 160,
101101 boardPos.y - 30,
102- (f32)m_HSize *(f32)m_SquareSize + 380,
103- (f32)m_VSize *(f32)m_SquareSize + 60,
102+ (f32)m_HSize * (f32)m_SquareSize + 380,
103+ (f32)m_VSize * (f32)m_SquareSize + 60,
104104 };
105105 DrawRectangleRec(gameArea, Fade(BLACK, 0.65f));
106106
@@ -225,7 +225,7 @@
225225 if (py >= 0) board[py][px] = m_CurPiece + 1;
226226 }
227227
228- // TODO: クリアでチェック
228+ clearLines();
229229 spawn();
230230 }
231231
@@ -305,6 +305,41 @@
305305 DrawTexturePro(blockTexture, { 0, 0, (f32)blockTexture.width, (f32)blockTexture.height }, rect, { 0, 0 }, 0.f, ghostCol);
306306 DrawRectangleLines(rect.x, rect.y, rect.width, rect.height, Fade(BLACK, .3f));
307307 }
308+ }
309+ }
310+
311+ void GameMain::clearLines() {
312+ i32 clearLine = 0;
313+
314+ for (i32 j = m_VSize - 1; j >= 0; --j) {
315+ bool isFull = true;
316+
317+ for (i32 i = 0; i < m_HSize; ++i) {
318+ if (board[j][i] == 0) {
319+ isFull = false;
320+ break;
321+ }
322+ }
323+
324+ if (isFull) {
325+ clearLine++;
326+
327+ for (i32 y = j; y > 0; --y)
328+ for (i32 x = 0; x < m_HSize; ++x)
329+ board[y][x] = board[y - 1][x];
330+
331+ for (i32 x = 0; x < m_HSize; ++x) board[0][x] = 0;
332+
333+ j++;
334+ }
335+ }
336+
337+ if (clearLine > 0) {
338+ m_Lines += clearLine;
339+ m_Score += clearLine * clearLine * 100;
340+
341+ m_Level = 1 + (m_Lines / 10);
342+ m_FallSpeed = std::max(.15f, .8f - (m_Level - 1) * .07f);
308343 }
309344 }
310345