Need Hint for Homework Episode 9 Beginners

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
PrecentralGyrus
Posts: 10
Joined: April 13th, 2013, 6:04 pm

Need Hint for Homework Episode 9 Beginners

Post by PrecentralGyrus » April 21st, 2013, 5:25 am

Hey guys,

I was wondering if someone could let me know if I'm on the right track for the homework of episode 9. I feel like I'm putting a lot of effort into something I shouldn't. We just learned how to make loops using the

Code: Select all

while()
statement, and the homework is to create a square by looping putpixels, and then make the square able to move and increase and decrease in size. Currently here is my wall of code for making the square:

Code: Select all

void Game::ComposeFrame()
{
	int x = 250;
	while( x < 550 )
	{
		gfx.PutPixel( x,300,255,255,255 );
		x++;
	}

	int x2 = 250;
	while( x2 < 550 )
	{
		gfx.PutPixel( x2,301,255,255,255 );
		x2++;
	}
	
	int x3 = 250;
	while( x3 < 550 )
	{
		gfx.PutPixel( x3,302,255,255,255 );
		x3++;
	}

	int x4 = 250;
	while( x4 < 550 )
	{
		gfx.PutPixel( x4,303,255,255,255 );
		x4++;
	}

	int x5 = 250;
	while( x5 < 550 )
	{
		gfx.PutPixel( x5,304,255,255,255 );
		x5++;
	}

	int x6 = 250;
	while( x6 < 550 )
	{
		gfx.PutPixel( x6,305,255,255,255 );
		x6++;
	}

	int x7 = 250;
	while( x7 < 550 )
	{
		gfx.PutPixel( x7,306,255,255,255 );
		x7++;
	}

	int x8 = 250;
	while( x8 < 550 )
	{
		gfx.PutPixel( x8,307,255,255,255 );
		x8++;
	}

	int x9 = 250;
	while( x9 < 550 )
	{
		gfx.PutPixel( x9,308,255,255,255 );
		x9++;
	}

	int x10 = 250;
	while( x10 < 550 )
	{
		gfx.PutPixel( x10,309,255,255,255 );
		x10++;
	}

	int x11 = 250;
	while( x11 < 550 )
	{
		gfx.PutPixel( x11,310,255,255,255 );
		x11++;
	}

	int x12 = 250;
	while( x12 < 550 )
	{
		gfx.PutPixel( x12,311,255,255,255 );
		x12++;
	}

	int x13 = 250;
	while( x13 < 550 )
	{
		gfx.PutPixel( x13,312,255,255,255 );
		x13++;
	}

	int x14 = 250;
	while( x14 < 550 )
	{
		gfx.PutPixel( x14,313,255,255,255 );
		x14++;
	}

	int x15 = 250;
	while( x15 < 550 )
	{
		gfx.PutPixel( x15,314,255,255,255 );
		x15++;
	}

	int x16 = 250;
	while( x16 < 550 )
	{
		gfx.PutPixel( x16,315,255,255,255 );
		x16++;
	}

	int x17 = 250;
	while( x17 < 550 )
	{
		gfx.PutPixel( x17,316,255,255,255 );
		x17++;
	}

	int x18 = 250;
	while( x18 < 550 )
	{
		gfx.PutPixel( x18,317,255,255,255 );
		x18++;
	}

	int x19 = 250;
	while( x19 < 550 )
	{
		gfx.PutPixel( x19,318,255,255,255 );
		x19++;
	}

	int x20 = 250;
	while( x20 < 550 )
	{
		gfx.PutPixel( x20,319,255,255,255 );
		x20++;
	}

	int x21 = 250;
	while( x21 < 550 )
	{
		gfx.PutPixel( x21,320,255,255,255 );
		x21++;
	}

	int x22 = 250;
	while( x22 < 550 )
	{
		gfx.PutPixel( x22,321,255,255,255 );
		x22++;
	}

	int x23 = 250;
	while( x23 < 550 )
	{
		gfx.PutPixel( x23,322,255,255,255 );
		x23++;
	}

	int x24 = 250;
	while( x24 < 550 )
	{
		gfx.PutPixel( x24,323,255,255,255 );
		x24++;
	}

	int x25 = 250;
	while( x25 < 550 )
	{
		gfx.PutPixel( x25,324,255,255,255 );
		x25++;
	}

	int x26 = 250;
	while( x26 < 550 )
	{
		gfx.PutPixel( x26,325,255,255,255 );
		x26++;
	}

	int x27 = 250;
	while( x27 < 550 )
	{
		gfx.PutPixel( x27,326,255,255,255 );
		x27++;
	}

	int x28 = 250;
	while( x28 < 550 )
	{
		gfx.PutPixel( x28,327,255,255,255 );
		x28++;
	}

	int x29 = 250;
	while( x29 < 550 )
	{
		gfx.PutPixel( x29,328,255,255,255 );
		x29++;
	}

	int x30 = 250;
	while( x30 < 550 )
	{
		gfx.PutPixel( x30,329,255,255,255 );
		x30++;
	}

	int x31 = 250;
	while( x31 < 550 )
	{
		gfx.PutPixel( x31,330,255,255,255 );
		x31++;
	}

	int x32 = 250;
	while( x32 < 550 )
	{
		gfx.PutPixel( x32,331,255,255,255 );
		x32++;
	}

	int x33 = 250;
	while( x33 < 550 )
	{
		gfx.PutPixel( x33,332,255,255,255 );
		x33++;
	}

	int x34 = 250;
	while( x34 < 550 )
	{
		gfx.PutPixel( x34,333,255,255,255 );
		x34++;
	}

	int x35 = 250;
	while( x35 < 550 )
	{
		gfx.PutPixel( x35,334,255,255,255 );
		x35++;
	}

	int x36 = 250;
	while( x36 < 550 )
	{
		gfx.PutPixel( x36,335,255,255,255 );
		x36++;
	}

	int x37 = 250;
	while( x37 < 550 )
	{
		gfx.PutPixel( x37,336,255,255,255 );
		x37++;
	}

	int x38 = 250;
	while( x38 < 550 )
	{
		gfx.PutPixel( x38,337,255,255,255 );
		x38++;
	}

	int x39 = 250;
	while( x39 < 550 )
	{
		gfx.PutPixel( x39,338,255,255,255 );
		x39++;
	}

	int x40 = 250;
	while( x40 < 550 )
	{
		gfx.PutPixel( x40,339,255,255,255 );
		x40++;
	}

}
Basically just editing the y axis and creating new variables for every single line of putpixels. I feel like I'm doing something wrong, but sometimes my intuition is wrong...I also don't want to get the straight answer, which is why I'm not just looking at episode 10 and seeing the answer there. I want to figure it out :P .

Can someone steer me in the right direction?

Cheers :)

Shaki
Posts: 104
Joined: June 13th, 2012, 12:20 am

Re: Need Hint for Homework Episode 9 Beginners

Post by Shaki » April 21st, 2013, 4:06 pm

One thing I noticed you're doing is you're going over the axis (as you stated) by a few pixels, then relooping, this is actually a really poor way of doing things, (and of course every beginner does the inefficient route :p). you can actually make a variable inside of your loop then make another loop inside that one! So you can have say, X1 increase, but every time x1 increases, you loop through x2.
For example, (as not to solve your question).
int a = 0;
while(a<100){
int b = 0;
while(b<200){
b++;
}
a++;
}

Now what that would do, interestingly enough, is make b loop through 200 times, every time a is added once.

I hope this helps.

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: Need Hint for Homework Episode 9 Beginners

Post by viruskiller » April 23rd, 2013, 7:47 pm

what is prolly hard for u to understand is that b is reset to 0 every time a is less than 100
basically once u get to the end of the while(a<100 ){....} loop any variable declared inside is deleted.

anyway this can be helped with some extra c++ tutorials most importantly learning the rules of scope.

Post Reply