Tetris part 2

The GameEngine Class


So, this is mainly going to be about the GameEngine class.

The main job of the GameEngine is to update and render the game environment.
Now, at any moment , there is only one falling Group. So that is signified by currentGroup .
Apart from that, the Blocks that have already fallen, are just kept in a 2D array. For purposes of collision detection, this array has a padding. The padding is also required as we do not want a block to instantly appear .. We want to to appear slowly, that is first, the lowermost layer, then the middle and finally the upper layer. ( Groups have 3 rows each).

The update function, at each call, moves the current Group  down, creates one if not present, and then checks whether any lines have formed.

Since this is a small scale game, concurrency of threads has not been considered. When the player presses a key, the methods of the GameEngine are called from the Event thread itself. The Player can rotate or shift the Group s only, no other functionality is there.

During rendering, the padding is not shown. As a result, since the currentGroup always starts from the top row in the grid, it is shown part by part.

Now, since we are using a small grid based system, collision detection is really easy, I am not going to go through that.

During rendering, the render method of all the Blocks that have already fallen and that of the currentGroup are called. though the main information retrieved is the color of that block.
Again, this takes advantage of the grid system, as for all blocks, we know exactly where to paint it.

This is really all the GameEngine does.

Comments

Popular posts from this blog

Small-to-Large

Segment Tree Beats - An introduction

Getting prepared for RMO