In the previous recipes we learned how to render the game environment and implement the game logic. One more important aspect of the development needs our attention: the user interaction.
We need to implement some functions to move the currently falling shape:
Enforce the game field constraints while moving a figure left or right:
bool MoveFigureLeft() { if ( g_Field.FigureFits( g_GS.FCurX - 1, g_GS.FCurY, g_CurrentFigure ) ) { g_GS.FCurX--; return true; } return false; }
The source code of
MoveFigureRight()
is similar toMoveFigureLeft()
. The code ofMoveFigureDown()
needs to update the score once the shape has hit the ground:bool MoveFigureDown() { if ( g_Field.FigureFits( g_GS.FCurX, g_GS.FCurY + 1, g_CurrentFigure ) ) { g_GS.FScore += 1 + g_GS.FLevel / 2; g_GS.FCurY++; return true; } return false;...