18.1.2 Next Block

At the position where the next block appears, we draw an image. We’ve already made a constant for this position: WAITPOS. But that is a position in the grid. So we should always multiply this position with the size of a square (the constant SQUARE_SIZE). Moreover, we should start at the position of the playing field, which is the constant GAMEAREA.

We can therefore calculate the following position:

 
Vec2 blockPos = GAMEAREA + (WAITPOS * SQUARE_SIZE);  

But as you know a rectangle requires a minimum and a maximum position. To calculate the minimum, you subtract two squares of the detected position. It would be logical add extra two squares for the maximum position. But later on you will see that this looks less good. This is no problem. You can change this code whenever you like. The last line uses the two new values in order to set the actual rectangle.

 
Vec2 min = blockPos - (2 * SQUARE_SIZE); 
Vec2 max = blockPos + (2 * SQUARE_SIZE); 
blockRect.set(min, max);  

Now add code to the draw method to draw the picture ‘Tetris_score’ using the rectangle you’ve just created.