From bdda3847fb7c7eaa19b890770d8dc6d36a3e0827 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Mon, 6 Feb 2012 00:27:52 +0000 Subject: [PATCH] [Fix] Tamir thought he was cool. But he typod soooo much!!! --- src/libUnuk/Engine/WorldManager.cpp | 280 ++++++++++++++-------------- 1 file changed, 140 insertions(+), 140 deletions(-) diff --git a/src/libUnuk/Engine/WorldManager.cpp b/src/libUnuk/Engine/WorldManager.cpp index 0578f69..d591dd1 100644 --- a/src/libUnuk/Engine/WorldManager.cpp +++ b/src/libUnuk/Engine/WorldManager.cpp @@ -5,183 +5,183 @@ #include "../UI/EventHistory.h" WorldManager::WorldManager(LevelGen* level) { - _level = level; + _level = level; } WorldManager::~WorldManager(void) { - for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { - NPC* npc = (*i); - delete npc; - } + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + NPC* npc = (*i); + delete npc; + } } void WorldManager::Update(void) { - for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { - NPC* npc = (*i); - npc->Update(); - } + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + NPC* npc = (*i); + npc->Update(); + } } void WorldManager::Render(void) { - for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { - NPC* npc = (*i); - npc->Render(); - } + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + NPC* npc = (*i); + npc->Render(); + } } void WorldManager::AddNPC(NPC* npc) { - _npcs.push_back(npc); + _npcs.push_back(npc); } void WorldManager::RemoveNPC(int index) { - int npcsIndex = 0; - for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { - NPC* npc = (*i); - if(npcsIndex == index) { - _npcs.erase(i); - delete npc; - } - npcsIndex++; - } + int npcsIndex = 0; + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + NPC* npc = (*i); + if(npcsIndex == index) { + _npcs.erase(i); + delete npc; + } + npcsIndex++; + } } NPC* WorldManager::GetNPC(int index) { - int npcsIndex = 0; - for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { - NPC* npc = (*i); - if(npcsIndex == index) { - return npc; - } - npcsIndex++; - } - return NULL; + int npcsIndex = 0; + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + NPC* npc = (*i); + if(npcsIndex == index) { + return npc; + } + npcsIndex++; + } + return NULL; } 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 npc; - } - } - return NULL; + 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 npc; + } + } + return NULL; } void WorldManager::CreateNPC(int x, int y) { - NPC* npc = new NPC(_level); - npc->SetXY(x, y); - npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45); - _npcs.push_back(npc); + NPC* npc = new NPC(_level); + npc->SetXY(x, y); + npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45); + _npcs.push_back(npc); } bool WorldManager::CheckCollision(const SDL_Rect& charRect, Character* exclude) { - for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { - NPC* npc = (*i); - - if(npc == exclude) { - continue; - } - - SDL_Rect npcRect; - npcRect.x = npc->GetX(); - npcRect.y = npc->GetY(); - npcRect.w = npc->GetWidth(); - npcRect.h = npc->GetHeight(); - - if(CheckCollisionRect(npcRect, charRect)) { - return true; - } - } - return false; + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + NPC* npc = (*i); + + if(npc == exclude) { + continue; + } + + SDL_Rect npcRect; + npcRect.x = npc->GetX(); + npcRect.y = npc->GetY(); + npcRect.w = npc->GetWidth(); + npcRect.h = npc->GetHeight(); + + if(CheckCollisionRect(npcRect, charRect)) { + return true; + } + } + return false; } void WorldManager::OnPlayerAttack(Player* player) { - int playerX = (int)(player->GetX() / 32.0f); - int playerY = (int)(player->GetY() / 32.0f); - int playerDir = player->GetDirectionFacing(); + int playerX = (int)(player->GetX() / 32.0f); + int playerY = (int)(player->GetY() / 32.0f); + int playerDir = player->GetDirectionFacing(); - std::list::iterator i = _npcs.begin(); + std::list::iterator i = _npcs.begin(); - while(i != _npcs.end()) { - NPC* npc = (*i); + while(i != _npcs.end()) { + NPC* npc = (*i); - int npcX = (int)(npc->GetX() / 32.0f); - int npcY = (int)(npc->GetY() / 32.0f); + int npcX = (int)(npc->GetX() / 32.0f); + int npcY = (int)(npc->GetY() / 32.0f); - int diffX = npcX - playerX; - int diffY = npcY - playerY; + int diffX = npcX - playerX; + int diffY = npcY - playerY; - // Not in player's line of sight. - if(diffX != 0 && diffY != 0) { - ++i; - continue; - } + // Not in player's line of sight. + if(diffX != 0 && diffY != 0) { + ++i; + continue; + } - // Distance is greater than 2. - if(abs(diffX) > 2 || abs(diffY) > 2) { - ++i; - continue; - } + // Distance is greater than 2. + if(abs(diffX) > 2 || abs(diffY) > 2) { + ++i; + continue; + } - // Player not facing the npc. - if((diffX < 0 && playerDir != Character::FACING_LEFT) || - (diffX > 0 && playerDir != Character::FACING_RIGHT) || - (diffY < 0 && playerDir != Character::FACING_UP) || - (diffY > 0 && playerDir != Character::FACING_DOWN)) - { - ++i; - continue; - } + // Player not facing the npc. + if((diffX < 0 && playerDir != Character::FACING_LEFT) || + (diffX > 0 && playerDir != Character::FACING_RIGHT) || + (diffY < 0 && playerDir != Character::FACING_UP) || + (diffY > 0 && playerDir != Character::FACING_DOWN)) + { + ++i; + continue; + } - npc->SetHealth(npc->GetHealth() - 20); - npc->OnAttack(); + npc->SetHealth(npc->GetHealth() - 20); + npc->OnAttack(); - if(npc->GetHealth() <= 0) { - - // Please note: - // Naked dudes are known to be sensitive to spicy food. - - char* waysOfDeath[] = { - "Choked Naked Dude!", - "Stabbed Naked Dude!", - "Urinated Acid on Naked Dude!", - "Killed Naked Dude with a dildo!", - "Poured Tabasco on Naked Dude!", - "Threw Acid on Naked Dude!", - "Slapped Naked Dude with Dead Fish!", - "Killed Naked Dude with a Pistol!", - "Ate Naked Dude's brain!", - "Slaughtered Naked Dude!", - "Roasted Naked Dude!", - "Paper Sprayed Naked Dude!", - "Stoned Naked Dude!", - "Slayed Naked Dude with a Katana!", - "Thew Chili Peppers on Naked Dude!", - "Used Karate on Naked Dude!", - "Beat the shit out of Naked Dude!", - "FUS RO DAH!" - }; - - eventHistory->LogEvent(waysOfDeath[rand() % (sizeof(waysOfDeath)/sizeof(char*))]); - - int expGain = 3 + (rand() % 2); - player->SetExp(player->GetExp() + expGain); - - i = _npcs.erase(i); - delete npc; - - if(_npcs.empty()) { - _level->Load("map"); - - int spawnX; - int spawnY; - _level->FindSpawnPoint(spawnX, spawnY, player->GetWidth(),player->GetHeight()); - player->SetXY(spawnX, spawnY); - } - } - else { - ++i; - } - } + if(npc->GetHealth() <= 0) { + + // Please note: + // Naked dudes are known to be sensitive to spicy food. + + char* waysOfDeath[] = { + "Choked Naked Dude!", + "Stabbed Naked Dude!", + "Urinated Acid on Naked Dude!", + "Killed Naked Dude with a dildo!", + "Poured Tabasco on Naked Dude!", + "Threw Acid on Naked Dude!", + "Slapped Naked Dude with Dead Fish!", + "Killed Naked Dude with a Pistol!", + "Ate Naked Dude's brain!", + "Slaughtered Naked Dude!", + "Roasted Naked Dude!", + "Pepper Sprayed Naked Dude!", + "Stoned Naked Dude!", + "Slayed Naked Dude with a Katana!", + "Threw Chili Peppers on Naked Dude!", + "Used Karate on Naked Dude!", + "Beat the shit out of Naked Dude!", + "FUS RO DAH!" + }; + + eventHistory->LogEvent(waysOfDeath[rand() % (sizeof(waysOfDeath)/sizeof(char*))]); + + int expGain = 3 + (rand() % 2); + player->SetExp(player->GetExp() + expGain); + + i = _npcs.erase(i); + delete npc; + + if(_npcs.empty()) { + _level->Load("map"); + + int spawnX; + int spawnY; + _level->FindSpawnPoint(spawnX, spawnY, player->GetWidth(),player->GetHeight()); + player->SetXY(spawnX, spawnY); + } + } + else { + ++i; + } + } }