diff options
-rw-r--r-- | Level.cpp | 17 | ||||
-rw-r--r-- | Level.h | 2 |
2 files changed, 17 insertions, 2 deletions
@@ -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()); } } @@ -31,6 +31,8 @@ class Level { // Reads in the map file void loadMap(int levelNo); + + int cameraX; }; #endif |