summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Level.cpp17
-rw-r--r--Level.h2
2 files changed, 17 insertions, 2 deletions
diff --git a/Level.cpp b/Level.cpp
index ac860b3..7da0bf4 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -40,6 +40,8 @@ void Level::changeLevel(int levelNo) {
// Read the map file (all level/player init should be done here, not above)
loadMap(levelNo);
+
+ cameraX = 0;
}
void Level::move() {
@@ -79,11 +81,22 @@ void Level::draw(Screen *screen) {
screen->blit(player.getX(), player.getY(), player.image, player.getClip());
+ // Scroll level
+ if (player.getX() == 0 || player.getX() >= SCREEN_WIDTH - MARCUS_WIDTH - 10) {
+ if (player.getXVel() < 0 || player.getXVel() > 0)
+ cameraX -= player.getXVel();
+ }
+
+ // Don't let the camera move to before the start of the level
+ if (cameraX > 0)
+ cameraX = 0;
+
// Draw each platform...
for (int i = 0; i < numPlatforms; i++) {
// ...if it is visible
- if (platform[i].getX() + TILE_SIZE >= 0 && platform[i].getX() <= SCREEN_WIDTH) {
- screen->blit(platform[i].getX(), platform[i].getY(),
+ if (platform[i].getX() + TILE_SIZE + cameraX >= 0 && platform[i].getX()
+ + cameraX <= SCREEN_WIDTH) {
+ screen->blit(platform[i].getX() + cameraX, platform[i].getY(),
platform[0].image, platform[i].getClip());
}
}
diff --git a/Level.h b/Level.h
index 774164e..b6ca8c6 100644
--- a/Level.h
+++ b/Level.h
@@ -31,6 +31,8 @@ class Level {
// Reads in the map file
void loadMap(int levelNo);
+
+ int cameraX;
};
#endif