Game Development Reference
In-Depth Information
Implementing picture puzzle game logic
This recipe you shows how to implement the game logic for a picture puzzle game. The game
consists of a set of rectangular tiles shufled and rendered on the screen. Users can tap on
individual tiles, and move them around, swapping them with the other tiles. Let us draft the
backbone data structures to implement this logic.
Getting ready
To feel the game logic better, you can build and run the 2_PuzzleProto project, which can
be downloaded from www.packtpub.com/support . If you want to enjoy the full-featured
game, just go ahead and download our Linderdaum Puzzle HD from Google Play. You can do it
at http://play.google.com/store/apps/details?id=com.linderdaum.engine.
puzzLHD .
How to do it...
1.
First, we need the clTile class to store the state of an individual puzzle piece. It
contains the current coordinates of the tile's upper-left corner, the original indices of
the tile in the grid, and the target coordinates where this tile will move to:
class clTile
{
public:
int FOriginX, FOriginY;
vec2 FCur, FTarget;
LRect FRect;
clTile(): FOriginX( 0 ), FOriginY( 0 ) {};
2.
The second constructor calculates and sets the FRect ield, which contains the
texture coordinates used later for the rendering:
clTile( int OriginX, int OriginY, int Columns, int Rows )
: FOriginX( OriginX )
, FOriginY( OriginY )
{
 
Search WWH ::




Custom Search