Page 1 of 1

beginner tutorial 8 ,poo game

Posted: February 19th, 2018, 7:11 pm
by dooomedstar

Code: Select all

void Game::UpdateModel()
{
	
	if (wnd.kbd.KeyIsPressed(VK_RIGHT))
	{
		dudeX = dudeX + 1;
	}
	if (wnd.kbd.KeyIsPressed(VK_LEFT))
	{
		dudeX = dudeX - 1;
	}
	if (wnd.kbd.KeyIsPressed(VK_UP))
	{
		dudeY = dudeY - 1;
	}
	if (wnd.kbd.KeyIsPressed(VK_DOWN))
	{
		dudeY = dudeY + 1;
	}

	//why these two lines don't clamp if i put in the 
	//beginning of update model? and works fine and dandy after the if statements??
	dudeX = ClampScreenX(dudeX, dudeWidth);
	dudeY = ClampScreenY(dudeY, dudeHeight); 
}

Re: beginner tutorial 8 ,poo game

Posted: February 19th, 2018, 8:34 pm
by albinopapa
Think about it in sequence:
The way you want to do it: X = 799, Y = 0
- Clamp X between 0 and 800
- X = 799
- Clamp Y between 0 and 600
- Y = 0
- User presses UP
- Y = -1
- Draw dude at (799, -1)

The way that works: X = 799, Y = 0
- User presses UP
- Y = -1
- Clamp X between 0 and 800
- X = 799
- Clamp Y between 0 and 600
- Y = 0
- Draw dude at (799, 0)