summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <l_bratch@yahoo.co.uk>2010-11-26 16:41:46 +0000
committerLuke Bratch <l_bratch@yahoo.co.uk>2010-11-26 16:41:46 +0000
commit7e046277d6a04e006d9653eda0a2b0990a454c2d (patch)
treea8f4a8f24fd1be77ac996c0adcb2436770ea489d
parentfbfe1f509f5a9b3b4f3f763648a96325ed6a295b (diff)
Level: Implement horizontally scrolling levels/camera
-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