[Add] World Manager.

[Fix] Added newlines in end of files.
This commit is contained in:
Tamir Atias 2012-01-11 04:07:35 +02:00
parent db6c8e695e
commit b508308115
10 changed files with 117 additions and 17 deletions

View File

@ -349,6 +349,14 @@
RelativePath="..\..\..\src\libUnuk\Timer.h" RelativePath="..\..\..\src\libUnuk\Timer.h"
> >
</File> </File>
<File
RelativePath="..\..\..\src\libUnuk\WorldManager.cpp"
>
</File>
<File
RelativePath="..\..\..\src\libUnuk\WorldManager.h"
>
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View File

@ -1,9 +1,10 @@
#include "Game.h" #include "Game.h"
#include "../libUnuk/NPC.h"
#include "../libUnuk/WorldManager.h"
Game::Game(void) { Game::Game(void) {
Debug::logger->message("Creating characters.."); Debug::logger->message("Creating characters..");
_player = new Player(&_map); _player = new Player(&_map);
_npc = new NPC(&_map);
_runGameReturnValue = gameMainMenu; _runGameReturnValue = gameMainMenu;
} }
@ -12,16 +13,12 @@ Game::~Game(void) {
Debug::logger->message("\n----- Cleaning Up ------"); Debug::logger->message("\n----- Cleaning Up ------");
// cleaning _player up caused a nice seg fault. I'll look later. // cleaning _player up caused a nice seg fault. I'll look later.
//delete _player; //delete _player;
delete _npc;
} }
gameNavVal_t Game::Run(const string savegameIDArg) { gameNavVal_t Game::Run(const string savegameIDArg) {
_player->SetXY(50, 50); _player->SetXY(50, 50);
_player->LoadSprites("../Data/Media/Images/Characters/template.png", 40, 45); _player->LoadSprites("../Data/Media/Images/Characters/template.png", 40, 45);
_npc->SetXY(300, 300);
_npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
LoadSavegame(savegameIDArg); LoadSavegame(savegameIDArg);
int fps = 0; int fps = 0;
@ -73,9 +70,9 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
} }
updateTimer.Pause(); updateTimer.Pause();
if (!stillRunning) { if (!stillRunning) {
break; break;
} }
renderTimer.Start(); renderTimer.Start();
Render(); Render();
@ -107,7 +104,7 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
_playerHealth.SetTextBlended(playerHealth.str(), vsmall, COLOUR_BLACK); _playerHealth.SetTextBlended(playerHealth.str(), vsmall, COLOUR_BLACK);
npcHealth.str(""); npcHealth.str("");
npcHealth << "NPC Health: " << _npc->GetHealth(); npcHealth << "NPC Health: " << _map.GetWorld().GetNPC(0)->GetHealth();
_npcHealth.SetTextBlended(npcHealth.str(), vsmall, COLOUR_BLACK); _npcHealth.SetTextBlended(npcHealth.str(), vsmall, COLOUR_BLACK);
} }
} }
@ -175,8 +172,8 @@ void Game::HandleInput(void) {
void Game::UpdateGame(void) { void Game::UpdateGame(void) {
if(_ingameMenu.GetStatus() == false) { if(_ingameMenu.GetStatus() == false) {
_map.Update();
_player->Update(); _player->Update();
_npc->Update();
} else { } else {
// :D // :D
} }
@ -186,9 +183,7 @@ void Game::Render(void) {
// SDL_FillRect(screen, NULL, 0); // You might want to clear the buffer! --konom // SDL_FillRect(screen, NULL, 0); // You might want to clear the buffer! --konom
if(_ingameMenu.GetStatus() == false) { if(_ingameMenu.GetStatus() == false) {
_map.Render(); _map.Render();
_player->Render(); _player->Render();
_npc->Render();
if(debugEnabled) { if(debugEnabled) {
_gameRenderTime.RenderLiteral(); _gameRenderTime.RenderLiteral();

View File

@ -14,7 +14,6 @@
#include "../libUnuk/IngameMenu.h" #include "../libUnuk/IngameMenu.h"
#include "../libUnuk/Map.h" #include "../libUnuk/Map.h"
#include "../libUnuk/Timer.h" #include "../libUnuk/Timer.h"
#include "../libUnuk/NPC.h"
#include "../libUnuk/Debug.h" #include "../libUnuk/Debug.h"
#include "../libUnuk/Text.h" #include "../libUnuk/Text.h"
#include "../libUnuk/MemClass.h" #include "../libUnuk/MemClass.h"
@ -58,7 +57,6 @@ private:
Map _map; Map _map;
Player* _player; Player* _player;
NPC* _npc;
}; };
#endif #endif

View File

@ -98,4 +98,4 @@ Button* ButtonGroup::GetButton(int index) {
buttonsIndex++; buttonsIndex++;
} }
return NULL; return NULL;
} }

View File

@ -32,4 +32,4 @@ private:
int _selectedButton; int _selectedButton;
}; };
#endif #endif

View File

@ -3,7 +3,7 @@ CFLAGS = -ansi -Wall -g
LDADD = -lGL -lGLU -lSDL -lSDL_ttf -lSDL_gfx -lSDL_image -ltinyxml LDADD = -lGL -lGLU -lSDL -lSDL_ttf -lSDL_gfx -lSDL_image -ltinyxml
objects = ApplySurface.o Button.o ButtonToggle.o ButtonGroup.o Character.o Collision.o \ objects = ApplySurface.o Button.o ButtonToggle.o ButtonGroup.o Character.o Collision.o \
Debug.o Font.o FPS.o ImageLoader.o IngameMenu.o Input.o MainMenu.o \ Debug.o Font.o FPS.o ImageLoader.o IngameMenu.o Input.o MainMenu.o \
Map.o MapElement.o MapEntities.o MemManager.o NPC.o ParticleEmitter.o \ WorldManager.o Map.o MapElement.o MapEntities.o MemManager.o NPC.o ParticleEmitter.o \
Rect.o Text.o Texture.o TextureManager.o Timer.o \ Rect.o Text.o Texture.o TextureManager.o Timer.o \
AStar.o \ AStar.o \

View File

@ -1,4 +1,5 @@
#include "Map.h" #include "Map.h"
#include "NPC.h"
Map::Map(void) { Map::Map(void) {
@ -126,9 +127,26 @@ void Map::Load(const string filename) {
levelHeight = y * TILE_HEIGHT; levelHeight = y * TILE_HEIGHT;
//character->Load(filename); //character->Load(filename);
NPC* npc = new NPC(this);
npc->SetXY(300, 300);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
npc = new NPC(this);
npc->SetXY(150, 350);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
npc = new NPC(this);
npc->SetXY(100, 250);
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
_world.AddNPC(npc);
} }
void Map::Update(void) { void Map::Update(void) {
_world.Update();
// Update the map so we can render when camera moves. // Update the map so we can render when camera moves.
} }
@ -167,6 +185,8 @@ void Map::Render(void) {
_tile[i][j].Render(); _tile[i][j].Render();
} }
} }
_world.Render();
} }
void Map::Unload(void) { void Map::Unload(void) {

View File

@ -14,6 +14,7 @@
#include "ApplySurface.h" #include "ApplySurface.h"
#include "MapTile.h" #include "MapTile.h"
#include "Debug.h" #include "Debug.h"
#include "WorldManager.h"
using namespace std; using namespace std;
//class CharacterManager; //class CharacterManager;
@ -45,6 +46,8 @@ public:
string GetCurrentMap(void); string GetCurrentMap(void);
WorldManager& GetWorld(void) { return _world; }
private: private:
void Unload(void); void Unload(void);
@ -57,6 +60,8 @@ private:
TextureManager _tileTextures; TextureManager _tileTextures;
TextureManager _entityTextures; TextureManager _entityTextures;
WorldManager _world;
}; };
#endif #endif

View File

@ -0,0 +1,54 @@
#include "WorldManager.h"
#include "NPC.h"
WorldManager::WorldManager(void) {
}
WorldManager::~WorldManager(void) {
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
NPC* npc = (*i);
delete npc;
}
}
void WorldManager::Update(void) {
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
NPC* npc = (*i);
npc->Update();
}
}
void WorldManager::Render(void) {
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
NPC* npc = (*i);
npc->Render();
}
}
void WorldManager::AddNPC(NPC* npc) {
_npcs.push_back(npc);
}
void WorldManager::RemoveNPC(int index) {
int npcsIndex = 0;
for(std::list<NPC*>::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<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
NPC* npc = (*i);
if(npcsIndex == index) {
return npc;
}
npcsIndex++;
}
return NULL;
}

View File

@ -0,0 +1,20 @@
#pragma once
#include <list>
class NPC;
class WorldManager {
public:
WorldManager(void);
~WorldManager(void);
void Update(void);
void Render(void);
void AddNPC(NPC* npc);
void RemoveNPC(int index);
NPC* GetNPC(int index);
private:
std::list<NPC*> _npcs;
};