From 34de0b2b50c3ab4dbb917ddcfda89d1eb12bc6be Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sat, 27 Nov 2010 23:29:00 +0000 Subject: Level: Cope with there being no defined player start location --- Level.cpp | 14 ++++++++++++-- Level.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Level.cpp b/Level.cpp index dc36e24..54fd8c6 100644 --- a/Level.cpp +++ b/Level.cpp @@ -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; } } diff --git a/Level.h b/Level.h index 3bfac32..95a57e6 100644 --- a/Level.h +++ b/Level.h @@ -35,6 +35,8 @@ class Level { int cameraX; bool checkCollision(SDL_Rect r); + + int startX, startY; }; #endif -- cgit v1.2.3