Game Development Reference
In-Depth Information
if ( i >= FWidth || j >= FHeight ) return -1;
int ColorIdx =
Shapes[FFigureIndex][FRotationIndex][i][j];
return ColorIdx ? FColor[ColorIdx] : -1;
}
7.
The method Rotate() does not rotate the individual cells. It does nothing but adjust
the rotation angle:
void Rotate( bool CW )
{
FRotationIndex = CW ?
( FRotationIndex ? FRotationIndex - 1 : ROTATIONS
- 1 ) :
( FRotationIndex + 1 ) % ROTATIONS;
}
8. Figure generation is also very simple. It is just a selection from the table of predeined
igures:
void GenFigure( int FigIdx, int Col )
{
for ( int i = 0; i != NUM_COLORS; i++ )
FColor[i] = Random( NUM_COLORS );
FFigureIndex = FigIdx;
FRotationIndex = 0;
}
9.
These methods are used to calculate the bounding box of the shape. Refer to the
game/Shape.h ile for their source code:
void GetTopLeftCorner( int* x, int* y ) const;
void GetBottomRightCorner( int* x, int* y ) const;
LRect GetSize() const;
};
How it works…
The main trick behind the code in the preceding section is the table of predeined shapes.
Its declaration is located in the Pentomino.h ile:
static const int NUM_SHAPES = 22;
static const int SHAPES_X = 5;
static const int SHAPES_Y = 5;
static const int ROTATIONS = 4;
extern char
Shapes[ NUM_SHAPES ][ ROTATIONS ][ SHAPES_X ][ SHAPES_Y ];
 
Search WWH ::




Custom Search