Tutorial 5 (Messed up code?)
-
- Posts: 5
- Joined: September 15th, 2017, 7:34 pm
Tutorial 5 (Messed up code?)
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 The Attachment
https://gyazo.com/a8a5cf113cbb8e94e7b9154065b6393d<-- that's what it does in the Framework box if u wanted to see it The Attachment
-
- Posts: 5
- Joined: September 15th, 2017, 7:34 pm
Re: Tutorial 5 (Messed up code?)
*edit* when i remove the code
everything works as normal? :\
*edit for this specific msg I realized that i typed "if (x (=)200)" instead of if(x > 200)
*facepalm**
Code: Select all
controlIsPressed = false;
if (x = 200)
{
if (x < 300)
{
controlIsPressed = true;
}
}
*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.
-
- Posts: 5
- Joined: September 15th, 2017, 7:34 pm
Re: Tutorial 5 (Messed up code?)
*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
ps. ShapeIsChanged is in game.h (head file)
Code: Select all
shapeIsChanged = wnd.kbd.KeyIsPressed(VK_SHIFT);
shapeIsChanged = false;
if (x > 300)
{
if (x < 400)
shapeIsChanged = true;
}
else
{
shapeIsChanged = false;
}
Re: Tutorial 5 (Messed up code?)
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
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
Re: Tutorial 5 (Messed up code?)
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......
{
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);
-
- Posts: 5
- Joined: September 15th, 2017, 7:34 pm
Re: Tutorial 5 (Messed up code?)
so what you're saying is reguardless if i make it true or false, wont matter if i haveYumtard 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);
Code: Select all
controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
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);
}
}
Last edited by WomboCombo on September 16th, 2017, 3:43 pm, edited 1 time in total.
-
- Posts: 5
- Joined: September 15th, 2017, 7:34 pm
Re: Tutorial 5 (Messed up code?)
Alright got'cha no more colors in text's to hard to read and hurt's peoples eyes got it!chili wrote:my. eyes.
Re: Tutorial 5 (Messed up code?)
No. You had it at the end of the function. if you put it above the if statement it'll work.WomboCombo wrote: so what you're saying is reguardless if i make it true or false, wont matter if i haveabove the if statement?Code: Select all
controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
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;
Code: Select all
if (x > 200)
{
if (x < 300)
{
controlIsPressed = true;
}
}
Code: Select all
controlIsPressed = wnd.kbd.KeyIsPressed(VK_CONTROL);
And then we go to ComposeFrame