Here is my version of the code;
Game.cpp
Code: Select all
Game::Game( HWND hWnd,const KeyboardServer& kServer )
: gfx ( hWnd ),
kbd( kServer ),
boxHeight( 200 ),
boxWidth( 200 ),
boxY( 200 ),
boxX( 300 )
{}
void Game::Go()
{
gfx.BeginFrame();
ComposeFrame();
gfx.EndFrame();
}
void Game::ComposeFrame()
{
/*Box cannot BreakFrame*/
if( boxX < 5 )
{
boxX = 5;
}
if( boxX + boxWidth > 795 )
{
boxX = 795 - boxWidth;
}
if( boxY < 5 )
{
boxY = 5;
}
if( boxY + boxHeight > 595 )
{
boxY = 595 - boxHeight;
}
/*Moving the Box*/
if( kbd.RightIsPressed())
{
boxX = boxX + 5;
}
if( kbd.LeftIsPressed())
{
boxX = boxX - 5;
}
if( kbd.UpIsPressed())
{
boxY = boxY - 5;
}
if( kbd.DownIsPressed())
{
boxY = boxY + 5;
}
/*Re-sizing the box*/
if( kbd.EnterIsPressed())
{
boxHeight = boxHeight - 10;
boxWidth = boxWidth - 10;
}
if( kbd.SpaceIsPressed())
{
boxHeight = boxHeight + 10;
boxWidth = boxWidth + 10;
}
/*Box cannot be bigger than 100x100*
if( boxHeight > 100 )
{
boxHeight = 100;
}
if( boxWidth > 100 )
{
boxWidth = 100;
}
/*Box cannot be smaller than 5x5*/
if( boxHeight < 5 )
{
boxHeight = 5;
}
if ( boxWidth < 5 )
{
boxWidth = 5;
}
/*Drawing the Box*/
int y = boxY;
while( y < boxY + boxHeight )
{
int x = boxX;
while( x < boxX + boxWidth )
{
gfx.PutPixel( x,y,255,255,255 );
x++;
}
y++;
}
}
Code: Select all
int boxX;
int boxY;
int boxWidth;
int boxHeight;
PS.
I don't know how to do the colorful circles and I couldn't find the post in the forums on it, could someone point me in that direction or if it's not posted could someone post it.