Game Development Reference
In-Depth Information
if ( NewPosition && ValidPosition1 && ValidPosition2 )
{
int dX = MouseI - FClickedI;
int dY = MouseJ - FClickedJ;
SwapTiles( FClickedI, FClickedJ, MouseI, MouseJ );
}
if ( IsComplete() )
{
// TODO: We've got a winner!
}
FClickedI = FClickedJ = -1;
}
}
How it works...
The 2_PuzzleProto example uses the clPuzzle class to show the gameplay without any
textures or any fancy graphics.
To render the state of the puzzle, the following routine is used:
void RenderGame( clPuzzle* g, const vec4& Color )
{
If we have selected the tile, we move it to the new mouse or touch position:
if ( g->FMovingImage && g->FClickedI >= 0 &&
g->FClickedI >= 0 &&
g->FClickedI < g->FColumns &&
g->FClickedJ < g->FRows )
{
vec2 MCI = Env_GetMouse();
int NewI = g->FClickedI;
int NewJ = g->FClickedJ;
float PosX, PosY;
PosX = Math::Clamp( MCI.x + g->FOfsX, 0.0f, 1.0f );
PosX *= g->FColumns;
PosY = Math::Clamp( MCI.y + g->FOfsY, 0.0f, 1.0f );
PosY *= g->FRows;
g->GetTile( NewI, NewJ )->MoveTo( PosX, PosY );
}
 
Search WWH ::




Custom Search