Game Development Reference
In-Depth Information
How it works…
The ProcessClick() function handles a single click. We store the position of the click in
the g_Pos global variable for code simplicity:
void ProcessClick( bool Pressed )
{
Reset the states of the buttons:
b_Flags[b_MoveLeft] = 0.0f;
b_Flags[b_MoveRight] = 0.0f;
b_Flags[b_Down] = 0.0f;
b_Flags[b_TurnLeft] = 0.0f;
b_Flags[b_TurnRight] = 0.0f;
b_Flags[b_Paused] = 0.0f;
b_Flags[b_Reset] = 0.0f;
bool MousePressed = Pressed;
if ( Reset.ContainsPoint( g_Pos ) )
{
if ( MousePressed ) { ResetGame(); }
b_Flags[b_Reset] = MousePressed ? 1.0f : 0.0f;
}
Don't allow to press any buttons once the game is over:
if ( g_GS.FGameOver ) { if ( !Pressed ) ResetGame(); return; }
Run actions and update the buttons' highlight states:
if ( Pressed )
{
if ( MoveLeft.ContainsPoint( g_Pos ) )
{ MoveFigureLeft(); b_Flags[b_MoveLeft] = 1.0f; }
if ( MoveRight.ContainsPoint( g_Pos ) )
{ MoveFigureRight(); b_Flags[b_MoveRight] = 1.0f; }
if ( Down.ContainsPoint( g_Pos ) )
{
if ( !MoveFigureDown() ) { NextFigure(); } b_Flags[b_Down] = 1.0f;
}
if ( TurnLeft.ContainsPoint( g_Pos ) )
{ rotateFigure( false ); b_Flags[b_TurnLeft] = 1.0f; }
if ( TurnRight.ContainsPoint( g_Pos ) )
{ rotateFigure( true ); b_Flags[b_TurnRight] = 1.0f; }
if ( Paused.ContainsPoint( g_Pos ) )
{
b_Flags[b_Paused] = 1.0f;
 
Search WWH ::




Custom Search