Game Development Reference
In-Depth Information
How to do it…
We need to implement some functions to move the currently falling shape:
1. Enforce the game ield constraints while moving a igure 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;
}
2.
The source code of MoveFigureRight() is similar to MoveFigureLeft() .
The code of MoveFigureDown() 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;
}
3.
The rotation code needs to check if the rotation is actually possible:
bool RotateFigure( bool CW )
{
clBricksShape TempFigure( g_CurrentFigure );
TempFigure.Rotate( CW );
if ( g_Field.FigureFits(g_GS.FCurX, g_GS.FCurY, TempFigure))
{
g_CurrentFigure = TempFigure;
return false;
}
return true;
}
4.
We need to call these methods in response to key presses or touches.
 
Search WWH ::




Custom Search