summaryrefslogtreecommitdiff
path: root/Level.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Level.cpp')
-rw-r--r--Level.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Level.cpp b/Level.cpp
index d956a78..9a230b0 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -23,6 +23,7 @@ void Level::changeLevel(int levelNo) {
player.setClip(ORIENT_BACK, MARCUS_WIDTH * 1, 0, MARCUS_WIDTH, MARCUS_HEIGHT);
player.setClip(ORIENT_RIGHT, MARCUS_WIDTH * 2, 0, MARCUS_WIDTH, MARCUS_HEIGHT);
player.setClip(ORIENT_LEFT, MARCUS_WIDTH * 3, 0, MARCUS_WIDTH, MARCUS_HEIGHT);
+ player.setClip(ORIENT_CROUCH, MARCUS_WIDTH * 4, 0, MARCUS_WIDTH, CROUCH_HEIGHT);
// Read the map file (all level/player init should be done here, not above)
loadMap(levelNo);
@@ -53,6 +54,23 @@ void Level::move() {
// Player x-axis movement
rect.x = player.getX() + player.getXVel();
+ // Check for crouching, 2 is setting crouch on
+ if (player.getCrouch() == 2)
+ rect.h = CROUCH_HEIGHT;
+ // 1 is trying to uncrouch, don't let them if something is in the way
+ if (player.getCrouch() == 1) {
+ rect.h = MARCUS_HEIGHT;
+ rect.y = player.getY() - MARCUS_HEIGHT + CROUCH_HEIGHT;
+ // If there's no collision, set crouch to 0 (normal, uncrouched)
+ if (!checkCollision(rect)) {
+ player.setCrouch(0);
+ // If the check failed then just keep checking collisions in crouched position
+ } else {
+ rect.h = CROUCH_HEIGHT;
+ rect.y = player.getY();
+ }
+ }
+
// If there's a collision in the x-axis ...
while (checkCollision(rect)) {
// ... fit snugly to edge