Game Development Reference
In-Depth Information
See also
F Creating a multiplatform gaming engine
Managing shapes
In the previous recipe, we learned how to render the game screen. Some classes remained
unimplemented. In this recipe, we will implement the clBricksShape class responsible for
the storage and manipulation of each of the shapes that appear in the game.
Getting ready
Take a look at how many different pentomino shapes can exist. Wikipedia provides
a comprehensive overview: http://en.wikipedia.org/wiki/Pentomino .
How to do it…
1.
The interface of our clBricksShape class looks as follows:
class clBricksShape
{
public:
2.
The size of shapes used in our game. We use 5x5 shapes.
static const int FWidth = SHAPES_X;
static const int FHeight = SHAPES_Y;
3.
Store the colors of the cells this shape consists of. The colors are stored as indices:
private:
int FColor[NUM_COLORS];
4. The igure index deines the shape type:
int FFigureIndex;
5. The rotation index corresponds to the rotation angle of the igure: 0 , 1 , 2 , and 3
stand for 0 , 90 , 180 , and 270 degrees:
int FRotationIndex;
6.
The methods are very short and straightforward as follows:
public:
int GetMask( int i, int j ) const
{
if ( i < 0 || j < 0 ) return -1;
 
Search WWH ::




Custom Search