I Made A Box - Lesson 10 My Attempt

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
TheRoflReaper
Posts: 4
Joined: June 3rd, 2012, 9:57 pm

I Made A Box - Lesson 10 My Attempt

Post by TheRoflReaper » June 3rd, 2012, 10:19 pm

I just wanted to post this to show my progress :D... and to help anyone if they had the same problem I had. So, when Chili said that he wouldn't write the code to move or change the box in lesson 10 I decided to attempt it. At first I wasn't too sure how to but then it clicked and it came naturally.
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++;
	}
}
Game.h user variables

Code: Select all

  int boxX;
	int boxY;
	int boxWidth;
	int boxHeight;
Hope this helps anyone if they need it :D

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.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I Made A Box - Lesson 10 My Attempt

Post by chili » June 4th, 2012, 2:53 pm

Bro, the box is lesson 9.

Here is the solution for the circle pattern:

http://www.planetchili.net/forum/viewto ... ?f=3&t=943
Chili

Post Reply