diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-26 13:31:11 +0000 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-26 13:31:11 +0000 |
commit | 2ae1f27204f0f3040ff3b258affd7025bce8cbe8 (patch) | |
tree | ac91e03ac85cf7aef47a993ec003dba1da18ec32 | |
parent | 4e986298d51b48a0033c9d0e8a9a32e9a21b3809 (diff) |
Implement player x/y-coordinate boundaries
-rw-r--r-- | Level.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -39,12 +39,32 @@ void Level::changeLevel(int levelNo) { } void Level::move() { + int newX, newY; + // Apply gravity player.incYVel(GRAVITY); - // Player movements - player.setX(player.getX() + player.getXVel()); - player.setY(player.getY() + player.getYVel()); + // Player x-axis movement + newX = player.getX() + player.getXVel(); + // Don't let player go off either end of the screen + if (newX >= 0 && newX <= SCREEN_WIDTH - MARCUS_WIDTH) { + player.setX(newX); + } + + // Player y-axis movement + newY = player.getY() + player.getYVel(); + // Don't let player fall below bottom of screen + if (newY <= SCREEN_HEIGHT - MARCUS_HEIGHT) { + player.setY(newY); + } else { + // If player was going to fall off, fit snugly to edge + while (newY > SCREEN_HEIGHT - MARCUS_HEIGHT) { + newY--; + } + player.setY(newY); + // Reset velocity + player.setYVel(0); + } player.orient(); } |