Merge branch 'master' of github.com:Allanis/Unuk
Conflicts: src/libUnuk/Engine/NPC.cpp src/libUnuk/LevelGen/LevelGen.h src/libUnuk/LevelGen/MapTile.cpp src/libUnuk/LevelGen/MapTile.h
This commit is contained in:
commit
2e50097502
BIN
Data/Media/Images/Characters/Reniesta.png
Normal file
BIN
Data/Media/Images/Characters/Reniesta.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
47
README
47
README
@ -1,9 +1,6 @@
|
|||||||
Readme plz!
|
Readme plz!
|
||||||
___________
|
___________
|
||||||
|
|
||||||
I have decided to use Git for SCM of this project.
|
|
||||||
Please see https://github.com/Allanis/Unuk
|
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
I am currently working on a series of algorithms to show off
|
I am currently working on a series of algorithms to show off
|
||||||
@ -11,49 +8,15 @@ for a portfolio piece. I will place this under the GPL licence.
|
|||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~Instructions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
TODO:
|
|
||||||
|
|
||||||
*Menu:
|
Arrow keys/wasd - Move Player.
|
||||||
~~~~~
|
'p' - Show debug information.
|
||||||
- New Game
|
'Space'/'Left Mouse' - Attack.
|
||||||
- SaveGame loading
|
|
||||||
- New screen or make buttons appear on the menu
|
|
||||||
- SaveGame deleting
|
|
||||||
- Game Settings
|
|
||||||
- Keybindings
|
|
||||||
- Fullscreen
|
|
||||||
|
|
||||||
*Fix NPC animation
|
|
||||||
|
|
||||||
*Map Editor:
|
|
||||||
~~~~~~~~~~~~
|
|
||||||
|
|
||||||
- Change the array of tiles into a list of tiles.
|
|
||||||
- Get a tile selection marker and display the current tile info.
|
|
||||||
|
|
||||||
*Proper collision testing.
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
- MapTile objects store a list of character* 's
|
|
||||||
- The character class will add and remove themselves from the list in the MapTile.
|
|
||||||
- When the Character class wants to check for collisions it hands a pointer to
|
|
||||||
itself to the MapTile object, the MapTile will then return true if any
|
|
||||||
Character in it's list collides with the Character* it just recieved.
|
|
||||||
- Create the appropriate methods in the MapTile class
|
|
||||||
- bool CheckCollision(Character *charptr);
|
|
||||||
- void AddCharacter(Character *charptr);
|
|
||||||
- void RemoveCharacter(Character *charptr);
|
|
||||||
|
|
||||||
*A way for entities to store information (Like items).
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
- Sort out how we will read in the information
|
|
||||||
- A list of present objects that can be referenced with a single word in the map file.
|
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
Copyright (C) 2011 SaraCraft
|
Copyright (C) 2011 SaraCraft
|
||||||
allanis@saracraft.net
|
allanis@saracraft.net
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
CONFIG -= qt
|
CONFIG -= qt
|
||||||
|
|
||||||
LIBS += -lGL \
|
LIBS += -lGL \
|
||||||
-lSDL \
|
-lSDL \
|
||||||
-lSDL_ttf \
|
-lSDL_ttf \
|
||||||
@ -7,7 +6,6 @@ LIBS += -lGL \
|
|||||||
-lSDL_gfx \
|
-lSDL_gfx \
|
||||||
-ltinyxml \
|
-ltinyxml \
|
||||||
-lGLU
|
-lGLU
|
||||||
|
|
||||||
HEADERS += ../src/Libs/wglext.h \
|
HEADERS += ../src/Libs/wglext.h \
|
||||||
../src/Libs/glxext.h \
|
../src/Libs/glxext.h \
|
||||||
../src/libUnuk/Engine/WorldManager.h \
|
../src/libUnuk/Engine/WorldManager.h \
|
||||||
@ -47,8 +45,8 @@ HEADERS += ../src/Libs/wglext.h \
|
|||||||
../src/libUnuk/System/Vec2.h \
|
../src/libUnuk/System/Vec2.h \
|
||||||
../src/libUnuk/System/MathBox.h \
|
../src/libUnuk/System/MathBox.h \
|
||||||
../src/libUnuk/Engine/Pathfinding.h \
|
../src/libUnuk/Engine/Pathfinding.h \
|
||||||
../src/libUnuk/UI/SavegameMenu.h
|
../src/libUnuk/UI/SavegameMenu.h \
|
||||||
|
../src/libUnuk/Engine/Spells.h
|
||||||
SOURCES += ../src/libUnuk/Engine/WorldManager.cpp \
|
SOURCES += ../src/libUnuk/Engine/WorldManager.cpp \
|
||||||
../src/libUnuk/Engine/ParticleEmitter.cpp \
|
../src/libUnuk/Engine/ParticleEmitter.cpp \
|
||||||
../src/libUnuk/Engine/NPC.cpp \
|
../src/libUnuk/Engine/NPC.cpp \
|
||||||
@ -82,4 +80,5 @@ SOURCES += ../src/libUnuk/Engine/WorldManager.cpp \
|
|||||||
../src/libUnuk/UI/EventHistory.cpp \
|
../src/libUnuk/UI/EventHistory.cpp \
|
||||||
../src/libUnuk/UI/Bar.cpp \
|
../src/libUnuk/UI/Bar.cpp \
|
||||||
../src/libUnuk/System/Vec2.cpp \
|
../src/libUnuk/System/Vec2.cpp \
|
||||||
../src/libUnuk/UI/SavegameMenu.cpp
|
../src/libUnuk/UI/SavegameMenu.cpp \
|
||||||
|
../src/libUnuk/Engine/Spells.cpp
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
Game::Game(void) {
|
Game::Game(void) {
|
||||||
Debug::logger->message("Creating characters..");
|
Debug::logger->message("Creating characters..");
|
||||||
_player = new Player(&_map);
|
_player = new Player(&_map);
|
||||||
_map.SetPlayer(_player);
|
_map.SetPlayer(_player);
|
||||||
|
|
||||||
_runGameReturnValue = gameMainMenu;
|
_runGameReturnValue = gameMainMenu;
|
||||||
}
|
}
|
||||||
@ -19,29 +19,29 @@ Game::~Game(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::New(const string& savegameIDArg) {
|
void Game::New(const string& savegameIDArg) {
|
||||||
_saveGameID = savegameIDArg;
|
_saveGameID = savegameIDArg;
|
||||||
NewSavegame(savegameIDArg);
|
NewSavegame(savegameIDArg);
|
||||||
|
|
||||||
int spawnX;
|
int spawnX;
|
||||||
int spawnY;
|
int spawnY;
|
||||||
_map.FindSpawnPoint(spawnX, spawnY, 40, 45);
|
_map.FindSpawnPoint(spawnX, spawnY, 40, 45);
|
||||||
|
|
||||||
_player->SetXY((float)spawnX, (float)spawnY);
|
_player->SetXY((float)spawnX, (float)spawnY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Load(const string& savegameIDArg) {
|
void Game::Load(const string& savegameIDArg) {
|
||||||
_saveGameID = savegameIDArg;
|
_saveGameID = savegameIDArg;
|
||||||
LoadSavegame(savegameIDArg);
|
LoadSavegame(savegameIDArg);
|
||||||
|
|
||||||
int spawnX;
|
int spawnX;
|
||||||
int spawnY;
|
int spawnY;
|
||||||
_map.FindSpawnPoint(spawnX, spawnY, 40, 45);
|
_map.FindSpawnPoint(spawnX, spawnY, 40, 45);
|
||||||
|
|
||||||
_player->SetXY((float)spawnX, (float)spawnY);
|
_player->SetXY((float)spawnX, (float)spawnY);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameNavVal_t Game::Run(void) {
|
gameNavVal_t Game::Run(void) {
|
||||||
_player->LoadSprites("../Data/Media/Images/Characters/Player.png", 40, 45);
|
_player->LoadSprites("../Data/Media/Images/Characters/Reniesta.png", 40, 45);
|
||||||
|
|
||||||
int fps = 0;
|
int fps = 0;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
@ -252,10 +252,10 @@ void Game::Render(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::NewSavegame(const string savegameIDArg) {
|
void Game::NewSavegame(const string savegameIDArg) {
|
||||||
string saveFilename = "../Save/" + savegameIDArg;
|
string saveFilename = "../Save/" + savegameIDArg;
|
||||||
|
|
||||||
_map.New();
|
_map.New();
|
||||||
_map.Save(_saveGameID);
|
_map.Save(_saveGameID);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
|
|
||||||
@ -267,11 +267,11 @@ void Game::NewSavegame(const string savegameIDArg) {
|
|||||||
TiXmlText* nameText = new TiXmlText("Allanis"); //TODO: replace with _player->GetName() when it works. --konom
|
TiXmlText* nameText = new TiXmlText("Allanis"); //TODO: replace with _player->GetName() when it works. --konom
|
||||||
nameElement->LinkEndChild(nameText);
|
nameElement->LinkEndChild(nameText);
|
||||||
|
|
||||||
int spawnX;
|
int spawnX;
|
||||||
int spawnY;
|
int spawnY;
|
||||||
_map.FindSpawnPoint(spawnX, spawnY, 40, 45);
|
_map.FindSpawnPoint(spawnX, spawnY, 40, 45);
|
||||||
|
|
||||||
_player->SetXY(spawnX, spawnY);
|
_player->SetXY(spawnX, spawnY);
|
||||||
|
|
||||||
std::stringstream xString;
|
std::stringstream xString;
|
||||||
xString << spawnX;
|
xString << spawnX;
|
||||||
@ -287,21 +287,21 @@ void Game::NewSavegame(const string savegameIDArg) {
|
|||||||
TiXmlText* yText = new TiXmlText(yString.str().c_str());
|
TiXmlText* yText = new TiXmlText(yString.str().c_str());
|
||||||
yElement->LinkEndChild(yText);
|
yElement->LinkEndChild(yText);
|
||||||
|
|
||||||
_player->SetLevelLiteral(1);
|
_player->SetLevelLiteral(1);
|
||||||
|
|
||||||
TiXmlElement* levelElement = new TiXmlElement("level");
|
TiXmlElement* levelElement = new TiXmlElement("level");
|
||||||
TiXmlText* levelText = new TiXmlText("1");
|
TiXmlText* levelText = new TiXmlText("1");
|
||||||
levelElement->LinkEndChild(levelText);
|
levelElement->LinkEndChild(levelText);
|
||||||
|
|
||||||
_player->SetExpLiteral(0);
|
_player->SetExpLiteral(0);
|
||||||
|
|
||||||
TiXmlElement* expElement = new TiXmlElement("exp");
|
TiXmlElement* expElement = new TiXmlElement("exp");
|
||||||
TiXmlText* expText = new TiXmlText("0");
|
TiXmlText* expText = new TiXmlText("0");
|
||||||
expElement->LinkEndChild(expText);
|
expElement->LinkEndChild(expText);
|
||||||
|
|
||||||
TiXmlElement* healthElement = new TiXmlElement("health");
|
TiXmlElement* healthElement = new TiXmlElement("health");
|
||||||
TiXmlText* healthText = new TiXmlText("100");
|
TiXmlText* healthText = new TiXmlText("100");
|
||||||
healthElement->LinkEndChild(healthText);
|
healthElement->LinkEndChild(healthText);
|
||||||
|
|
||||||
TiXmlElement* mapElement = new TiXmlElement("map");
|
TiXmlElement* mapElement = new TiXmlElement("map");
|
||||||
TiXmlText* mapText = new TiXmlText("map"); //TODO: replace with actual map name.
|
TiXmlText* mapText = new TiXmlText("map"); //TODO: replace with actual map name.
|
||||||
@ -310,9 +310,9 @@ void Game::NewSavegame(const string savegameIDArg) {
|
|||||||
saveElement->LinkEndChild(nameElement);
|
saveElement->LinkEndChild(nameElement);
|
||||||
saveElement->LinkEndChild(xElement);
|
saveElement->LinkEndChild(xElement);
|
||||||
saveElement->LinkEndChild(yElement);
|
saveElement->LinkEndChild(yElement);
|
||||||
saveElement->LinkEndChild(levelElement);
|
saveElement->LinkEndChild(levelElement);
|
||||||
saveElement->LinkEndChild(expElement);
|
saveElement->LinkEndChild(expElement);
|
||||||
saveElement->LinkEndChild(healthElement);
|
saveElement->LinkEndChild(healthElement);
|
||||||
saveElement->LinkEndChild(mapElement);
|
saveElement->LinkEndChild(mapElement);
|
||||||
|
|
||||||
doc.LinkEndChild(decl);
|
doc.LinkEndChild(decl);
|
||||||
@ -328,11 +328,11 @@ void Game::LoadSavegame(const string savegameIDArg) {
|
|||||||
// Converting to XML ftw!
|
// Converting to XML ftw!
|
||||||
TiXmlDocument mapFile(saveFilename.c_str());
|
TiXmlDocument mapFile(saveFilename.c_str());
|
||||||
|
|
||||||
// Create new save if can't load file.
|
// Create new save if can't load file.
|
||||||
if(!mapFile.LoadFile()) {
|
if(!mapFile.LoadFile()) {
|
||||||
New(savegameIDArg);
|
New(savegameIDArg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TiXmlElement* rootElem = NULL;
|
TiXmlElement* rootElem = NULL;
|
||||||
TiXmlElement* dataElem = NULL;
|
TiXmlElement* dataElem = NULL;
|
||||||
@ -365,35 +365,35 @@ void Game::LoadSavegame(const string savegameIDArg) {
|
|||||||
_player->SetXY((float)playerX, (float)playerY);
|
_player->SetXY((float)playerX, (float)playerY);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// <level> - Parse the player level.
|
// <level> - Parse the player level.
|
||||||
dataElem = dataElem->NextSiblingElement("level");
|
dataElem = dataElem->NextSiblingElement("level");
|
||||||
assert(dataElem != NULL);
|
assert(dataElem != NULL);
|
||||||
int playerLevel = atoi(dataElem->GetText());
|
int playerLevel = atoi(dataElem->GetText());
|
||||||
// </level>
|
// </level>
|
||||||
|
|
||||||
_player->SetLevelLiteral(playerLevel);
|
_player->SetLevelLiteral(playerLevel);
|
||||||
|
|
||||||
// <exp> - Parse the player exp.
|
// <exp> - Parse the player exp.
|
||||||
dataElem = dataElem->NextSiblingElement("exp");
|
dataElem = dataElem->NextSiblingElement("exp");
|
||||||
assert(dataElem != NULL);
|
assert(dataElem != NULL);
|
||||||
int playerExp = atoi(dataElem->GetText());
|
int playerExp = atoi(dataElem->GetText());
|
||||||
// </exp>
|
// </exp>
|
||||||
|
|
||||||
_player->SetExpLiteral(playerExp);
|
_player->SetExpLiteral(playerExp);
|
||||||
|
|
||||||
// <health> - Parse the player health.
|
// <health> - Parse the player health.
|
||||||
dataElem = dataElem->NextSiblingElement("health");
|
dataElem = dataElem->NextSiblingElement("health");
|
||||||
assert(dataElem != NULL);
|
assert(dataElem != NULL);
|
||||||
int playerHealth = atoi(dataElem->GetText());
|
int playerHealth = atoi(dataElem->GetText());
|
||||||
// </health>
|
// </health>
|
||||||
|
|
||||||
_player->SetHealthLiteral(playerHealth);
|
_player->SetHealthLiteral(playerHealth);
|
||||||
}
|
}
|
||||||
// <save>
|
// <save>
|
||||||
|
|
||||||
// </save>
|
// </save>
|
||||||
|
|
||||||
_map.Load(_saveGameID);
|
_map.Load(_saveGameID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::SaveSavegame(void) {
|
void Game::SaveSavegame(void) {
|
||||||
@ -425,38 +425,38 @@ void Game::SaveSavegame(void) {
|
|||||||
yElement->LinkEndChild(yText);
|
yElement->LinkEndChild(yText);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::stringstream levelString;
|
std::stringstream levelString;
|
||||||
levelString << _player->GetLevel();
|
levelString << _player->GetLevel();
|
||||||
|
|
||||||
TiXmlElement* levelElement = new TiXmlElement("level");
|
TiXmlElement* levelElement = new TiXmlElement("level");
|
||||||
TiXmlText* levelText = new TiXmlText(levelString.str().c_str());
|
TiXmlText* levelText = new TiXmlText(levelString.str().c_str());
|
||||||
levelElement->LinkEndChild(levelText);
|
levelElement->LinkEndChild(levelText);
|
||||||
|
|
||||||
std::stringstream expString;
|
std::stringstream expString;
|
||||||
expString << _player->GetExp();
|
expString << _player->GetExp();
|
||||||
|
|
||||||
TiXmlElement* expElement = new TiXmlElement("exp");
|
TiXmlElement* expElement = new TiXmlElement("exp");
|
||||||
TiXmlText* expText = new TiXmlText(expString.str().c_str());
|
TiXmlText* expText = new TiXmlText(expString.str().c_str());
|
||||||
expElement->LinkEndChild(expText);
|
expElement->LinkEndChild(expText);
|
||||||
|
|
||||||
std::stringstream healthString;
|
std::stringstream healthString;
|
||||||
healthString << _player->GetHealth();
|
healthString << _player->GetHealth();
|
||||||
|
|
||||||
TiXmlElement* healthElement = new TiXmlElement("health");
|
TiXmlElement* healthElement = new TiXmlElement("health");
|
||||||
TiXmlText* healthText = new TiXmlText(healthString.str().c_str());
|
TiXmlText* healthText = new TiXmlText(healthString.str().c_str());
|
||||||
healthElement->LinkEndChild(healthText);
|
healthElement->LinkEndChild(healthText);
|
||||||
|
|
||||||
saveElement->LinkEndChild(nameElement);
|
saveElement->LinkEndChild(nameElement);
|
||||||
//saveElement->LinkEndChild(xElement);
|
//saveElement->LinkEndChild(xElement);
|
||||||
//saveElement->LinkEndChild(yElement);
|
//saveElement->LinkEndChild(yElement);
|
||||||
saveElement->LinkEndChild(levelElement);
|
saveElement->LinkEndChild(levelElement);
|
||||||
saveElement->LinkEndChild(expElement);
|
saveElement->LinkEndChild(expElement);
|
||||||
saveElement->LinkEndChild(healthElement);
|
saveElement->LinkEndChild(healthElement);
|
||||||
|
|
||||||
doc.LinkEndChild(decl);
|
doc.LinkEndChild(decl);
|
||||||
doc.LinkEndChild(saveElement);
|
doc.LinkEndChild(saveElement);
|
||||||
|
|
||||||
doc.SaveFile(saveFilename.c_str());
|
doc.SaveFile(saveFilename.c_str());
|
||||||
|
|
||||||
_map.Save(_saveGameID);
|
_map.Save(_saveGameID);
|
||||||
}
|
}
|
||||||
|
@ -23,46 +23,46 @@ enum gameNavVal_t { gameMainMenu, gameQuitGame };
|
|||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
public:
|
public:
|
||||||
Game(void);
|
Game(void);
|
||||||
~Game(void);
|
~Game(void);
|
||||||
|
|
||||||
void New(const string& savegameIDArg);
|
void New(const string& savegameIDArg);
|
||||||
void Load(const string& savegameIDArg);
|
void Load(const string& savegameIDArg);
|
||||||
|
|
||||||
gameNavVal_t Run(void);
|
gameNavVal_t Run(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void HandleInput(void);
|
void HandleInput(void);
|
||||||
void UpdateGame(void);
|
void UpdateGame(void);
|
||||||
void Render(void);
|
void Render(void);
|
||||||
|
|
||||||
void NewSavegame(const string savegameIDArg);
|
void NewSavegame(const string savegameIDArg);
|
||||||
void LoadSavegame(const string savegameIDArg);
|
void LoadSavegame(const string savegameIDArg);
|
||||||
void SaveSavegame(void);
|
void SaveSavegame(void);
|
||||||
|
|
||||||
static const int MAX_FPS = 200;
|
static const int MAX_FPS = 200;
|
||||||
static const int GAME_UPDATES_PER_SECOND = 60;
|
static const int GAME_UPDATES_PER_SECOND = 60;
|
||||||
static const int SKIP_TICKS = 1000 / GAME_UPDATES_PER_SECOND;
|
static const int SKIP_TICKS = 1000 / GAME_UPDATES_PER_SECOND;
|
||||||
|
|
||||||
bool _gameRunning;
|
bool _gameRunning;
|
||||||
|
|
||||||
gameNavVal_t _runGameReturnValue;
|
gameNavVal_t _runGameReturnValue;
|
||||||
|
|
||||||
string _saveGameID;
|
string _saveGameID;
|
||||||
string _mapID;
|
string _mapID;
|
||||||
|
|
||||||
Text _gameUpdateTime;
|
Text _gameUpdateTime;
|
||||||
Text _gameRenderTime;
|
Text _gameRenderTime;
|
||||||
Text _playerXY;
|
Text _playerXY;
|
||||||
Text _npcHealth;
|
Text _npcHealth;
|
||||||
|
|
||||||
IngameMenu _ingameMenu;
|
IngameMenu _ingameMenu;
|
||||||
LevelGen _map;
|
LevelGen _map;
|
||||||
|
|
||||||
Player* _player;
|
Player* _player;
|
||||||
|
|
||||||
Text _playerHealth;
|
Text _playerHealth;
|
||||||
Text _playerExp;
|
Text _playerExp;
|
||||||
Bar _playerHealthBar;
|
Bar _playerHealthBar;
|
||||||
Bar _playerExpBar;
|
Bar _playerExpBar;
|
||||||
};
|
};
|
||||||
|
@ -17,23 +17,23 @@ const int Player::EXP_TABLE[MAX_LEVEL] = {
|
|||||||
2000,
|
2000,
|
||||||
3500,
|
3500,
|
||||||
5000,
|
5000,
|
||||||
6500,
|
6500,
|
||||||
8500,
|
8500,
|
||||||
10250,
|
10250,
|
||||||
12000,
|
12000,
|
||||||
15000,
|
15000,
|
||||||
25000,
|
25000,
|
||||||
50000,
|
50000,
|
||||||
65000,
|
65000,
|
||||||
80000,
|
80000,
|
||||||
100000
|
100000
|
||||||
};
|
};
|
||||||
|
|
||||||
Player::Player(LevelGen *mapArg) : Character(mapArg) {
|
Player::Player(LevelGen *mapArg) : Character(mapArg) {
|
||||||
_level = 1;
|
_level = 1;
|
||||||
_exp = 0;
|
_exp = 0;
|
||||||
_lastTileX = 0;
|
_lastTileX = 0;
|
||||||
_lastTileY = 0;
|
_lastTileY = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player(void) {
|
Player::~Player(void) {
|
||||||
@ -101,14 +101,14 @@ void Player::Update(void) {
|
|||||||
// For now The camera will be static.
|
// For now The camera will be static.
|
||||||
//SetCamera();
|
//SetCamera();
|
||||||
|
|
||||||
int tileX = x / TILE_WIDTH;
|
int tileX = x / TILE_WIDTH;
|
||||||
int tileY = y / TILE_HEIGHT;
|
int tileY = y / TILE_HEIGHT;
|
||||||
if(tileX != _lastTileX || tileY != _lastTileY) {
|
if(tileX != _lastTileX || tileY != _lastTileY) {
|
||||||
_lastTileX = tileX;
|
_lastTileX = tileX;
|
||||||
_lastTileY = tileY;
|
_lastTileY = tileY;
|
||||||
|
|
||||||
map->GetWorld().OnPlayerMove(this);
|
map->GetWorld().OnPlayerMove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
_healthBar.SetProgress((float)GetHealth() / 100.0f);
|
_healthBar.SetProgress((float)GetHealth() / 100.0f);
|
||||||
}
|
}
|
||||||
@ -133,8 +133,8 @@ void Player::SetCamera(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::Move() {
|
void Player::Move() {
|
||||||
map->MoveIfPossible(this, xVel, yVel, true);
|
map->MoveIfPossible(this, xVel, yVel, true);
|
||||||
Character::HealthBarScroll();
|
Character::HealthBarScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SetLevel(int level) {
|
void Player::SetLevel(int level) {
|
||||||
@ -143,10 +143,10 @@ void Player::SetLevel(int level) {
|
|||||||
if(_exp < 0) {
|
if(_exp < 0) {
|
||||||
_exp = 0;
|
_exp = 0;
|
||||||
}
|
}
|
||||||
if(_level == MAX_LEVEL) {
|
if(_level == MAX_LEVEL) {
|
||||||
eventHistory->LogEvent("YOU BEAT IT! I'M SO PROUD!");
|
eventHistory->LogEvent("YOU BEAT IT! I'M SO PROUD!");
|
||||||
eventHistory->LogEvent("*Sheds Tear*");
|
eventHistory->LogEvent("*Sheds Tear*");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SetExp(int exp) {
|
void Player::SetExp(int exp) {
|
||||||
|
@ -4,46 +4,46 @@
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "../libUnuk/Engine/Character.h"
|
#include "../libUnuk/Engine/Character.h"
|
||||||
#include "../libUnuk//System/Debug.h"
|
#include "../libUnuk/System/Debug.h"
|
||||||
|
|
||||||
class Player : public Character {
|
class Player : public Character {
|
||||||
public:
|
public:
|
||||||
Player(LevelGen* mapArg);
|
Player(LevelGen* mapArg);
|
||||||
~Player(void);
|
~Player(void);
|
||||||
|
|
||||||
void HandleInput(void);
|
void HandleInput(void);
|
||||||
void Update(void);
|
void Update(void);
|
||||||
|
|
||||||
void SetName(string nameArg);
|
void SetName(string nameArg);
|
||||||
string GetName(void) { return _name; }
|
string GetName(void) { return _name; }
|
||||||
|
|
||||||
void SetLevel(int level);
|
void SetLevel(int level);
|
||||||
int GetLevel(void) { return _level; }
|
int GetLevel(void) { return _level; }
|
||||||
|
|
||||||
void SetExp(int exp);
|
void SetExp(int exp);
|
||||||
int GetExp(void) { return _exp; }
|
int GetExp(void) { return _exp; }
|
||||||
|
|
||||||
void SetLevelLiteral(int level) { _level = level; }
|
void SetLevelLiteral(int level) { _level = level; }
|
||||||
void SetExpLiteral(int exp) { _exp = exp; }
|
void SetExpLiteral(int exp) { _exp = exp; }
|
||||||
void SetHealthLiteral(int health) { _health = health; }
|
void SetHealthLiteral(int health) { _health = health; }
|
||||||
|
|
||||||
void SetXY(float xArg, float yArg) { x = xArg, y = yArg; _lastTileX = xArg / TILE_WIDTH; _lastTileY = yArg / TILE_HEIGHT; }
|
void SetXY(float xArg, float yArg) { x = xArg, y = yArg; _lastTileX = xArg / TILE_WIDTH; _lastTileY = yArg / TILE_HEIGHT; }
|
||||||
|
|
||||||
static const int MAX_LEVEL = 20;
|
static const int MAX_LEVEL = 20;
|
||||||
static const int EXP_TABLE[MAX_LEVEL];
|
static const int EXP_TABLE[MAX_LEVEL];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Move(void);
|
void Move(void);
|
||||||
void CheckTileCollisions(void);
|
void CheckTileCollisions(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetCamera(void);
|
void SetCamera(void);
|
||||||
static const float PLAYER_SPEED;
|
static const float PLAYER_SPEED;
|
||||||
|
|
||||||
string _name;
|
string _name;
|
||||||
int _level;
|
int _level;
|
||||||
int _exp;
|
int _exp;
|
||||||
|
|
||||||
int _lastTileX;
|
int _lastTileX;
|
||||||
int _lastTileY;
|
int _lastTileY;
|
||||||
};
|
};
|
||||||
|
@ -45,28 +45,29 @@ public:
|
|||||||
|
|
||||||
void OnAttack(void);
|
void OnAttack(void);
|
||||||
|
|
||||||
// inline void* operator new(size_t size) {
|
// Overload new and delete operators to utilize MemManager.
|
||||||
// return gMemManager.Allocate(size);
|
inline void* operator new(size_t size) {
|
||||||
// }
|
return gMemManager.Allocate(size);
|
||||||
//
|
}
|
||||||
// inline void operator delete(void* object) {
|
|
||||||
// gMemManager.Free(object);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// inline void* operator new [](size_t size) {
|
|
||||||
// return gMemManager.Allocate(size);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// inline void operator delete [](void* object) {
|
|
||||||
// gMemManager.Free(object);
|
|
||||||
// }
|
|
||||||
|
|
||||||
enum {
|
inline void operator delete(void* object) {
|
||||||
FACING_UP,
|
gMemManager.Free(object);
|
||||||
FACING_RIGHT,
|
}
|
||||||
FACING_DOWN,
|
|
||||||
FACING_LEFT
|
inline void* operator new [](size_t size) {
|
||||||
};
|
return gMemManager.Allocate(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void operator delete [](void* object) {
|
||||||
|
gMemManager.Free(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum {
|
||||||
|
FACING_UP,
|
||||||
|
FACING_RIGHT,
|
||||||
|
FACING_DOWN,
|
||||||
|
FACING_LEFT
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void HealthBarScroll(void);
|
void HealthBarScroll(void);
|
||||||
|
@ -4,203 +4,203 @@
|
|||||||
MemManager gMemManager;
|
MemManager gMemManager;
|
||||||
|
|
||||||
void BitMapEntry::SetBit(int position, bool flag) {
|
void BitMapEntry::SetBit(int position, bool flag) {
|
||||||
blocksAvailable += flag ? 1 : -1;
|
blocksAvailable += flag ? 1 : -1;
|
||||||
int elementNo = position / INT_SIZE;
|
int elementNo = position / INT_SIZE;
|
||||||
int bitNo = position % INT_SIZE;
|
int bitNo = position % INT_SIZE;
|
||||||
if(flag)
|
if(flag)
|
||||||
bitMap[elementNo] = bitMap[elementNo] | (1 << bitNo);
|
bitMap[elementNo] = bitMap[elementNo] | (1 << bitNo);
|
||||||
else
|
else
|
||||||
bitMap[elementNo] = bitMap[elementNo] & ~(1 << bitNo);
|
bitMap[elementNo] = bitMap[elementNo] & ~(1 << bitNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitMapEntry::SetMultipleBits(int position, bool flag, int count) {
|
void BitMapEntry::SetMultipleBits(int position, bool flag, int count) {
|
||||||
blocksAvailable += flag ? count : -count;
|
blocksAvailable += flag ? count : -count;
|
||||||
int elementNo = position / INT_SIZE;
|
int elementNo = position / INT_SIZE;
|
||||||
int bitNo = position % INT_SIZE;
|
int bitNo = position % INT_SIZE;
|
||||||
|
|
||||||
int bitSize = (count <= INT_SIZE - bitNo) ? count : INT_SIZE - bitNo;
|
int bitSize = (count <= INT_SIZE - bitNo) ? count : INT_SIZE - bitNo;
|
||||||
SetRangeOfInt(&bitMap[elementNo], bitNo + bitSize - 1, bitNo, flag);
|
SetRangeOfInt(&bitMap[elementNo], bitNo + bitSize - 1, bitNo, flag);
|
||||||
count -= bitSize;
|
count -= bitSize;
|
||||||
if(!count) return;
|
if(!count) return;
|
||||||
|
|
||||||
int i = ++elementNo;
|
int i = ++elementNo;
|
||||||
while(count >= 0) {
|
while(count >= 0) {
|
||||||
if(count <= INT_SIZE) {
|
if(count <= INT_SIZE) {
|
||||||
SetRangeOfInt(&bitMap[i], count - 1, 0, flag);
|
SetRangeOfInt(&bitMap[i], count - 1, 0, flag);
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
bitMap[i] = flag ? unsigned (-1) : 0;
|
bitMap[i] = flag ? unsigned (-1) : 0;
|
||||||
count -= 32;
|
count -= 32;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitMapEntry::SetRangeOfInt(int* element, int msb, int lsb, bool flag) {
|
void BitMapEntry::SetRangeOfInt(int* element, int msb, int lsb, bool flag) {
|
||||||
if(flag) {
|
if(flag) {
|
||||||
int mask = (unsigned(-1) << lsb) & (unsigned(-1) >> (INT_SIZE - msb - 1));
|
int mask = (unsigned(-1) << lsb) & (unsigned(-1) >> (INT_SIZE - msb - 1));
|
||||||
*element |= mask;
|
*element |= mask;
|
||||||
} else {
|
} else {
|
||||||
int mask = (unsigned(-1) << lsb) & (unsigned(-1) >> (INT_SIZE - msb - 1));
|
int mask = (unsigned(-1) << lsb) & (unsigned(-1) >> (INT_SIZE - msb - 1));
|
||||||
*element &= ~mask;
|
*element &= ~mask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MemClass* BitMapEntry::FirstFreeBlock(size_t/* size*/) {
|
MemClass* BitMapEntry::FirstFreeBlock(size_t/* size*/) {
|
||||||
for(int i = 0; i < BIT_MAP_ELEMENTS; i++) {
|
for(int i = 0; i < BIT_MAP_ELEMENTS; i++) {
|
||||||
if(bitMap[i] == 0)
|
if(bitMap[i] == 0)
|
||||||
// There aint any bits free.
|
// There aint any bits free.
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Yield the first bit position. This is a 1
|
// Yield the first bit position. This is a 1
|
||||||
// in an int from the right.
|
// in an int from the right.
|
||||||
int result = bitMap[i] & -(bitMap[i]);
|
int result = bitMap[i] & -(bitMap[i]);
|
||||||
//void* address = 0;
|
//void* address = 0;
|
||||||
int basePos = (INT_SIZE * i);
|
int basePos = (INT_SIZE * i);
|
||||||
|
|
||||||
switch(result) {
|
switch(result) {
|
||||||
// Make the corresponfing bit 0 so block is no longer free.
|
// Make the corresponfing bit 0 so block is no longer free.
|
||||||
case 0x00000001: return ComplexObjectAddress(basePos + 0);
|
case 0x00000001: return ComplexObjectAddress(basePos + 0);
|
||||||
case 0x00000002: return ComplexObjectAddress(basePos + 1);
|
case 0x00000002: return ComplexObjectAddress(basePos + 1);
|
||||||
case 0x00000004: return ComplexObjectAddress(basePos + 2);
|
case 0x00000004: return ComplexObjectAddress(basePos + 2);
|
||||||
case 0x00000008: return ComplexObjectAddress(basePos + 3);
|
case 0x00000008: return ComplexObjectAddress(basePos + 3);
|
||||||
case 0x00000010: return ComplexObjectAddress(basePos + 4);
|
case 0x00000010: return ComplexObjectAddress(basePos + 4);
|
||||||
case 0x00000020: return ComplexObjectAddress(basePos + 5);
|
case 0x00000020: return ComplexObjectAddress(basePos + 5);
|
||||||
case 0x00000040: return ComplexObjectAddress(basePos + 6);
|
case 0x00000040: return ComplexObjectAddress(basePos + 6);
|
||||||
case 0x00000080: return ComplexObjectAddress(basePos + 7);
|
case 0x00000080: return ComplexObjectAddress(basePos + 7);
|
||||||
case 0x00000100: return ComplexObjectAddress(basePos + 8);
|
case 0x00000100: return ComplexObjectAddress(basePos + 8);
|
||||||
case 0x00000200: return ComplexObjectAddress(basePos + 9);
|
case 0x00000200: return ComplexObjectAddress(basePos + 9);
|
||||||
case 0x00000400: return ComplexObjectAddress(basePos + 10);
|
case 0x00000400: return ComplexObjectAddress(basePos + 10);
|
||||||
case 0x00000800: return ComplexObjectAddress(basePos + 11);
|
case 0x00000800: return ComplexObjectAddress(basePos + 11);
|
||||||
case 0x00001000: return ComplexObjectAddress(basePos + 12);
|
case 0x00001000: return ComplexObjectAddress(basePos + 12);
|
||||||
case 0x00002000: return ComplexObjectAddress(basePos + 13);
|
case 0x00002000: return ComplexObjectAddress(basePos + 13);
|
||||||
case 0x00004000: return ComplexObjectAddress(basePos + 14);
|
case 0x00004000: return ComplexObjectAddress(basePos + 14);
|
||||||
case 0x00008000: return ComplexObjectAddress(basePos + 15);
|
case 0x00008000: return ComplexObjectAddress(basePos + 15);
|
||||||
case 0x00010000: return ComplexObjectAddress(basePos + 16);
|
case 0x00010000: return ComplexObjectAddress(basePos + 16);
|
||||||
case 0x00020000: return ComplexObjectAddress(basePos + 17);
|
case 0x00020000: return ComplexObjectAddress(basePos + 17);
|
||||||
case 0x00040000: return ComplexObjectAddress(basePos + 18);
|
case 0x00040000: return ComplexObjectAddress(basePos + 18);
|
||||||
case 0x00080000: return ComplexObjectAddress(basePos + 19);
|
case 0x00080000: return ComplexObjectAddress(basePos + 19);
|
||||||
case 0x00100000: return ComplexObjectAddress(basePos + 20);
|
case 0x00100000: return ComplexObjectAddress(basePos + 20);
|
||||||
case 0x00200000: return ComplexObjectAddress(basePos + 21);
|
case 0x00200000: return ComplexObjectAddress(basePos + 21);
|
||||||
case 0x00400000: return ComplexObjectAddress(basePos + 22);
|
case 0x00400000: return ComplexObjectAddress(basePos + 22);
|
||||||
case 0x00800000: return ComplexObjectAddress(basePos + 23);
|
case 0x00800000: return ComplexObjectAddress(basePos + 23);
|
||||||
case 0x01000000: return ComplexObjectAddress(basePos + 24);
|
case 0x01000000: return ComplexObjectAddress(basePos + 24);
|
||||||
case 0x02000000: return ComplexObjectAddress(basePos + 25);
|
case 0x02000000: return ComplexObjectAddress(basePos + 25);
|
||||||
case 0x04000000: return ComplexObjectAddress(basePos + 26);
|
case 0x04000000: return ComplexObjectAddress(basePos + 26);
|
||||||
case 0x08000000: return ComplexObjectAddress(basePos + 27);
|
case 0x08000000: return ComplexObjectAddress(basePos + 27);
|
||||||
case 0x10000000: return ComplexObjectAddress(basePos + 28);
|
case 0x10000000: return ComplexObjectAddress(basePos + 28);
|
||||||
case 0x20000000: return ComplexObjectAddress(basePos + 29);
|
case 0x20000000: return ComplexObjectAddress(basePos + 29);
|
||||||
case 0x40000000: return ComplexObjectAddress(basePos + 30);
|
case 0x40000000: return ComplexObjectAddress(basePos + 30);
|
||||||
case 0x80000000: return ComplexObjectAddress(basePos + 31);
|
case 0x80000000: return ComplexObjectAddress(basePos + 31);
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemClass* BitMapEntry::ComplexObjectAddress(int pos) {
|
MemClass* BitMapEntry::ComplexObjectAddress(int pos) {
|
||||||
SetBit(pos, false);
|
SetBit(pos, false);
|
||||||
return &((static_cast<MemClass*>(Head()) + (pos / INT_SIZE)) [INT_SIZE - (pos % INT_SIZE + 1)]);
|
return &((static_cast<MemClass*>(Head()) + (pos / INT_SIZE)) [INT_SIZE - (pos % INT_SIZE + 1)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* BitMapEntry::Head(void) {
|
void* BitMapEntry::Head(void) {
|
||||||
return gMemManager.GetMemoryPoolList()[index];
|
return gMemManager.GetMemoryPoolList()[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MemManager::Allocate(size_t size) {
|
void* MemManager::Allocate(size_t size) {
|
||||||
// None array.
|
// None array.
|
||||||
if(size == sizeof(MemClass)) {
|
if(size == sizeof(MemClass)) {
|
||||||
set<BitMapEntry*>::iterator freeMapI = _freeMapEntries.begin();
|
set<BitMapEntry*>::iterator freeMapI = _freeMapEntries.begin();
|
||||||
if(freeMapI != _freeMapEntries.end()) {
|
if(freeMapI != _freeMapEntries.end()) {
|
||||||
BitMapEntry* mapEntry = *freeMapI;
|
BitMapEntry* mapEntry = *freeMapI;
|
||||||
return mapEntry->FirstFreeBlock(size);
|
return mapEntry->FirstFreeBlock(size);
|
||||||
} else {
|
} else {
|
||||||
AllocateChunkAndInitBitMap();
|
AllocateChunkAndInitBitMap();
|
||||||
_freeMapEntries.insert(&(_bitMapEntryList[_bitMapEntryList.size() - 1]));
|
_freeMapEntries.insert(&(_bitMapEntryList[_bitMapEntryList.size() - 1]));
|
||||||
return _bitMapEntryList[_bitMapEntryList.size() - 1].FirstFreeBlock(size);
|
return _bitMapEntryList[_bitMapEntryList.size() - 1].FirstFreeBlock(size);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Array.
|
// Array.
|
||||||
if(_arrayMemoryList.empty()) {
|
if(_arrayMemoryList.empty()) {
|
||||||
return AllocateArrayMemory(size);
|
return AllocateArrayMemory(size);
|
||||||
} else {
|
} else {
|
||||||
map<void*, ArrayMemoryInfo>::iterator infoI = _arrayMemoryList.begin();
|
map<void*, ArrayMemoryInfo>::iterator infoI = _arrayMemoryList.begin();
|
||||||
map<void*, ArrayMemoryInfo>::iterator infoEndI = _arrayMemoryList.end();
|
map<void*, ArrayMemoryInfo>::iterator infoEndI = _arrayMemoryList.end();
|
||||||
|
|
||||||
while(infoI != infoEndI) {
|
while(infoI != infoEndI) {
|
||||||
ArrayMemoryInfo info = (*infoI).second;
|
ArrayMemoryInfo info = (*infoI).second;
|
||||||
if(info.StartPosition != 0)
|
if(info.StartPosition != 0)
|
||||||
// Only search the memory blocks where allocation
|
// Only search the memory blocks where allocation
|
||||||
// is done from first byte.
|
// is done from first byte.
|
||||||
continue;
|
continue;
|
||||||
else {
|
else {
|
||||||
BitMapEntry* entry = &_bitMapEntryList[info.memPoolListIndex];
|
BitMapEntry* entry = &_bitMapEntryList[info.memPoolListIndex];
|
||||||
if(entry->blocksAvailable < (size / sizeof(MemClass)))
|
if(entry->blocksAvailable < (size / sizeof(MemClass)))
|
||||||
return AllocateArrayMemory(size);
|
return AllocateArrayMemory(size);
|
||||||
else {
|
else {
|
||||||
info.StartPosition = BIT_MAP_SIZE - entry->blocksAvailable;
|
info.StartPosition = BIT_MAP_SIZE - entry->blocksAvailable;
|
||||||
info.Size = size / sizeof(MemClass);
|
info.Size = size / sizeof(MemClass);
|
||||||
MemClass* baseAddress = static_cast<MemClass*>(_memoryPoolList[info.memPoolListIndex]) + info.StartPosition;
|
MemClass* baseAddress = static_cast<MemClass*>(_memoryPoolList[info.memPoolListIndex]) + info.StartPosition;
|
||||||
|
|
||||||
_arrayMemoryList[baseAddress] = info;
|
_arrayMemoryList[baseAddress] = info;
|
||||||
SetMultipleBlockBits(&info, false);
|
SetMultipleBlockBits(&info, false);
|
||||||
|
|
||||||
return baseAddress;
|
return baseAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MemManager::AllocateArrayMemory(size_t size) {
|
void* MemManager::AllocateArrayMemory(size_t size) {
|
||||||
void* chunkAddress = AllocateChunkAndInitBitMap();
|
void* chunkAddress = AllocateChunkAndInitBitMap();
|
||||||
ArrayMemoryInfo info;
|
ArrayMemoryInfo info;
|
||||||
info.memPoolListIndex = _memoryPoolList.size() - 1;
|
info.memPoolListIndex = _memoryPoolList.size() - 1;
|
||||||
info.StartPosition = 0;
|
info.StartPosition = 0;
|
||||||
info.Size = size / sizeof(MemClass);
|
info.Size = size / sizeof(MemClass);
|
||||||
_arrayMemoryList[chunkAddress] = info;
|
_arrayMemoryList[chunkAddress] = info;
|
||||||
SetMultipleBlockBits(&info, false);
|
SetMultipleBlockBits(&info, false);
|
||||||
return chunkAddress;
|
return chunkAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MemManager::AllocateChunkAndInitBitMap(void) {
|
void* MemManager::AllocateChunkAndInitBitMap(void) {
|
||||||
BitMapEntry mapEntry;
|
BitMapEntry mapEntry;
|
||||||
MemClass* memoryBeginAddress = reinterpret_cast<MemClass*>(new char[sizeof(MemClass) * BIT_MAP_SIZE]);
|
MemClass* memoryBeginAddress = reinterpret_cast<MemClass*>(new char[sizeof(MemClass) * BIT_MAP_SIZE]);
|
||||||
_memoryPoolList.push_back(memoryBeginAddress);
|
_memoryPoolList.push_back(memoryBeginAddress);
|
||||||
mapEntry.index = _memoryPoolList.size() - 1;
|
mapEntry.index = _memoryPoolList.size() - 1;
|
||||||
_bitMapEntryList.push_back(mapEntry);
|
_bitMapEntryList.push_back(mapEntry);
|
||||||
return memoryBeginAddress;
|
return memoryBeginAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemManager::Free(void* object) {
|
void MemManager::Free(void* object) {
|
||||||
if(_arrayMemoryList.find(object) == _arrayMemoryList.end())
|
if(_arrayMemoryList.find(object) == _arrayMemoryList.end())
|
||||||
// Simple block deletion.
|
// Simple block deletion.
|
||||||
SetBlockBit(object, true);
|
SetBlockBit(object, true);
|
||||||
else {
|
else {
|
||||||
// Memory block deletion.
|
// Memory block deletion.
|
||||||
ArrayMemoryInfo *info = &_arrayMemoryList[object];
|
ArrayMemoryInfo *info = &_arrayMemoryList[object];
|
||||||
SetMultipleBlockBits(info, true);
|
SetMultipleBlockBits(info, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemManager::SetBlockBit(void* object, bool flag) {
|
void MemManager::SetBlockBit(void* object, bool flag) {
|
||||||
int i = _bitMapEntryList.size() - 1;
|
int i = _bitMapEntryList.size() - 1;
|
||||||
for(; i >= 0; i--) {
|
for(; i >= 0; i--) {
|
||||||
BitMapEntry* bitMap = &_bitMapEntryList[i];
|
BitMapEntry* bitMap = &_bitMapEntryList[i];
|
||||||
if((bitMap->Head() <= object) && (&(static_cast<MemClass*>(bitMap->Head()))[BIT_MAP_SIZE - 1] >= object)) {
|
if((bitMap->Head() <= object) && (&(static_cast<MemClass*>(bitMap->Head()))[BIT_MAP_SIZE - 1] >= object)) {
|
||||||
int position = static_cast<MemClass*>(object)- static_cast<MemClass*>(bitMap->Head());
|
int position = static_cast<MemClass*>(object)- static_cast<MemClass*>(bitMap->Head());
|
||||||
bitMap->SetBit(position, flag);
|
bitMap->SetBit(position, flag);
|
||||||
flag ? bitMap->blocksAvailable++ : bitMap->blocksAvailable--;
|
flag ? bitMap->blocksAvailable++ : bitMap->blocksAvailable--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemManager::SetMultipleBlockBits(ArrayMemoryInfo* info, bool flag) {
|
void MemManager::SetMultipleBlockBits(ArrayMemoryInfo* info, bool flag) {
|
||||||
BitMapEntry* mapEntry = &_bitMapEntryList[info->memPoolListIndex];
|
BitMapEntry* mapEntry = &_bitMapEntryList[info->memPoolListIndex];
|
||||||
mapEntry->SetMultipleBits(info->StartPosition, flag, info->Size);
|
mapEntry->SetMultipleBits(info->StartPosition, flag, info->Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<void*>& MemManager::GetMemoryPoolList(void) {
|
vector<void*>& MemManager::GetMemoryPoolList(void) {
|
||||||
return _memoryPoolList;
|
return _memoryPoolList;
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,17 @@ void NPC::ForceMove(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NPC::Update(void) {
|
void NPC::Update(void) {
|
||||||
// Store the NPC's health.
|
// Store the NPC's health.
|
||||||
// int health = GetHealth(); // not referenced
|
// int health = GetHealth(); // not referenced
|
||||||
|
|
||||||
Move();
|
Move();
|
||||||
|
|
||||||
if(xVel > 0) directionFacing = FACING_RIGHT;
|
if(xVel > 0) directionFacing = FACING_RIGHT;
|
||||||
else if(xVel < 0) directionFacing = FACING_LEFT;
|
else if(xVel < 0) directionFacing = FACING_LEFT;
|
||||||
else if(yVel > 0) directionFacing = FACING_DOWN;
|
else if(yVel > 0) directionFacing = FACING_DOWN;
|
||||||
else if(yVel < 0) directionFacing = FACING_UP;
|
else if(yVel < 0) directionFacing = FACING_UP;
|
||||||
|
|
||||||
_healthBar.SetProgress((float)GetHealth() / 100.0f);
|
_healthBar.SetProgress((float)GetHealth() / 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NPC::Move(void) {
|
void NPC::Move(void) {
|
||||||
|
@ -9,72 +9,72 @@ ParticleEmitter::~ParticleEmitter(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::SetXY(int xArg, int yArg) {
|
void ParticleEmitter::SetXY(int xArg, int yArg) {
|
||||||
x = xArg;
|
x = xArg;
|
||||||
y = yArg;
|
y = yArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::ForceXY(int xArg, int yArg) {
|
void ParticleEmitter::ForceXY(int xArg, int yArg) {
|
||||||
for(int i = 0; i < _particleCount; i++) {
|
for(int i = 0; i < _particleCount; i++) {
|
||||||
m_particle[i].x = (float)xArg;
|
m_particle[i].x = (float)xArg;
|
||||||
m_particle[i].y = (float)yArg;
|
m_particle[i].y = (float)yArg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::SetParticleCount(int countArg) {
|
void ParticleEmitter::SetParticleCount(int countArg) {
|
||||||
_particleCount = countArg;
|
_particleCount = countArg;
|
||||||
m_particle.resize(_particleCount);
|
m_particle.resize(_particleCount);
|
||||||
|
|
||||||
for(int i = 0; i < _particleCount; i++) {
|
for(int i = 0; i < _particleCount; i++) {
|
||||||
m_particle[i].startTime = SDL_GetTicks();
|
m_particle[i].startTime = SDL_GetTicks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::SetParticleSpeed(float speedArg) {
|
void ParticleEmitter::SetParticleSpeed(float speedArg) {
|
||||||
_particleSpeed = speedArg;
|
_particleSpeed = speedArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::SetParticleType(string typeArg) {
|
void ParticleEmitter::SetParticleType(string typeArg) {
|
||||||
if(!_particleTexture) {
|
if(!_particleTexture) {
|
||||||
SDL_FreeSurface(_particleTexture);
|
SDL_FreeSurface(_particleTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
string textureFilename = "../Data/Media/Images/Particles/" + typeArg + ".png";
|
string textureFilename = "../../Data/Media/Images/Particles/" + typeArg + ".png";
|
||||||
_particleTexture = LoadImageAlpha(textureFilename.c_str());
|
_particleTexture = LoadImageAlpha(textureFilename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::SetParticleLifetime(int lifetimeArg) {
|
void ParticleEmitter::SetParticleLifetime(int lifetimeArg) {
|
||||||
_particleLifetime = lifetimeArg;
|
_particleLifetime = lifetimeArg;
|
||||||
|
|
||||||
for(int i = 0; i < _particleCount; i++) {
|
for(int i = 0; i < _particleCount; i++) {
|
||||||
m_particle[i].lifetime = rand() % _particleLifetime + _particleLifetime / 4;
|
m_particle[i].lifetime = rand() % _particleLifetime + _particleLifetime / 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::Render(void) {
|
void ParticleEmitter::Render(void) {
|
||||||
for(int i = 0; i < _particleCount; i++) {
|
for(int i = 0; i < _particleCount; i++) {
|
||||||
ApplySurface((int)m_particle[i].x, (int)m_particle[i].y, _particleTexture, screen);
|
ApplySurface((int)m_particle[i].x, (int)m_particle[i].y, _particleTexture, screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEmitter::Update(void) {
|
void ParticleEmitter::Update(void) {
|
||||||
for(int i = 0; i < _particleCount; i++) {
|
for(int i = 0; i < _particleCount; i++) {
|
||||||
if((int)SDL_GetTicks() - m_particle[i].startTime > m_particle[i].lifetime) {
|
if((int)SDL_GetTicks() - m_particle[i].startTime > m_particle[i].lifetime) {
|
||||||
// Reset the x and y coords.
|
// Reset the x and y coords.
|
||||||
m_particle[i].x = (float)x;
|
m_particle[i].x = (float)x;
|
||||||
m_particle[i].y = (float)y;
|
m_particle[i].y = (float)y;
|
||||||
|
|
||||||
m_particle[i].xVel = (float)(rand() % 360);
|
m_particle[i].xVel = (float)(rand() % 360);
|
||||||
m_particle[i].yVel = (float)(rand() % 360);
|
m_particle[i].yVel = (float)(rand() % 360);
|
||||||
|
|
||||||
if(rand() % 2)
|
if(rand() % 2)
|
||||||
m_particle[i].xVel = m_particle[i].xVel * -1.0f;
|
m_particle[i].xVel = m_particle[i].xVel * -1.0f;
|
||||||
if(rand() % 2)
|
if(rand() % 2)
|
||||||
m_particle[i].yVel = m_particle[i].yVel * -1.0f;
|
m_particle[i].yVel = m_particle[i].yVel * -1.0f;
|
||||||
|
|
||||||
m_particle[i].startTime = SDL_GetTicks();
|
m_particle[i].startTime = SDL_GetTicks();
|
||||||
} else {
|
} else {
|
||||||
m_particle[i].x += m_particle[i].xVel * _particleSpeed;
|
m_particle[i].x += m_particle[i].xVel * _particleSpeed;
|
||||||
m_particle[i].y += m_particle[i].yVel * _particleSpeed;
|
m_particle[i].y += m_particle[i].yVel * _particleSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
src/libUnuk/Engine/Spells.cpp
Normal file
17
src/libUnuk/Engine/Spells.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "Spells.h"
|
||||||
|
|
||||||
|
Spells::Spells(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Spells::~Spells(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Spells::CastSpell() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Spells::Render(void) {
|
||||||
|
//_particle->Render();
|
||||||
|
}
|
22
src/libUnuk/Engine/Spells.h
Normal file
22
src/libUnuk/Engine/Spells.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../Unuk/Player.h"
|
||||||
|
#include "../System/Timer.h"
|
||||||
|
#include "ParticleEmitter.h"
|
||||||
|
|
||||||
|
class Spells {
|
||||||
|
public:
|
||||||
|
Spells(void);
|
||||||
|
~Spells(void);
|
||||||
|
|
||||||
|
enum {
|
||||||
|
FIREBALL,
|
||||||
|
ICE
|
||||||
|
};
|
||||||
|
|
||||||
|
void CastSpell(/*Player* player*/);
|
||||||
|
void Render(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Timer* _timeBetweenCast;
|
||||||
|
ParticleEmitter* _particle;
|
||||||
|
};
|
@ -188,7 +188,7 @@ void WorldManager::OnPlayerAttack(Player* player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldManager::OnPlayerMove(Player* player) {
|
void WorldManager::OnPlayerMove(Player* player) {
|
||||||
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
|
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
|
||||||
(*i)->OnPlayerMove(player);
|
(*i)->OnPlayerMove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include "MemClass.h"
|
||||||
class Character;
|
class Character;
|
||||||
class NPC;
|
class NPC;
|
||||||
class Player;
|
class Player;
|
||||||
@ -10,26 +10,26 @@ class LevelGen;
|
|||||||
|
|
||||||
class WorldManager {
|
class WorldManager {
|
||||||
public:
|
public:
|
||||||
WorldManager(LevelGen* level);
|
WorldManager(LevelGen* level);
|
||||||
~WorldManager(void);
|
~WorldManager(void);
|
||||||
|
|
||||||
void Update(void);
|
void Update(void);
|
||||||
void Render(void);
|
void Render(void);
|
||||||
|
|
||||||
void AddNPC(NPC* npc);
|
void AddNPC(NPC* npc);
|
||||||
void RemoveNPC(int index);
|
void RemoveNPC(int index);
|
||||||
NPC* GetNPC(int index);
|
NPC* GetNPC(int index);
|
||||||
NPC* GetNPCAt(int xArg, int yArg);
|
NPC* GetNPCAt(int xArg, int yArg);
|
||||||
void CreateNPC(int x, int y);
|
void CreateNPC(int x, int y);
|
||||||
|
|
||||||
bool CheckCollision(const SDL_Rect& charRect, Character* exclude);
|
bool CheckCollision(const SDL_Rect& charRect, Character* exclude);
|
||||||
|
|
||||||
int GetNPCCount() { return _npcs.size(); }
|
int GetNPCCount() { return _npcs.size(); }
|
||||||
|
|
||||||
void OnPlayerAttack(Player* player);
|
void OnPlayerAttack(Player* player);
|
||||||
void OnPlayerMove(Player* player);
|
void OnPlayerMove(Player* player);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LevelGen* _level;
|
LevelGen* _level;
|
||||||
std::list<NPC*> _npcs;
|
std::list<NPC*> _npcs;
|
||||||
};
|
};
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "../LevelGen/AStarTile.h"
|
#include "../LevelGen/AStarTile.h"
|
||||||
#include "../System/Debug.h"
|
#include "../System/Debug.h"
|
||||||
#include "../Engine/WorldManager.h"
|
#include "../Engine/WorldManager.h"
|
||||||
|
#include "../Engine/MemClass.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Character;
|
class Character;
|
||||||
@ -53,7 +54,7 @@ public:
|
|||||||
|
|
||||||
WorldManager& GetWorld(void) { return _world; }
|
WorldManager& GetWorld(void) { return _world; }
|
||||||
|
|
||||||
void SetPlayer(Player* player) { _player = player; }
|
void SetPlayer(Player* player) { _player = player; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Unload(void);
|
void Unload(void);
|
||||||
|
66
src/libUnuk/LevelGen/MapTile.cpp
Normal file
66
src/libUnuk/LevelGen/MapTile.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "MapTile.h"
|
||||||
|
#include "LevelGen.h"
|
||||||
|
|
||||||
|
MapTile::MapTile(const MapTile& source) {
|
||||||
|
_level = source._level;
|
||||||
|
_tile = source._tile;
|
||||||
|
_entity = source._entity;
|
||||||
|
_zLevel = source._zLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapTile::IsSameState(MapTile& tile) {
|
||||||
|
return (tile.GetTileX() == _tile.GetX()) && (tile.GetTileY() == _tile.GetY());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapTile::IsGoal(MapTile& tile) {
|
||||||
|
return IsSameState(tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
float MapTile::GoalDistanceEstimate(MapTile& goal) {
|
||||||
|
Vec2 thisPos(_tile.GetX(), _tile.GetY());
|
||||||
|
Vec2 goalPos(goal.GetTileX(), goal.GetTileY());
|
||||||
|
return fabs(Vec2::DistanceSquared(thisPos, goalPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
float MapTile::GetCost(MapTile& goal) {
|
||||||
|
return 64.0f*64.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapTile::GetSuccessors(AStarSearch<MapTile>* search, MapTile* parent) {
|
||||||
|
int tileX = _tile.GetX() / TILE_WIDTH;
|
||||||
|
int tileY = _tile.GetY() / TILE_HEIGHT;
|
||||||
|
|
||||||
|
// Add tile to the left if possible.
|
||||||
|
if(tileX > 0) {
|
||||||
|
MapTile& successor = _level->GetTile(tileX - 1, tileY);
|
||||||
|
if(successor.GetTileSolidity() || successor.GetEntitySolitity()) {
|
||||||
|
search->AddSuccessor(successor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add tile to the right if possible
|
||||||
|
if(tileX < TILE_WIDTH) {
|
||||||
|
MapTile& successor = _level->GetTile(tileX + 1, tileY);
|
||||||
|
if(successor.GetTileSolidity() || successor.GetEntitySolitity()) {
|
||||||
|
search->AddSuccessor(successor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add tile to the bottom if possible
|
||||||
|
if(tileY > 0) {
|
||||||
|
MapTile& successor = _level->GetTile(tileX, tileY - 1);
|
||||||
|
if(successor.GetTileSolidity() || successor.GetEntitySolitity()) {
|
||||||
|
search->AddSuccessor(successor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add tile to the top if possible
|
||||||
|
if(tileY < TILE_HEIGHT) {
|
||||||
|
MapTile& successor = _level->GetTile(tileX, tileY + 1);
|
||||||
|
if(successor.GetTileSolidity() || successor.GetEntitySolitity()) {
|
||||||
|
search->AddSuccessor(successor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
@ -14,7 +14,7 @@ public:
|
|||||||
MapTile(void) { }
|
MapTile(void) { }
|
||||||
~MapTile(void) { }
|
~MapTile(void) { }
|
||||||
|
|
||||||
void Render(void) { _tile.Render(), _entity.Render(); }
|
void Render(void) { _tile.Render(), _entity.Render(); }
|
||||||
|
|
||||||
// Tile Mutators.
|
// Tile Mutators.
|
||||||
SDL_Surface* SetTileTexture(SDL_Surface* arg) { _tile.SetTexture(arg); return NULL; }
|
SDL_Surface* SetTileTexture(SDL_Surface* arg) { _tile.SetTexture(arg); return NULL; }
|
||||||
@ -29,29 +29,30 @@ public:
|
|||||||
int GetTileX(void) { return _tile.GetX(); }
|
int GetTileX(void) { return _tile.GetX(); }
|
||||||
int GetTileY(void) { return _tile.GetY(); }
|
int GetTileY(void) { return _tile.GetY(); }
|
||||||
|
|
||||||
// Entity Mutators.
|
|
||||||
void SetEntityTexture(SDL_Surface* arg) { _entity.SetTexture(arg); }
|
|
||||||
void SetEntityTextureName(string path) { _entity.SetTextureName(path); }
|
|
||||||
void SetEntityXY(int xArg, int yArg) { _entity.SetXY(xArg, yArg); }
|
|
||||||
void SetEntitySolidity(bool arg) { _entity.SetSolidity(arg); }
|
|
||||||
bool GetEntitySolitity(void) { return _entity.GetSolidity(); }
|
|
||||||
|
|
||||||
// Entity Mutators.
|
// Entity Mutators.
|
||||||
int GetEntityX(void) { return _entity.GetX(); }
|
void SetEntityTexture(SDL_Surface* arg) { _entity.SetTexture(arg); }
|
||||||
int GetEntityY(void) { return _entity.GetY(); }
|
void SetEntityTextureName(string path) { _entity.SetTextureName(path); }
|
||||||
int GetEntityWidth(void) { return _entity.GetWidth(); }
|
void SetEntityXY(int xArg, int yArg) { _entity.SetXY(xArg, yArg); }
|
||||||
int GetEntityHeight(void) { return _entity.GetHeight(); }
|
void SetEntitySolidity(bool arg) { _entity.SetSolidity(arg); }
|
||||||
string GetEntityTextureName(void) { return _entity.GetTextureName(); }
|
bool GetEntitySolitity(void) { return _entity.GetSolidity(); }
|
||||||
|
|
||||||
|
// Entity Mutators.
|
||||||
|
int GetEntityX(void) { return _entity.GetX(); }
|
||||||
|
int GetEntityY(void) { return _entity.GetY(); }
|
||||||
|
int GetEntityWidth(void) { return _entity.GetWidth(); }
|
||||||
|
int GetEntityHeight(void) { return _entity.GetHeight(); }
|
||||||
|
string GetEntityTextureName(void) { return _entity.GetTextureName(); }
|
||||||
|
|
||||||
// ZLevel Mutators.
|
// ZLevel Mutators.
|
||||||
void SetZLevel(int arg) { _zLevel = arg; }
|
void SetZLevel(int arg) { _zLevel = arg; }
|
||||||
int GetZLevel(void) { return _zLevel; }
|
int GetZLevel(void) { return _zLevel; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapElement _tile;
|
MapElement _tile;
|
||||||
MapEntityGeneric _entity;
|
MapEntityGeneric _entity;
|
||||||
|
|
||||||
// -1 is a 'special' tile, the next tile that the player walks
|
// -1 is a 'special' tile, the next tile that the player walks
|
||||||
// on is the players new zlevel.
|
// on is the players new zlevel.
|
||||||
int _zLevel;
|
int _zLevel;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user