summaryrefslogtreecommitdiff
path: root/Level.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Level.cpp')
-rw-r--r--Level.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/Level.cpp b/Level.cpp
index f704c79..c70181a 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -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();
}