[Fix] Sped up characters.
[Fix] Load game. [Fix] Enemy collisions. [Add] Enemies attacking the player. [Add] GAME OVER!!! :D
This commit is contained in:
parent
57e3229baf
commit
120be24f96
@ -219,6 +219,18 @@ void Game::UpdateGame(void) {
|
|||||||
if(_ingameMenu.GetStatus() == false) {
|
if(_ingameMenu.GetStatus() == false) {
|
||||||
_map.Update();
|
_map.Update();
|
||||||
_player->Update();
|
_player->Update();
|
||||||
|
|
||||||
|
if(gameOver) {
|
||||||
|
gameOver = false;
|
||||||
|
|
||||||
|
_map.New();
|
||||||
|
_player->SetHealth(100);
|
||||||
|
_player->SetLevelLiteral(1);
|
||||||
|
_player->SetExpLiteral(0);
|
||||||
|
|
||||||
|
New(_saveGameID);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// :D
|
// :D
|
||||||
}
|
}
|
||||||
|
@ -16,3 +16,5 @@ int plrKeyeft;
|
|||||||
int plrKeyRight;
|
int plrKeyRight;
|
||||||
|
|
||||||
int plrBtnSpell;
|
int plrBtnSpell;
|
||||||
|
|
||||||
|
bool gameOver = false;
|
||||||
|
@ -11,3 +11,5 @@ extern bool debugEnabled;
|
|||||||
class EventHistory;
|
class EventHistory;
|
||||||
|
|
||||||
extern EventHistory* eventHistory;
|
extern EventHistory* eventHistory;
|
||||||
|
|
||||||
|
extern bool gameOver;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "Character.h"
|
#include "Character.h"
|
||||||
|
|
||||||
// Pixels * 60 / sec
|
// Pixels * 60 / sec
|
||||||
const float Character::CHARACTER_SPEED = 1.0f;
|
const float Character::CHARACTER_SPEED = 2.0f;
|
||||||
|
|
||||||
Character::Character(LevelGen* mapArg) {
|
Character::Character(LevelGen* mapArg) {
|
||||||
map = mapArg;
|
map = mapArg;
|
||||||
|
@ -46,7 +46,6 @@ public:
|
|||||||
void OnAttack(void);
|
void OnAttack(void);
|
||||||
|
|
||||||
// Overload new and delete operators to utilize MemManager.
|
// Overload new and delete operators to utilize MemManager.
|
||||||
/*
|
|
||||||
inline void* operator new(size_t size) {
|
inline void* operator new(size_t size) {
|
||||||
return gMemManager.Allocate(size);
|
return gMemManager.Allocate(size);
|
||||||
}
|
}
|
||||||
@ -62,7 +61,6 @@ public:
|
|||||||
inline void operator delete [](void* object) {
|
inline void operator delete [](void* object) {
|
||||||
gMemManager.Free(object);
|
gMemManager.Free(object);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
FACING_UP,
|
FACING_UP,
|
||||||
|
@ -31,23 +31,11 @@ void NPC::Update(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NPC::Move(void) {
|
void NPC::Move(void) {
|
||||||
Character::HealthBarScroll();
|
|
||||||
|
|
||||||
xVel = 0.0f;
|
xVel = 0.0f;
|
||||||
yVel = 0.0f;
|
yVel = 0.0f;
|
||||||
|
|
||||||
if(!_walkInPath) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2 realPos(x, y);
|
|
||||||
|
|
||||||
Character* player = map->GetPlayer();
|
Character* player = map->GetPlayer();
|
||||||
|
|
||||||
if(fabs((player->GetX() - x)) > 256 || fabs((player->GetY() - y)) > 256) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect selfRect;
|
SDL_Rect selfRect;
|
||||||
selfRect.x = x - 5;
|
selfRect.x = x - 5;
|
||||||
selfRect.y = y - 5;
|
selfRect.y = y - 5;
|
||||||
@ -60,7 +48,36 @@ void NPC::Move(void) {
|
|||||||
playerRect.w = player->GetWidth() + 5;
|
playerRect.w = player->GetWidth() + 5;
|
||||||
playerRect.h = player->GetHeight() + 5;
|
playerRect.h = player->GetHeight() + 5;
|
||||||
|
|
||||||
if(CheckCollisionRect(selfRect, playerRect)) {
|
bool isNearPlayer = CheckCollisionRect(selfRect, playerRect);
|
||||||
|
|
||||||
|
if(isNearPlayer) {
|
||||||
|
if(!attackTimer.IsStarted()) {
|
||||||
|
attackTimer.Start();
|
||||||
|
} else {
|
||||||
|
if(attackTimer.GetTicks() >= ATTACK_FREQUENCY) {
|
||||||
|
attackTimer.Start();
|
||||||
|
AttackPlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(attackTimer.IsStarted()) {
|
||||||
|
attackTimer.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Character::HealthBarScroll();
|
||||||
|
|
||||||
|
if(!_walkInPath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 realPos(x, y);
|
||||||
|
|
||||||
|
if(fabs((player->GetX() - x)) > 256 || fabs((player->GetY() - y)) > 256) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isNearPlayer) {
|
||||||
_walkInPath = false;
|
_walkInPath = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,7 +104,9 @@ void NPC::Move(void) {
|
|||||||
if(xVel != 0.0f || yVel != 0.0f) {
|
if(xVel != 0.0f || yVel != 0.0f) {
|
||||||
map->MoveIfPossible(this, xVel, yVel, false);
|
map->MoveIfPossible(this, xVel, yVel, false);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
if(dx >= -CHARACTER_SPEED && dx <= CHARACTER_SPEED &&
|
||||||
|
dy >= -CHARACTER_SPEED && dy <= CHARACTER_SPEED) {
|
||||||
_target = _astar.GetSolutionNext();
|
_target = _astar.GetSolutionNext();
|
||||||
|
|
||||||
if(_target == NULL || _target == _lastTarget) {
|
if(_target == NULL || _target == _lastTarget) {
|
||||||
@ -136,3 +155,11 @@ void NPC::OnPlayerMove(Player* player) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NPC::AttackPlayer() {
|
||||||
|
map->GetPlayer()->SetHealth(map->GetPlayer()->GetHealth() - (rand() % 3));
|
||||||
|
map->GetPlayer()->OnAttack();
|
||||||
|
if(map->GetPlayer()->GetHealth() < 0) {
|
||||||
|
gameOver = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "Character.h"
|
#include "Character.h"
|
||||||
#include "Pathfinding.h"
|
#include "Pathfinding.h"
|
||||||
#include "../LevelGen/AStarTile.h"
|
#include "../LevelGen/AStarTile.h"
|
||||||
|
#include "../System/Timer.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Move(void);
|
void Move(void);
|
||||||
|
void AttackPlayer(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _moving;
|
bool _moving;
|
||||||
@ -26,4 +28,8 @@ private:
|
|||||||
bool _walkInPath;
|
bool _walkInPath;
|
||||||
AStarTile* _target;
|
AStarTile* _target;
|
||||||
AStarTile* _lastTarget;
|
AStarTile* _lastTarget;
|
||||||
|
|
||||||
|
Timer _attackTimer;
|
||||||
|
|
||||||
|
static const int ATTACK_FREQUENCY = 1000;
|
||||||
};
|
};
|
||||||
|
@ -86,9 +86,9 @@ bool WorldManager::CheckCollision(const SDL_Rect& charRect, Character* exclude)
|
|||||||
|
|
||||||
SDL_Rect npcRect;
|
SDL_Rect npcRect;
|
||||||
npcRect.x = npc->GetX();
|
npcRect.x = npc->GetX();
|
||||||
npcRect.y = npc->GetY() + (npc->GetHeight() / 4) * 3;
|
npcRect.y = npc->GetY()/* + (npc->GetHeight() / 4) * 3*/;
|
||||||
npcRect.w = npc->GetWidth();
|
npcRect.w = npc->GetWidth();
|
||||||
npcRect.h = npc->GetHeight() / 4;
|
npcRect.h = npc->GetHeight()/* / 4*/;
|
||||||
|
|
||||||
if(CheckCollisionRect(npcRect, charRect)) {
|
if(CheckCollisionRect(npcRect, charRect)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -150,10 +150,10 @@ void LevelGen::Save(const string& filename){
|
|||||||
|
|
||||||
TiXmlElement* rootElem = new TiXmlElement("map");
|
TiXmlElement* rootElem = new TiXmlElement("map");
|
||||||
|
|
||||||
for(y = 0; y < TILE_ARRAY_WIDTH; y++) {
|
for(y = 0; y < TILE_ARRAY_HEIGHT; y++) {
|
||||||
TiXmlElement* lineElem = new TiXmlElement("line");
|
TiXmlElement* lineElem = new TiXmlElement("line");
|
||||||
|
|
||||||
for(x = 0; x < TILE_ARRAY_HEIGHT; x++) {
|
for(x = 0; x < TILE_ARRAY_WIDTH; x++) {
|
||||||
TiXmlElement* tileElem = new TiXmlElement("tile");
|
TiXmlElement* tileElem = new TiXmlElement("tile");
|
||||||
|
|
||||||
TiXmlElement* tileTextureElem = new TiXmlElement("tileTexture");
|
TiXmlElement* tileTextureElem = new TiXmlElement("tileTexture");
|
||||||
@ -339,7 +339,7 @@ void LevelGen::FindSpawnPoint(int& xArg, int& yArg, int objWidth, int objHeight)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LevelGen::GenerateEnemies(void) {
|
void LevelGen::GenerateEnemies(void) {
|
||||||
int npcsToGen = 4 + (rand() % ((_player->GetLevel() * 2) + 4));
|
int npcsToGen = (_player->GetLevel() * 2) + (rand() % 4);
|
||||||
|
|
||||||
for(int i = 0; i < npcsToGen; i++) {
|
for(int i = 0; i < npcsToGen; i++) {
|
||||||
int spawnX;
|
int spawnX;
|
||||||
@ -394,11 +394,9 @@ void LevelGen::MoveIfPossible(Character* character, float xVel, float yVel, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(true) {
|
|
||||||
if(_world.CheckCollision(charRect, character)) {
|
if(_world.CheckCollision(charRect, character)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(!isPlayer) {
|
if(!isPlayer) {
|
||||||
SDL_Rect playerRect;
|
SDL_Rect playerRect;
|
||||||
@ -442,9 +440,9 @@ bool LevelGen::AStarTilePassable(int xArg, int yArg) {
|
|||||||
|
|
||||||
SDL_Rect playerRect;
|
SDL_Rect playerRect;
|
||||||
playerRect.x = _player->GetX();
|
playerRect.x = _player->GetX();
|
||||||
playerRect.y = _player->GetY() + (_player->GetHeight() / 4) * 3;
|
playerRect.y = _player->GetY()/* + (_player->GetHeight() / 4) * 3*/;
|
||||||
playerRect.w = _player->GetWidth();
|
playerRect.w = _player->GetWidth();
|
||||||
playerRect.h = _player->GetHeight() / 4;
|
playerRect.h = _player->GetHeight()/* / 4*/;
|
||||||
|
|
||||||
if(CheckCollisionRect(tileRect, playerRect)) {
|
if(CheckCollisionRect(tileRect, playerRect)) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user