summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Level.cpp17
-rw-r--r--Level.h2
2 files changed, 11 insertions, 8 deletions
diff --git a/Level.cpp b/Level.cpp
index 9a230b0..8e9def4 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -62,7 +62,7 @@ void Level::move() {
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)) {
+ if (checkCollision(rect) != 1) {
player.setCrouch(0);
// If the check failed then just keep checking collisions in crouched position
} else {
@@ -72,7 +72,7 @@ void Level::move() {
}
// If there's a collision in the x-axis ...
- while (checkCollision(rect)) {
+ while (checkCollision(rect) == 1) {
// ... fit snugly to edge
if (player.getXVel() > 0) {
rect.x--;
@@ -88,8 +88,8 @@ void Level::move() {
rect.y = player.getY() + player.getYVel();
// If there's a collision in the y-axis ...
- if (checkCollision(rect)) {
- while (checkCollision(rect)) {
+ if (checkCollision(rect) == 1) {
+ while (checkCollision(rect) == 1) {
// ... fit snugly to edge
if (player.getYVel() > 0)
rect.y--;
@@ -191,15 +191,18 @@ void Level::loadMap(int LevelNo) {
map.close();
}
-bool Level::checkCollision(SDL_Rect r) {
+/* Return values:
+ 0: No collision
+ 1: Platform */
+int Level::checkCollision(SDL_Rect r) {
// Loop through each platform
for (int i = 0; i < numPlatforms; i++) {
// Check for collisions in the x-axis ...
if (r.x > platform[i].getX() - r.w && r.x < platform[i].getX() + TILE_SIZE)
// ... if found, check for collisions in the y-axis
if (r.y > platform[i].getY() - r.h && r.y < platform[i].getY() + TILE_SIZE)
- return true;
+ return 1;
}
- return false;
+ return 0;
}
diff --git a/Level.h b/Level.h
index 95a57e6..0a38029 100644
--- a/Level.h
+++ b/Level.h
@@ -34,7 +34,7 @@ class Level {
int cameraX;
- bool checkCollision(SDL_Rect r);
+ int checkCollision(SDL_Rect r);
int startX, startY;
};