The Partridge Family were neither partridges nor a family. Discuss.
-
dooomedstar
- Posts: 3
- Joined: February 5th, 2018, 4:17 pm
Post
by dooomedstar » February 19th, 2018, 7:11 pm
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);
}
-
albinopapa
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Post
by albinopapa » February 19th, 2018, 8:34 pm
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)
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com