Tutorial 5 (Messed up code?)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
WomboCombo
Posts: 5
Joined: September 15th, 2017, 7:34 pm

Tutorial 5 (Messed up code?)

Post by WomboCombo » September 15th, 2017, 7:51 pm

Alright Boy's and Girl's. I'm Stuck and confused. I'm only going to upload 2 files the game.cpp and the game.h cause up to tut 5 that's all chili has taught us to edit. Basically My problem is when i start click "Start without Debug" the black screen pops up with the Reticle right? well only thing is in tut 5 chili is teaching us how to change the color when it enter's a certain region and and if it's true than it changes color right? well. For someone reason on the outside of that region it's deciding to put the cursor outside of it as default. and when i hit the right key ->(Arrow key right) it doesn't maintain it's 1 pixel velocity. i have to spam it just to move it 1 pixel at a time.
https://gyazo.com/a8a5cf113cbb8e94e7b9154065b6393d<-- that's what it does in the Framework box if u wanted to see it
Game.h & Game.cpp.rar
These are the two files, I know chili provided a link to clean out ur .sln and blah blah blah. it was to confusing for a noob like me so i did it a way i'm cummfy with okie dokie!
(2.05 KiB) Downloaded 120 times
The Attachment

WomboCombo
Posts: 5
Joined: September 15th, 2017, 7:34 pm

Re: Tutorial 5 (Messed up code?)

Post by WomboCombo » September 15th, 2017, 9:29 pm

*edit* when i remove the code

Code: Select all

	controlIsPressed = false;
	if (x = 200)
	{
		if (x < 300)
		{
			controlIsPressed = true;
		}
	}
everything works as normal? :\

*edit for this specific msg I realized that i typed "if (x (=)200)" instead of if(x > 200)
*facepalm**
Last edited by WomboCombo on September 15th, 2017, 9:57 pm, edited 1 time in total.

WomboCombo
Posts: 5
Joined: September 15th, 2017, 7:34 pm

Re: Tutorial 5 (Messed up code?)

Post by WomboCombo » September 15th, 2017, 9:55 pm

*edit #2* I figured it out i just did this instead of color's IDK WHY but colors on my framework are weird i just typed this instead and worked just the same

Code: Select all

	shapeIsChanged = wnd.kbd.KeyIsPressed(VK_SHIFT);
	shapeIsChanged = false;
	if (x > 300)
	{
		if (x < 400)
			shapeIsChanged = true;
	}
	else
	{
		shapeIsChanged = false;
	}
ps. ShapeIsChanged is in game.h (head file)

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Tutorial 5 (Messed up code?)

Post by Yumtard » September 16th, 2017, 11:30 am

Haven't looked at all the code yet but one issues I already can see in your second post is this.

if (x = 200)
= is the assignment operator. To check if x equals 200 you have to write
if (x == 200)

this would make the nested if statement redundant tho since if x == 200 it's always < 300.
So yeah what you probably want is
if (x > 200 && x < 300)


Edit: i missed the fact that you've already noticed this mistake. your colored fonts are confusing me

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Tutorial 5 (Messed up code?)

Post by Yumtard » September 16th, 2017, 12:12 pm

if (controlIsPressed)
{
gb = 0;
}

This should be in the update function not in the composeframe
Also you probably want to add an else so that the cursor is only red while control is being held down?


Also, the issue why your color isn't automatically getting changed when x > 200 && x < 300.....

At the end of your update function you're doing this

controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);

so......

Code: Select all

controlIsPressed = false; //setting it to false
	if (x > 200)
	{
		if (x < 300)
		{
			controlIsPressed = true; //setting it to true
		}
	}

//setting it to true or false depending on if the key is pressed rendering above code useless
controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);

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

Re: Tutorial 5 (Messed up code?)

Post by chili » September 16th, 2017, 12:45 pm

my. eyes.
Chili

WomboCombo
Posts: 5
Joined: September 15th, 2017, 7:34 pm

Re: Tutorial 5 (Messed up code?)

Post by WomboCombo » September 16th, 2017, 3:40 pm

Yumtard wrote:if (controlIsPressed)
{
gb = 0;
}

This should be in the update function not in the composeframe
Also you probably want to add an else so that the cursor is only red while control is being held down?


Also, the issue why your color isn't automatically getting changed when x > 200 && x < 300.....

At the end of your update function you're doing this

controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);

so......

Code: Select all

controlIsPressed = false; //setting it to false
	if (x > 200)
	{
		if (x < 300)
		{
			controlIsPressed = true; //setting it to true
		}
	}

//setting it to true or false depending on if the key is pressed rendering above code useless
controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
so what you're saying is reguardless if i make it true or false, wont matter if i have

Code: Select all

controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
above the if statement?

also this is my code as of right now chili gave us homework which was too, make it so when the cursor collides with the other cursor it changes colors this is this code i have.

Code: Select all

void Game::Go()
{
	gfx.BeginFrame();	
	UpdateModel();
	ComposeFrame();
	gfx.EndFrame();
}

void Game::UpdateModel()
{
	if (x + 5 >= gfx.ScreenWidth)
	{
		x = gfx.ScreenWidth - 6;
		vx = 0;
	}
	if (x - 5 < 0)
	{
		x = 5;
	}
	if (y + 5 >= gfx.ScreenHeight)
	{
		y = gfx.ScreenHeight - 6;
		vy = 0;
	}
	if (y - 5 < 0)
	{
		y = 5;
	}

	if (wnd.kbd.KeyIsPressed(VK_UP))
	{
		if (inhibitUp)
		{
		}
		else
		{
			vy = vy - 1;
			inhibitUp = true;
		}
	}
	else
	{
		inhibitUp = false;
	}
	if (wnd.kbd.KeyIsPressed(VK_DOWN))
	{
		if (inhibitDown)
		{
		}
		else
		{
			vy = vy + 1;
			inhibitDown = true;
		}
	}
	else
	{
		inhibitDown = false;
	}
	if (wnd.kbd.KeyIsPressed(VK_LEFT))
	{
		if (inhibitLeft)
		{
		}
		else
		{
			vx = vx - 1;
			inhibitLeft = true;
		}
	}
	else
	{
		inhibitLeft = false;
	}
	if (wnd.kbd.KeyIsPressed(VK_RIGHT))
	{
		if (inhibitRight)
		{
		}
		else
		{
			vx = vx + 1;
			inhibitRight = true;
		}
	}
	else
	{
		inhibitRight = false;
	}

	x = x + vx;
	y = y + vy;
	controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
	shapeIsChanged = wnd.kbd.KeyIsPressed(VK_SHIFT);
	shapeIsChanged = false;
	if (x < 200 || x > 300 )
	{
			shapeIsChanged = true;
	}
	
}

void Game::ComposeFrame()
{
	if(ExtraBox)
	{
		gb3 = 0;
		gfx.PutPixel(5 + x2, y2, 255, gb2, gb3);
		gfx.PutPixel(4 + x2, y2, 255, gb2, gb3);
		gfx.PutPixel(3 + x2, y2, 255, gb2, gb3);
		gfx.PutPixel(x2, 3 + y2, 255, gb2, gb3);
		gfx.PutPixel(x2, 4 + y2, 255, gb2, gb3);
		gfx.PutPixel(x2, 5 + y2, 255, gb2, gb3);
		gfx.PutPixel(-5 + x2, y2, 255,gb2, gb3);
		gfx.PutPixel(-4 + x2, y2, 255,gb2, gb3);
		gfx.PutPixel(-3 + x2, y2, 255,gb2, gb3);
		gfx.PutPixel(x2, -3 +y2, 255, gb2, gb3);
		gfx.PutPixel(x2, -4 +y2, 255, gb2, gb3);
		gfx.PutPixel(x2, -5 +y2, 255, gb2, gb3);
	}
	
		if (shapeIsChanged)
		{
			gfx.PutPixel(5 + x, y, 255, gb, gb);
			gfx.PutPixel(5 + x,1 + y, 255, gb, gb);
			gfx.PutPixel(5 + x,2 + y, 255, gb, gb);
			gfx.PutPixel(4 + x,3 + y, 255, gb, gb);
			gfx.PutPixel(3 + x,3 + y, 255, gb, gb);
			gfx.PutPixel(2 + x,3 + y, 255, gb, gb);
			gfx.PutPixel(-5 + x, -0 + y, 255, gb, gb);
			gfx.PutPixel(-5 + x, -1 + y, 255, gb, gb);
			gfx.PutPixel(-5 + x, -2 + y, 255, gb, gb);
			gfx.PutPixel(-4 + x,-3 + y, 255, gb, gb);
			gfx.PutPixel(-3 + x,-3 + y, 255, gb, gb);
			gfx.PutPixel(-2 + x,-3 + y, 255, gb, gb);
		}
		else
		{
			gfx.PutPixel(5 + x, y, 255, gb, gb);
			gfx.PutPixel(4 + x, y, 255, gb, gb);
			gfx.PutPixel(3 + x, y, 255, gb, gb);
			gfx.PutPixel(x, 3 + y, 255, gb, gb);
			gfx.PutPixel(x, 4 + y, 255, gb, gb);
			gfx.PutPixel(x, 5 + y, 255, gb, gb);
			gfx.PutPixel(-5 + x, y, 255, gb, gb);
			gfx.PutPixel(-4 + x, y, 255, gb, gb);
			gfx.PutPixel(-3 + x, y, 255, gb, gb);
			gfx.PutPixel(x, -3 + y, 255, gb, gb);
			gfx.PutPixel(x, -4 + y, 255, gb, gb);
			gfx.PutPixel(x, -5 + y, 255, gb, gb);
		}
		if (controlIsPressed)
		{
			gb = 0;
			gfx.PutPixel(5 + x, y, 255, gb, gb);
			gfx.PutPixel(4 + x, y, 255, gb, gb);
			gfx.PutPixel(3 + x, y, 255, gb, gb);
			gfx.PutPixel(x, 3 + y, 255, gb, gb);
			gfx.PutPixel(x, 4 + y, 255, gb, gb);
			gfx.PutPixel(x, 5 + y, 255, gb, gb);
			gfx.PutPixel(-5 + x, y, 255, gb, gb);
			gfx.PutPixel(-4 + x, y, 255, gb, gb);
			gfx.PutPixel(-3 + x, y, 255, gb, gb);
			gfx.PutPixel(x, -3 + y, 255, gb, gb);
			gfx.PutPixel(x, -4 + y, 255, gb, gb);
			gfx.PutPixel(x, -5 + y, 255, gb, gb);
		}
}
in short i was able to get a box to appear i just didn't know how to make it "Collide" and i gave up and as soon i looked up the video chili freaking had bool colliding = false; or true; one of the two and i went OMG I KNEW IT! i was so mad that i gave up and looked cause i knew somehow i had to make it collide or write the code cause there was nothing :P
Last edited by WomboCombo on September 16th, 2017, 3:43 pm, edited 1 time in total.

WomboCombo
Posts: 5
Joined: September 15th, 2017, 7:34 pm

Re: Tutorial 5 (Messed up code?)

Post by WomboCombo » September 16th, 2017, 3:40 pm

chili wrote:my. eyes.
Alright got'cha no more colors in text's to hard to read and hurt's peoples eyes got it! :D

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Tutorial 5 (Messed up code?)

Post by Yumtard » September 16th, 2017, 5:03 pm

WomboCombo wrote: so what you're saying is reguardless if i make it true or false, wont matter if i have

Code: Select all

controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
above the if statement?
No. You had it at the end of the function. if you put it above the if statement it'll work.
The compiler reads your code from the top down.
So say your reticle is inside the are where you want it to be red but control is not pressed.
The compiler would read the code like:

Code: Select all

controlIsPressed = false;
"Okay you want me to set controlIsPress to false, I'll do that."

Code: Select all

   if (x > 200)
	{
		if (x < 300)
		{
			controlIsPressed = true;
		}
	}
"X is bigger than 200 and smaller than 300 so I guess I'll change controlIsPressed back to true"

Code: Select all

controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
"The control button isn't pressed so I'll change controlIsPressed back to false"

And then we go to ComposeFrame

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

Re: Tutorial 5 (Messed up code?)

Post by chili » September 17th, 2017, 3:07 am

Good explanation! (I just put the code in code tags for ya)
Chili

Post Reply