[Add] World Manager.
[Fix] Added newlines in end of files.
This commit is contained in:
parent
db6c8e695e
commit
b508308115
@ -349,6 +349,14 @@
|
||||
RelativePath="..\..\..\src\libUnuk\Timer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\src\libUnuk\WorldManager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\src\libUnuk\WorldManager.h"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include "Game.h"
|
||||
#include "../libUnuk/NPC.h"
|
||||
#include "../libUnuk/WorldManager.h"
|
||||
|
||||
Game::Game(void) {
|
||||
Debug::logger->message("Creating characters..");
|
||||
_player = new Player(&_map);
|
||||
_npc = new NPC(&_map);
|
||||
|
||||
_runGameReturnValue = gameMainMenu;
|
||||
}
|
||||
@ -12,16 +13,12 @@ Game::~Game(void) {
|
||||
Debug::logger->message("\n----- Cleaning Up ------");
|
||||
// cleaning _player up caused a nice seg fault. I'll look later.
|
||||
//delete _player;
|
||||
delete _npc;
|
||||
}
|
||||
|
||||
gameNavVal_t Game::Run(const string savegameIDArg) {
|
||||
_player->SetXY(50, 50);
|
||||
_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);
|
||||
|
||||
int fps = 0;
|
||||
@ -107,7 +104,7 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
||||
_playerHealth.SetTextBlended(playerHealth.str(), vsmall, COLOUR_BLACK);
|
||||
|
||||
npcHealth.str("");
|
||||
npcHealth << "NPC Health: " << _npc->GetHealth();
|
||||
npcHealth << "NPC Health: " << _map.GetWorld().GetNPC(0)->GetHealth();
|
||||
_npcHealth.SetTextBlended(npcHealth.str(), vsmall, COLOUR_BLACK);
|
||||
}
|
||||
}
|
||||
@ -175,8 +172,8 @@ void Game::HandleInput(void) {
|
||||
|
||||
void Game::UpdateGame(void) {
|
||||
if(_ingameMenu.GetStatus() == false) {
|
||||
_map.Update();
|
||||
_player->Update();
|
||||
_npc->Update();
|
||||
} else {
|
||||
// :D
|
||||
}
|
||||
@ -186,9 +183,7 @@ void Game::Render(void) {
|
||||
// SDL_FillRect(screen, NULL, 0); // You might want to clear the buffer! --konom
|
||||
if(_ingameMenu.GetStatus() == false) {
|
||||
_map.Render();
|
||||
|
||||
_player->Render();
|
||||
_npc->Render();
|
||||
|
||||
if(debugEnabled) {
|
||||
_gameRenderTime.RenderLiteral();
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "../libUnuk/IngameMenu.h"
|
||||
#include "../libUnuk/Map.h"
|
||||
#include "../libUnuk/Timer.h"
|
||||
#include "../libUnuk/NPC.h"
|
||||
#include "../libUnuk/Debug.h"
|
||||
#include "../libUnuk/Text.h"
|
||||
#include "../libUnuk/MemClass.h"
|
||||
@ -58,7 +57,6 @@ private:
|
||||
Map _map;
|
||||
|
||||
Player* _player;
|
||||
NPC* _npc;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,7 +3,7 @@ CFLAGS = -ansi -Wall -g
|
||||
LDADD = -lGL -lGLU -lSDL -lSDL_ttf -lSDL_gfx -lSDL_image -ltinyxml
|
||||
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 \
|
||||
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 \
|
||||
AStar.o \
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "Map.h"
|
||||
#include "NPC.h"
|
||||
|
||||
Map::Map(void) {
|
||||
|
||||
@ -126,9 +127,26 @@ void Map::Load(const string filename) {
|
||||
levelHeight = y * TILE_HEIGHT;
|
||||
|
||||
//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) {
|
||||
_world.Update();
|
||||
// Update the map so we can render when camera moves.
|
||||
}
|
||||
|
||||
@ -167,6 +185,8 @@ void Map::Render(void) {
|
||||
_tile[i][j].Render();
|
||||
}
|
||||
}
|
||||
|
||||
_world.Render();
|
||||
}
|
||||
|
||||
void Map::Unload(void) {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "ApplySurface.h"
|
||||
#include "MapTile.h"
|
||||
#include "Debug.h"
|
||||
#include "WorldManager.h"
|
||||
using namespace std;
|
||||
|
||||
//class CharacterManager;
|
||||
@ -45,6 +46,8 @@ public:
|
||||
|
||||
string GetCurrentMap(void);
|
||||
|
||||
WorldManager& GetWorld(void) { return _world; }
|
||||
|
||||
private:
|
||||
void Unload(void);
|
||||
|
||||
@ -57,6 +60,8 @@ private:
|
||||
|
||||
TextureManager _tileTextures;
|
||||
TextureManager _entityTextures;
|
||||
|
||||
WorldManager _world;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
54
src/libUnuk/WorldManager.cpp
Normal file
54
src/libUnuk/WorldManager.cpp
Normal 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;
|
||||
}
|
20
src/libUnuk/WorldManager.h
Normal file
20
src/libUnuk/WorldManager.h
Normal 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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user