From cc258c35e04e217d8b7037c9dc7469b901395664 Mon Sep 17 00:00:00 2001 From: Tamir Atias Date: Sun, 5 Feb 2012 00:30:42 +0200 Subject: [PATCH] [Fix] Supposedly fixed spawning on top of NPCs. --- Data/Media/Maps/map | 44 ++++++++++++++--------------- src/Unuk/Game.cpp | 1 - src/libUnuk/Engine/WorldManager.cpp | 6 ++-- src/libUnuk/Engine/WorldManager.h | 2 +- src/libUnuk/LevelGen/LevelGen.cpp | 16 ++++++++--- src/libUnuk/LevelGen/LevelGen.h | 2 +- 6 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Data/Media/Maps/map b/Data/Media/Maps/map index b4373b6..c170515 100644 --- a/Data/Media/Maps/map +++ b/Data/Media/Maps/map @@ -824,8 +824,8 @@ grass false - cabin - true + null + false 100 @@ -2052,8 +2052,8 @@ - MessyBrickWall - true + grass + false null false @@ -2066,8 +2066,8 @@ - MessyBrickWall - true + grass + false null false @@ -2080,8 +2080,8 @@ - MessyBrickWall - true + grass + false null false @@ -2094,8 +2094,8 @@ - MessyBrickWall - true + grass + false null false @@ -2108,8 +2108,8 @@ - MessyBrickWall - true + grass + false null false @@ -2122,8 +2122,8 @@ - MessyBrickWall - true + grass + false null false @@ -2136,8 +2136,8 @@ - MessyBrickWall - true + grass + false null false @@ -2150,8 +2150,8 @@ - MessyBrickWall - true + grass + false null false @@ -2164,8 +2164,8 @@ - MessyBrickWall - true + grass + false null false @@ -2178,8 +2178,8 @@ - MessyBrickWall - true + grass + false null false diff --git a/src/Unuk/Game.cpp b/src/Unuk/Game.cpp index 00ba266..ed2e9f3 100644 --- a/src/Unuk/Game.cpp +++ b/src/Unuk/Game.cpp @@ -29,7 +29,6 @@ void Game::Load(const string& savegameIDArg) { } gameNavVal_t Game::Run(void) { - _player->SetXY(400, 400); _player->LoadSprites("../Data/Media/Images/Characters/Player.png", 40, 45); int fps = 0; diff --git a/src/libUnuk/Engine/WorldManager.cpp b/src/libUnuk/Engine/WorldManager.cpp index 6f0eca3..b0d273b 100644 --- a/src/libUnuk/Engine/WorldManager.cpp +++ b/src/libUnuk/Engine/WorldManager.cpp @@ -57,15 +57,15 @@ NPC* WorldManager::GetNPC(int index) { return NULL; } -bool WorldManager::HasNPCIn(int xArg, int yArg) { +NPC* WorldManager::GetNPCAt(int xArg, int yArg) { for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { NPC* npc = (*i); if(xArg >= npc->GetX() && xArg <= (npc->GetX() + npc->GetWidth()) && yArg >= npc->GetY() && yArg <= (npc->GetY() + npc->GetHeight())) { - return true; + return npc; } } - return false; + return NULL; } void WorldManager::CreateNPC(int x, int y) { diff --git a/src/libUnuk/Engine/WorldManager.h b/src/libUnuk/Engine/WorldManager.h index 00d4472..e161d0f 100644 --- a/src/libUnuk/Engine/WorldManager.h +++ b/src/libUnuk/Engine/WorldManager.h @@ -16,9 +16,9 @@ public: void AddNPC(NPC* npc); void RemoveNPC(int index); NPC* GetNPC(int index); + NPC* GetNPCAt(int xArg, int yArg); void CreateNPC(int x, int y); - bool HasNPCIn(int xArg, int yArg); int GetNPCCount() { return _npcs.size(); } diff --git a/src/libUnuk/LevelGen/LevelGen.cpp b/src/libUnuk/LevelGen/LevelGen.cpp index bbeb780..bf5e658 100644 --- a/src/libUnuk/LevelGen/LevelGen.cpp +++ b/src/libUnuk/LevelGen/LevelGen.cpp @@ -241,16 +241,24 @@ void LevelGen::FindSpawnPoint(int& xArg, int& yArg, int objWidth, int objHeight) xArg = rand() % (BOUNDARIES_X * TILE_WIDTH); yArg = rand() % (BOUNDARIES_Y * TILE_HEIGHT); - if(_world.HasNPCIn(xArg, yArg)) { - goto findNext; - } - SDL_Rect objRect; objRect.x = xArg; objRect.y = yArg; objRect.w = objWidth; objRect.h = objHeight; + NPC* npc = _world.GetNPCAt(xArg, yArg); + if(npc) { + SDL_Rect npcRect; + npcRect.x = npc->GetX(); + npcRect.y = npc->GetY(); + npcRect.w = npc->GetWidth(); + npcRect.h = npc->GetHeight(); + + if(CheckCollisionRect(npcRect, objRect)) + goto findNext; + } + for(int x = 0; x < BOUNDARIES_X; x++) { for(int y = 0; y < BOUNDARIES_Y; y++) { if(_tile[x][y].GetTileSolidity()) { diff --git a/src/libUnuk/LevelGen/LevelGen.h b/src/libUnuk/LevelGen/LevelGen.h index ba6d12d..b1d1e88 100644 --- a/src/libUnuk/LevelGen/LevelGen.h +++ b/src/libUnuk/LevelGen/LevelGen.h @@ -62,7 +62,7 @@ private: MapTile _tile[TILE_ARRAY_SIZE][TILE_ARRAY_SIZE]; static const int BOUNDARIES_X = (SCREEN_WIDTH / TILE_WIDTH) - 2; - static const int BOUNDARIES_Y = (SCREEN_HEIGHT / TILE_HEIGHT) - 2; + static const int BOUNDARIES_Y = (SCREEN_HEIGHT / TILE_HEIGHT) - 1; TextureManager _tileTextures; TextureManager _entityTextures;