[Fix] NPCs and Player shall no longer spawn inside entities!
This commit is contained in:
parent
228371376d
commit
90e3ff7a22
@ -255,7 +255,7 @@ void Game::NewSavegame(const string savegameIDArg) {
|
||||
|
||||
int spawnX;
|
||||
int spawnY;
|
||||
_map.FindSpawnPoint(spawnX, spawnY);
|
||||
_map.FindSpawnPoint(spawnX, spawnY, _player->GetWidth(), _player->GetHeight());
|
||||
|
||||
_player->SetXY(spawnX, spawnY);
|
||||
|
||||
|
@ -130,7 +130,7 @@ void WorldManager::OnPlayerAttack(Player* player) {
|
||||
|
||||
int spawnX;
|
||||
int spawnY;
|
||||
_level->FindSpawnPoint(spawnX, spawnY);
|
||||
_level->FindSpawnPoint(spawnX, spawnY, player->GetWidth(),player->GetHeight());
|
||||
player->SetXY(spawnX, spawnY);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <list>
|
||||
|
||||
#include "LevelGen.h"
|
||||
#include "../Engine/NPC.h"
|
||||
|
||||
@ -235,20 +237,44 @@ void LevelGen::MakeWalkingPaths(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void LevelGen::FindSpawnPoint(int& xArg, int& yArg) {
|
||||
void LevelGen::FindSpawnPoint(int& xArg, int& yArg, int objWidth, int objHeight) {
|
||||
xArg = rand() % (BOUNDARIES_X * TILE_WIDTH);
|
||||
yArg = rand() % (BOUNDARIES_Y * TILE_HEIGHT);
|
||||
|
||||
int tileX = xArg / 64;
|
||||
int tileY = yArg / 64;
|
||||
if(_world.HasNPCIn(xArg, yArg)) {
|
||||
goto findNext;
|
||||
}
|
||||
|
||||
if(!_tile[tileX][tileY].GetEntitySolitity() &&
|
||||
!_tile[tileX][tileY].GetTileSolidity() &&
|
||||
!_world.HasNPCIn(xArg, yArg)) {
|
||||
return;
|
||||
}
|
||||
SDL_Rect objRect;
|
||||
objRect.x = xArg;
|
||||
objRect.y = yArg;
|
||||
objRect.w = objWidth;
|
||||
objRect.h = objHeight;
|
||||
|
||||
FindSpawnPoint(xArg, yArg);
|
||||
for(int x = 0; x < BOUNDARIES_X; x++) {
|
||||
for(int y = 0; y < BOUNDARIES_Y; y++) {
|
||||
if(_tile[x][y].GetTileSolidity()) {
|
||||
goto findNext;
|
||||
}
|
||||
|
||||
if(_tile[x][y].GetEntitySolitity()) {
|
||||
SDL_Rect entityRect;
|
||||
entityRect.x = _tile[x][y].GetEntityX();
|
||||
entityRect.y = _tile[x][y].GetEntityY();
|
||||
entityRect.w = _tile[x][y].GetEntityWidth();
|
||||
entityRect.h = _tile[x][y].GetEntityHeight();
|
||||
|
||||
if(CheckCollisionRect(entityRect, objRect)) {
|
||||
goto findNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
findNext:
|
||||
FindSpawnPoint(xArg, yArg, objWidth, objHeight);
|
||||
}
|
||||
|
||||
void LevelGen::GenerateEnemies(void) {
|
||||
@ -257,7 +283,7 @@ void LevelGen::GenerateEnemies(void) {
|
||||
for(int i = 0; i < npcsToGen; i++) {
|
||||
int spawnX;
|
||||
int spawnY;
|
||||
FindSpawnPoint(spawnX, spawnY);
|
||||
FindSpawnPoint(spawnX, spawnY, 40,45);
|
||||
|
||||
_world.CreateNPC(spawnX, spawnY);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
void Update(void);
|
||||
void Render(void);
|
||||
|
||||
void FindSpawnPoint(int& xArg, int& yArg);
|
||||
void FindSpawnPoint(int& xArg, int& yArg, int objWidth, int objHeight);
|
||||
|
||||
bool GetTileSolidity(int xArg, int yArg);
|
||||
int GetTileX(int xArg, int yArg);
|
||||
|
Loading…
Reference in New Issue
Block a user