I would also suggest to make such game step by step:
Try to separate visual representation from input handling from logic handling. Start by defining smallest part of the game and writing down its design:
Grid is a 8x8 grid (or 8x10, etc, but usually 8 is the width).
Blocks can be: 1x1, 1x2, 1x3, 1x4.
- Implement Block Sliding Logic:
a) implement picking correct block
b) then allow to move it only horizontally
c) make sure you can slide only within the grid’s row (between “walls”)
c) make sure you can’t slide past other blocks in a row, if there are some - Implement what happens on
action.released
:
a) there should be a check if some blocks can fall down, so for each row, for each block in that for check if there is space for this block below this block (notice how when forming such statement you “write”for
loops)
b) if there is space, move that block to the row below (not visually, move that “block” in your grid (a Lua table)
c) notice how this check should be done for all blocks from top rows to bottom rows - Add row “fullness” check - if blocks in a row fill the whole row - remove all blocks from that row - and repeat step above
- Add game over conditions (if there is a block in the highest-1 row after all blocks fall, because if you spawn next line, which you will do below, you will touch the ceiling - but you can perhaps also check it after 5.)
- Add new line spawning (in the very bottom of the grid, but first move all blocks to the row above, starting from top to bottom)
a) you increase difficulty by spawning more of bigger blocks in a row, because e.g. 1x1 blocks are always a life saver - you can slide them almost anywhere and many times you make a full row with them (I know, because I play a lot of games like this xD)