I kinda need help

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
npissoawsome
Posts: 114
Joined: June 8th, 2012, 3:01 pm

Re: I kinda need help

Post by npissoawsome » June 8th, 2012, 4:27 pm

LuX wrote:Alright. There's something wrong there. I personally haven't used the while command, at least knowing what is does.

Here's how I would do it:

Code: Select all

/*Drawing the Box*/

   int y = boxY;
   while( y < boxY + boxHeight )
   {
		int x = boxX;
		while( x < boxX + boxWidth )
		{
			gfx.PutPixel( x,y,r,g,b );
			x++;
		}
		y++;
   }

	if( kbd.SpaceIsPressed() && kbd.LeftIsPressed())
	{
		r++;
	}
In addition to that, take a look at where "r" is defined as 30. At the top of compose frame, which means what ever you do to "r" it's going to become 30 anyways, so nothing will happen to it. You need to put that "r = 0;" under the initialization as you have done with the Box variables.

Oh, and the reason for you code crashing, I bet its because of the "while (kbd.leftispressed())" as it creates a loop which wont be exited since the left wont be unpressed in the middle of a frame.

that code is pretty much the same thing as this :)

Code: Select all

for( int y = boxy; y < (boxY + boxHeight); y++ )
	for( int x = boxX; x < (boxX + boxWidth); x++ )
		gfx.PutPixel( x, y, r, g, b );

if( kbd.SpaceIsPressed() && kbd.LeftIsPressed())
	r++;
Have you used for loops before?

EDIT:
That was some sloppy code, I think I fixed it lol

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

Re: I kinda need help

Post by chili » June 9th, 2012, 12:19 pm

Yo np! I think you should read this thread. ;)

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

User avatar
npissoawsome
Posts: 114
Joined: June 8th, 2012, 3:01 pm

Re: I kinda need help

Post by npissoawsome » June 12th, 2012, 6:04 pm

chili wrote:Yo np! I think you should read this thread. ;)

http://www.planetchili.net/forum/viewto ... f=3&t=1107

Ahaha, yeah I'm aware, if you don't use braces, it only affects the next line of code

I generally use braces, but I was just showing that the code he suggested was way too long :p

Post Reply