diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-26 16:41:46 +0000 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-26 16:41:46 +0000 |
commit | 7e046277d6a04e006d9653eda0a2b0990a454c2d (patch) | |
tree | a8f4a8f24fd1be77ac996c0adcb2436770ea489d | |
parent | fbfe1f509f5a9b3b4f3f763648a96325ed6a295b (diff) |
Level: Implement horizontally scrolling levels/camera
-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 |