diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-27 23:29:00 +0000 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-27 23:29:00 +0000 |
commit | 34de0b2b50c3ab4dbb917ddcfda89d1eb12bc6be (patch) | |
tree | bd6a1e3e7670e044e0f7b8b841070cf09d2a9875 | |
parent | a00e29799a9fa4e8f140ef3f292f3200736fe957 (diff) |
Level: Cope with there being no defined player start location
-rw-r--r-- | Level.cpp | 14 | ||||
-rw-r--r-- | Level.h | 2 |
2 files changed, 14 insertions, 2 deletions
@@ -8,6 +8,8 @@ #include "Platform.h" Level::Level() { + startX = -1; + startY = -1; } void Level::changeLevel(int levelNo) { @@ -33,6 +35,14 @@ void Level::changeLevel(int levelNo) { // Read the map file (all level/player init should be done here, not above) loadMap(levelNo); + if (startX < 0) { + startX = 0; + startY = 0; + } + + player.setX(startX); + player.setY(startY); + cameraX = 0; } @@ -146,8 +156,8 @@ void Level::loadMap(int LevelNo) { numPlatforms++; } else if (type == 'P') { // Set the player starting position - player.setX((i % MAP_X) * TILE_SIZE); - player.setY((i / MAP_X) * TILE_SIZE - player.getClip()->h); + startX = (i % MAP_X) * TILE_SIZE; + startY = (i / MAP_X) * TILE_SIZE - player.getClip()->h; } } @@ -35,6 +35,8 @@ class Level { int cameraX; bool checkCollision(SDL_Rect r); + + int startX, startY; }; #endif |