From c04ccc9cc3aa91c634880cbfd2d77b58d68189ad Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Tue, 21 Dec 2010 18:00:21 +0000 Subject: Implement crouching --- Level.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Level.cpp') 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 -- cgit v1.2.3