Minigame Monday: 3D Tetris

 3D Tetris:

  • The concept:

I wanted to do another full sized minigame now that the game jam has finished (expect a post on that later in the week). This was actually an idea from my father, and it gave a number of interesting programming challenges so I decided on it as soon as I heard it. The idea itself is explained pretty well by the title; tetris, but in three dimensions.

  • The challenge:

The first issue for this game was how to represent the grid. I could have had each square control itself, and consider squares around it to decide when layers should be cleared, but I decided to have an overaching controller to handle it. I instantiated a cube in each possible spot on the gameplay area, and then used the controller to enable/disable the cubes and set their colour. Although doing this did involve a number of loops, as the game won't have large dimentions these loops won't be so large. As well as that, instantiating the cubes at the begining and enabling/disabling them is more efficient than instatiating them as blocks fall into the correct position (although of course it's unlikely to matter for a game of this size).

Checking for layers being complete didn't prove too difficult; to test it I wrote a quick line of code to randomly enable blocks, so I could see the lines being cleared, and check if blocks were being moved down correctly. Doing so made a slightly trippy effect of the block spawning:

Lots of colours...
 ...and also proved my code worked, which was nice. Less nice was sorting out the code to rotate falling blocks. To rotate the blocks, I gave the falling block script (which controlled all the falling blocks) an axis of rotation, which moved when the blocks did. This allowed me to rotate all blocks not on the axis around the axis, with the logic that to produce a 90 degree rotation in (x,y), the transform is (-y,x). Unfortunatly, I had some issues with getting the rotations correct, but I persevered and managed to get working rotations.

  • The result:


 

I achived what I was setting out to do when I made this game, in that it's 3D Tetris. On the other hand, there are plenty of things I'd have liked to add to the game; a display for the next blocks coming; vertical rotation, and increasing drop speed, to name just a few. Play the game for yourself at https://reddragonmakesgames.itch.io/3d-tetris, and the assets and code are on my github.



Comments

Popular posts from this blog

Armageddump (Boss Rush Jam 2023)

Imperfect Control: Gameplay

Hair of the Wolf (GameOff 2022)