[Add] NPCs now generating randomally.
[Add] Map is regenerated after all NPCs are killed. [Fix] Bugs regarding level up system. [Fix] Unuk-QT.pro.user is now ignored.
This commit is contained in:
parent
7d1a1b1295
commit
4808d8b45d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
UnukQT/Makefile
|
UnukQT/Makefile
|
||||||
|
UnukQT/Unuk-QT.pro.user
|
||||||
Win32/Unuk/Debug
|
Win32/Unuk/Debug
|
||||||
Win32/Unuk/Release
|
Win32/Unuk/Release
|
||||||
Win32/Unuk/LibUnuk/Debug
|
Win32/Unuk/LibUnuk/Debug
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by Qt Creator 2.4.1, 2012-02-02T01:31:32. -->
|
<!-- Written by Qt Creator 2.4.1, 2012-02-02T23:24:13. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
@ -23,9 +23,6 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
|||||||
|
|
||||||
LoadSavegame(savegameIDArg);
|
LoadSavegame(savegameIDArg);
|
||||||
|
|
||||||
// some weird bug. player->_exp is set to unreasonable number randomally after LoadSavegame returns.
|
|
||||||
_player->SetExpNeeded(Player::BASE_EXP_NEEDED);
|
|
||||||
|
|
||||||
int fps = 0;
|
int fps = 0;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
int nextGameTick = SDL_GetTicks();
|
int nextGameTick = SDL_GetTicks();
|
||||||
@ -115,10 +112,10 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
|||||||
_playerHealthBar.SetProgress((float)_player->GetHealth() / 100.0f);
|
_playerHealthBar.SetProgress((float)_player->GetHealth() / 100.0f);
|
||||||
|
|
||||||
playerExp.str("");
|
playerExp.str("");
|
||||||
playerExp << "Player Level " << _player->GetLevel() << " (" << _player->GetExp() << "/" << _player->GetExpNeeded() << ")";
|
playerExp << "Player Level " << _player->GetLevel() << " (" << _player->GetExp() << "/" << Player::EXP_TABLE[_player->GetLevel()] << ")";
|
||||||
_playerExp.SetTextBlended(playerExp.str(), vsmall, COLOUR_WHITE);
|
_playerExp.SetTextBlended(playerExp.str(), vsmall, COLOUR_WHITE);
|
||||||
|
|
||||||
_playerExpBar.SetProgress((float)_player->GetExp() / (float)_player->GetExpNeeded());
|
_playerExpBar.SetProgress((float)_player->GetExp() / (float)Player::EXP_TABLE[_player->GetLevel()]);
|
||||||
|
|
||||||
// Check to see if we are allowed to display debug info.
|
// Check to see if we are allowed to display debug info.
|
||||||
if(debugEnabled) {
|
if(debugEnabled) {
|
||||||
|
@ -5,13 +5,23 @@
|
|||||||
// Pixels * 60 / sec.
|
// Pixels * 60 / sec.
|
||||||
const float Player::PLAYER_SPEED = Character::CHARACTER_SPEED + 0.5f;
|
const float Player::PLAYER_SPEED = Character::CHARACTER_SPEED + 0.5f;
|
||||||
|
|
||||||
// Amount of Exp needed to level up from 1 to 2
|
// Amount of Exp needed every level
|
||||||
const int Player::BASE_EXP_NEEDED = 10;
|
const int Player::EXP_TABLE[10] = {
|
||||||
|
10,
|
||||||
|
30,
|
||||||
|
90,
|
||||||
|
150,
|
||||||
|
300,
|
||||||
|
512,
|
||||||
|
1000,
|
||||||
|
2000,
|
||||||
|
3500,
|
||||||
|
5000
|
||||||
|
};
|
||||||
|
|
||||||
Player::Player(LevelGen *mapArg) : Character(mapArg) {
|
Player::Player(LevelGen *mapArg) : Character(mapArg) {
|
||||||
_level = 1;
|
_level = 1;
|
||||||
_exp = 0;
|
_exp = 0;
|
||||||
_expNeeded = BASE_EXP_NEEDED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player(void) {
|
Player::~Player(void) {
|
||||||
@ -111,11 +121,10 @@ void Player::Move() {
|
|||||||
|
|
||||||
void Player::SetLevel(int level) {
|
void Player::SetLevel(int level) {
|
||||||
_level = level;
|
_level = level;
|
||||||
_exp = _exp - _expNeeded;
|
_exp = _exp - EXP_TABLE[level];
|
||||||
if(_exp < 0) {
|
if(_exp < 0) {
|
||||||
_exp = 0;
|
_exp = 0;
|
||||||
}
|
}
|
||||||
_expNeeded = pow(BASE_EXP_NEEDED, _level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SetExp(int exp) {
|
void Player::SetExp(int exp) {
|
||||||
@ -123,13 +132,9 @@ void Player::SetExp(int exp) {
|
|||||||
evtMsg << "Gained " << (exp - _exp) << " Experience Points.";
|
evtMsg << "Gained " << (exp - _exp) << " Experience Points.";
|
||||||
eventHistory->LogEvent(evtMsg.str());
|
eventHistory->LogEvent(evtMsg.str());
|
||||||
|
|
||||||
_exp += exp;
|
_exp = exp;
|
||||||
if(_exp >= _expNeeded) {
|
if(_level != MAX_LEVEL && _exp >= EXP_TABLE[_level]) {
|
||||||
eventHistory->LogEvent("Player leveled up!");
|
eventHistory->LogEvent("Player leveled up!");
|
||||||
SetLevel(_level + 1);
|
SetLevel(_level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SetExpNeeded(int expNeeded) {
|
|
||||||
_expNeeded = expNeeded;
|
|
||||||
}
|
|
||||||
|
@ -23,10 +23,8 @@ public:
|
|||||||
void SetExp(int exp);
|
void SetExp(int exp);
|
||||||
int GetExp(void) { return _exp; }
|
int GetExp(void) { return _exp; }
|
||||||
|
|
||||||
void SetExpNeeded(int expNeeded);
|
static const int MAX_LEVEL = 10;
|
||||||
int GetExpNeeded(void) { return _expNeeded; }
|
static const int EXP_TABLE[MAX_LEVEL];
|
||||||
|
|
||||||
static const int BASE_EXP_NEEDED;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Move(void);
|
void Move(void);
|
||||||
@ -37,8 +35,6 @@ private:
|
|||||||
static const float PLAYER_SPEED;
|
static const float PLAYER_SPEED;
|
||||||
|
|
||||||
string _name;
|
string _name;
|
||||||
//int _health;
|
|
||||||
int _level;
|
int _level;
|
||||||
int _exp;
|
int _exp;
|
||||||
int _expNeeded;
|
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
#include "../../Unuk/Globals.h"
|
#include "../../Unuk/Globals.h"
|
||||||
#include "../UI/EventHistory.h"
|
#include "../UI/EventHistory.h"
|
||||||
|
|
||||||
WorldManager::WorldManager(void) {
|
WorldManager::WorldManager(LevelGen* level) {
|
||||||
|
_level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldManager::~WorldManager(void) {
|
WorldManager::~WorldManager(void) {
|
||||||
@ -67,6 +68,13 @@ bool WorldManager::HasNPCIn(int xArg, int yArg) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldManager::OnPlayerAttack(Player* player) {
|
void WorldManager::OnPlayerAttack(Player* player) {
|
||||||
int playerX = (int)(player->GetX() / 32.0f);
|
int playerX = (int)(player->GetX() / 32.0f);
|
||||||
int playerY = (int)(player->GetY() / 32.0f);
|
int playerY = (int)(player->GetY() / 32.0f);
|
||||||
@ -105,7 +113,7 @@ void WorldManager::OnPlayerAttack(Player* player) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
npc->SetHealth(npc->GetHealth() - 5);
|
npc->SetHealth(npc->GetHealth() - 20);
|
||||||
npc->OnAttack();
|
npc->OnAttack();
|
||||||
|
|
||||||
if(npc->GetHealth() <= 0) {
|
if(npc->GetHealth() <= 0) {
|
||||||
@ -116,6 +124,10 @@ void WorldManager::OnPlayerAttack(Player* player) {
|
|||||||
|
|
||||||
i = _npcs.erase(i);
|
i = _npcs.erase(i);
|
||||||
delete npc;
|
delete npc;
|
||||||
|
|
||||||
|
if(_npcs.empty()) {
|
||||||
|
_level->Load("map");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
++i;
|
++i;
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
class NPC;
|
class NPC;
|
||||||
class Player;
|
class Player;
|
||||||
|
class LevelGen;
|
||||||
|
|
||||||
class WorldManager {
|
class WorldManager {
|
||||||
public:
|
public:
|
||||||
WorldManager(void);
|
WorldManager(LevelGen* level);
|
||||||
~WorldManager(void);
|
~WorldManager(void);
|
||||||
|
|
||||||
void Update(void);
|
void Update(void);
|
||||||
@ -15,6 +16,7 @@ public:
|
|||||||
void AddNPC(NPC* npc);
|
void AddNPC(NPC* npc);
|
||||||
void RemoveNPC(int index);
|
void RemoveNPC(int index);
|
||||||
NPC* GetNPC(int index);
|
NPC* GetNPC(int index);
|
||||||
|
void CreateNPC(int x, int y);
|
||||||
|
|
||||||
bool HasNPCIn(int xArg, int yArg);
|
bool HasNPCIn(int xArg, int yArg);
|
||||||
|
|
||||||
@ -23,5 +25,6 @@ public:
|
|||||||
void OnPlayerAttack(Player* player);
|
void OnPlayerAttack(Player* player);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
LevelGen* _level;
|
||||||
std::list<NPC*> _npcs;
|
std::list<NPC*> _npcs;
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "LevelGen.h"
|
#include "LevelGen.h"
|
||||||
#include "../Engine/NPC.h"
|
#include "../Engine/NPC.h"
|
||||||
|
|
||||||
LevelGen::LevelGen(void) {
|
LevelGen::LevelGen(void) : _world(this) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,42 +128,6 @@ void LevelGen::Load(const string filename) {
|
|||||||
|
|
||||||
// procedural generation
|
// procedural generation
|
||||||
DoMagic();
|
DoMagic();
|
||||||
|
|
||||||
//character->Load(filename);
|
|
||||||
|
|
||||||
NPC* npc = new NPC(this);
|
|
||||||
|
|
||||||
//int spawnX;
|
|
||||||
//int spawnY;
|
|
||||||
//FindSpawnPoint(spawnX, spawnY);
|
|
||||||
//npc->SetXY(spawnX, spawnY); // try to uncomment this, try to find out what's going on.. --konom
|
|
||||||
npc->SetXY(100, 230);
|
|
||||||
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
|
|
||||||
_world.AddNPC(npc);
|
|
||||||
|
|
||||||
npc = new NPC(this);
|
|
||||||
//FindSpawnPoint(spawnX, spawnY);
|
|
||||||
npc->SetXY(300, 250);
|
|
||||||
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
|
|
||||||
_world.AddNPC(npc);
|
|
||||||
|
|
||||||
npc = new NPC(this);
|
|
||||||
//FindSpawnPoint(spawnX, spawnY);
|
|
||||||
npc->SetXY(400, 100);
|
|
||||||
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
|
|
||||||
_world.AddNPC(npc);
|
|
||||||
|
|
||||||
npc = new NPC(this);
|
|
||||||
//FindSpawnPoint(spawnX, spawnY);
|
|
||||||
npc->SetXY(200, 400);
|
|
||||||
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
|
|
||||||
_world.AddNPC(npc);
|
|
||||||
|
|
||||||
npc = new NPC(this);
|
|
||||||
//FindSpawnPoint(spawnX, spawnY);
|
|
||||||
npc->SetXY(250, 250);
|
|
||||||
npc->LoadSprites("../Data/Media/Images/Characters/template.png", 40,45);
|
|
||||||
_world.AddNPC(npc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelGen::Update(void) {
|
void LevelGen::Update(void) {
|
||||||
@ -213,6 +177,7 @@ void LevelGen::Render(void) {
|
|||||||
void LevelGen::Unload(void) {
|
void LevelGen::Unload(void) {
|
||||||
_tileTextures.Unload();
|
_tileTextures.Unload();
|
||||||
_entityTextures.Unload();
|
_entityTextures.Unload();
|
||||||
|
memset(_tile, sizeof(_tile), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelGen::DoMagic(void) {
|
void LevelGen::DoMagic(void) {
|
||||||
@ -220,14 +185,15 @@ void LevelGen::DoMagic(void) {
|
|||||||
GenerateEntities("hedge", 15);
|
GenerateEntities("hedge", 15);
|
||||||
GenerateEntities("barrel", 40);
|
GenerateEntities("barrel", 40);
|
||||||
MakeWalkingPaths();
|
MakeWalkingPaths();
|
||||||
|
GenerateEnemies();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelGen::GenerateEntities(const string& name, int frequency) {
|
void LevelGen::GenerateEntities(const string& name, int frequency) {
|
||||||
int nextEntityGen = 1 + (rand() % frequency);
|
int nextEntityGen = 1 + (rand() % frequency);
|
||||||
std::string filename = "../Data/Media/Images/Entities/" + name + ".png";
|
std::string filename = "../Data/Media/Images/Entities/" + name + ".png";
|
||||||
|
|
||||||
for(int x = 0; x < SCREEN_WIDTH/64 + 1; x++) {
|
for(int x = 0; x < BOUNDARIES_X; x++) {
|
||||||
for(int y = 0; y < SCREEN_HEIGHT/64; y++) {
|
for(int y = 0; y < BOUNDARIES_Y; y++) {
|
||||||
nextEntityGen--;
|
nextEntityGen--;
|
||||||
if(!_tile[x][y].GetTileSolidity() && !_tile[x][y].GetEntitySolitity() && nextEntityGen <= 0) {
|
if(!_tile[x][y].GetTileSolidity() && !_tile[x][y].GetEntitySolitity() && nextEntityGen <= 0) {
|
||||||
_tile[x][y].SetEntityTexture(_entityTextures.AddAlpha(filename));
|
_tile[x][y].SetEntityTexture(_entityTextures.AddAlpha(filename));
|
||||||
@ -246,10 +212,10 @@ void LevelGen::GenerateEntities(const string& name, int frequency) {
|
|||||||
void LevelGen::MakeWalkingPaths(void) {
|
void LevelGen::MakeWalkingPaths(void) {
|
||||||
int lastOpenY = rand() % 5;
|
int lastOpenY = rand() % 5;
|
||||||
|
|
||||||
for(int x = 0; x < SCREEN_WIDTH/64 + 1; x++) {
|
for(int x = 0; x < BOUNDARIES_X; x++) {
|
||||||
bool pathFound = false;
|
bool pathFound = false;
|
||||||
|
|
||||||
for(int y = 0; y < SCREEN_HEIGHT/64; y++) {
|
for(int y = 0; y < BOUNDARIES_Y; y++) {
|
||||||
if(!_tile[x][y].GetEntitySolitity()) {
|
if(!_tile[x][y].GetEntitySolitity()) {
|
||||||
pathFound = true;
|
pathFound = true;
|
||||||
break;
|
break;
|
||||||
@ -266,19 +232,33 @@ void LevelGen::MakeWalkingPaths(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LevelGen::FindSpawnPoint(int& xArg, int& yArg) {
|
void LevelGen::FindSpawnPoint(int& xArg, int& yArg) {
|
||||||
xArg = rand() % SCREEN_WIDTH;
|
xArg = rand() % (BOUNDARIES_X * TILE_WIDTH);
|
||||||
yArg = rand() % SCREEN_HEIGHT;
|
yArg = rand() % (BOUNDARIES_Y * TILE_HEIGHT);
|
||||||
|
|
||||||
int tileX = xArg / 64;
|
int tileX = xArg / 64;
|
||||||
int tileY = yArg / 64;
|
int tileY = yArg / 64;
|
||||||
|
|
||||||
if(!_tile[tileX][tileY].GetEntitySolitity() && !_world.HasNPCIn(xArg, yArg)) {
|
if(!_tile[tileX][tileY].GetEntitySolitity() &&
|
||||||
|
!_tile[tileX][tileY].GetTileSolidity() &&
|
||||||
|
!_world.HasNPCIn(xArg, yArg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FindSpawnPoint(xArg, yArg);
|
FindSpawnPoint(xArg, yArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LevelGen::GenerateEnemies(void) {
|
||||||
|
int npcsToGen = 4 + (rand() % 4);
|
||||||
|
|
||||||
|
for(int i = 0; i < npcsToGen; i++) {
|
||||||
|
int spawnX;
|
||||||
|
int spawnY;
|
||||||
|
FindSpawnPoint(spawnX, spawnY);
|
||||||
|
|
||||||
|
_world.CreateNPC(spawnX, spawnY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string LevelGen::GetCurrentMap(void) {
|
string LevelGen::GetCurrentMap(void) {
|
||||||
return _currentMap;
|
return _currentMap;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ private:
|
|||||||
void DoMagic(void);
|
void DoMagic(void);
|
||||||
void GenerateEntities(const std::string& name, int frequency);
|
void GenerateEntities(const std::string& name, int frequency);
|
||||||
void MakeWalkingPaths(void);
|
void MakeWalkingPaths(void);
|
||||||
|
void GenerateEnemies(void);
|
||||||
|
|
||||||
string _currentMap;
|
string _currentMap;
|
||||||
int x;
|
int x;
|
||||||
@ -60,6 +61,9 @@ private:
|
|||||||
static const int TILE_ARRAY_SIZE = 150;
|
static const int TILE_ARRAY_SIZE = 150;
|
||||||
MapTile _tile[TILE_ARRAY_SIZE][TILE_ARRAY_SIZE];
|
MapTile _tile[TILE_ARRAY_SIZE][TILE_ARRAY_SIZE];
|
||||||
|
|
||||||
|
static const int BOUNDARIES_X = (SCREEN_WIDTH / TILE_WIDTH) - 2;
|
||||||
|
static const int BOUNDARIES_Y = (SCREEN_HEIGHT / TILE_HEIGHT) - 2;
|
||||||
|
|
||||||
TextureManager _tileTextures;
|
TextureManager _tileTextures;
|
||||||
TextureManager _entityTextures;
|
TextureManager _entityTextures;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user