Game Development Reference
In-Depth Information
How it works…
In the preceding code, we used some helper functions that might need some explanation.
The DrawQuad() and DrawTexQuad() functions draw a single cell of the game ield.
They consist of some hardcoded values to position the cells relative to the background
image. The following is the source code of one function:
void DrawTexQuad( float x, float y, float w, float h,
float OfsX, float OfsY,
const LVector4& Color, int ImageID )
{
Magic constants of 800.0f and 600.0f appear here to convert from the coordinate system
of the UI, which was designed for a 600×800 screen in portrait orientation, to the loating-
point normalized coordinates:
float X1 = x / 800.0f;
float Y1 = y / 600.0f;
float X2 = ( x + w ) / 800.0f;
float Y2 = ( y + h ) / 600.0f;
Other magic constants are also part of the design and were chosen empirically.
Try adjusting them:
X1 *= Field_Width / 0.35f;
X2 *= Field_Width / 0.35f;
Y1 *= Field_Height / 0.75f;
Y2 *= Field_Height / 0.75f;
Canvas->TexturedRect2D( X1 + OfsX, Y1 + OfsY,
X2 + OfsX, Y2 + OfsY,
Color, BricksImage[ImageID] );
}
The DrawFigure() method is used to draw a single shape anywhere in the game ield:
void DrawFigure( clBricksShape* Figure, int X, int Y,
float OfsX, float OfsY, float BlockSize )
{
for ( int i = 0 ; i < Figure->FWidth ; i++ )
{
for ( int j = 0 ; j < Figure->FHeight ; j++ )
{
 
Search WWH ::




Custom Search