[Change] Character::Move was named incorrectly, This is now defined as Character::HealthBarScroll
This commit is contained in:
parent
4be65645da
commit
35fd91c97a
@ -123,7 +123,7 @@ void Player::SetCamera(void) {
|
|||||||
|
|
||||||
void Player::Move() {
|
void Player::Move() {
|
||||||
map->MoveIfPossible(this, xVel, yVel, true);
|
map->MoveIfPossible(this, xVel, yVel, true);
|
||||||
Character::Move();
|
Character::HealthBarScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SetLevel(int level) {
|
void Player::SetLevel(int level) {
|
||||||
|
@ -7,108 +7,108 @@ static list<Character*>collisionList;
|
|||||||
static list<Character*>::iterator collisionIter;
|
static list<Character*>::iterator collisionIter;
|
||||||
|
|
||||||
Character::Character(LevelGen* mapArg) {
|
Character::Character(LevelGen* mapArg) {
|
||||||
map = mapArg;
|
map = mapArg;
|
||||||
attacking = false;
|
attacking = false;
|
||||||
directionFacing = FACING_DOWN;
|
directionFacing = FACING_DOWN;
|
||||||
_animationStage = ANIM_NO_FOOT;
|
_animationStage = ANIM_NO_FOOT;
|
||||||
_animationTimer.Start();
|
_animationTimer.Start();
|
||||||
_leftFoot = false;
|
_leftFoot = false;
|
||||||
_health = 100;
|
_health = 100;
|
||||||
|
|
||||||
xVel = 0.0f;
|
xVel = 0.0f;
|
||||||
yVel = 0.0f;
|
yVel = 0.0f;
|
||||||
|
|
||||||
_texture = NULL;
|
|
||||||
|
|
||||||
collisionList.push_front(this);
|
|
||||||
|
|
||||||
_healthBar.SetBackgroundRGB(0, 0, 0);
|
_texture = NULL;
|
||||||
_healthBar.SetForegroundRGB(255, 0, 0);
|
|
||||||
|
|
||||||
_showHealthBar = false;
|
collisionList.push_front(this);
|
||||||
|
|
||||||
|
_healthBar.SetBackgroundRGB(0, 0, 0);
|
||||||
|
_healthBar.SetForegroundRGB(255, 0, 0);
|
||||||
|
|
||||||
|
_showHealthBar = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Character::~Character(void) {
|
Character::~Character(void) {
|
||||||
SDL_FreeSurface(_texture);
|
SDL_FreeSurface(_texture);
|
||||||
for(collisionIter = collisionList.begin(); collisionIter != collisionList.end(); collisionIter++) {
|
for(collisionIter = collisionList.begin(); collisionIter != collisionList.end(); collisionIter++) {
|
||||||
if((*collisionIter) == this) {
|
if((*collisionIter) == this) {
|
||||||
collisionList.erase(collisionIter);
|
collisionList.erase(collisionIter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::LoadSprites(string filename, int wArg, int hArg) {
|
void Character::LoadSprites(string filename, int wArg, int hArg) {
|
||||||
if(_texture != NULL)
|
if(_texture != NULL)
|
||||||
SDL_FreeSurface(_texture);
|
SDL_FreeSurface(_texture);
|
||||||
|
|
||||||
_texture = LoadImageAlpha(filename.c_str());
|
_texture = LoadImageAlpha(filename.c_str());
|
||||||
|
|
||||||
w = (float)wArg;
|
w = (float)wArg;
|
||||||
h = (float)hArg;
|
h = (float)hArg;
|
||||||
|
|
||||||
for(int m_direction = 0; m_direction < 4; m_direction++) {
|
for(int m_direction = 0; m_direction < 4; m_direction++) {
|
||||||
for(int m_action = 0; m_action < 4; m_action++) {
|
for(int m_action = 0; m_action < 4; m_action++) {
|
||||||
_sprites[m_direction][m_action].x = (Sint16)(w * m_action);
|
_sprites[m_direction][m_action].x = (Sint16)(w * m_action);
|
||||||
_sprites[m_direction][m_action].y = (Sint16)(h * m_direction);
|
_sprites[m_direction][m_action].y = (Sint16)(h * m_direction);
|
||||||
_sprites[m_direction][m_action].w = (Sint16)w;
|
_sprites[m_direction][m_action].w = (Sint16)w;
|
||||||
_sprites[m_direction][m_action].h = (Sint16)h;
|
_sprites[m_direction][m_action].h = (Sint16)h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_healthBar.SetWidthHeight((int)w, 10);
|
_healthBar.SetWidthHeight((int)w, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::Render(void) {
|
void Character::Render(void) {
|
||||||
if(attacking && attackTimer.GetTicks() < ATTACKING_DISPLAY_LEN) {
|
if(attacking && attackTimer.GetTicks() < ATTACKING_DISPLAY_LEN) {
|
||||||
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][ANIM_ATTACK]);
|
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][ANIM_ATTACK]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(attacking)
|
else if(attacking)
|
||||||
attacking = false;
|
attacking = false;
|
||||||
|
|
||||||
if(xVel == 0.0f && yVel == 0.0f)
|
|
||||||
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][ANIM_NO_FOOT]);
|
|
||||||
else {
|
|
||||||
if(_animationTimer.GetTicks() > ANIMATION_SPEED) {
|
|
||||||
if(_animationStage == ANIM_NO_FOOT) {
|
|
||||||
if(_leftFoot == true)
|
|
||||||
_animationStage = ANIM_RIGHT_FOOT;
|
|
||||||
else
|
|
||||||
_animationStage = ANIM_LEFT_FOOT;
|
|
||||||
}
|
|
||||||
else if(_animationStage == ANIM_LEFT_FOOT) {
|
|
||||||
_animationStage = ANIM_NO_FOOT;
|
|
||||||
_leftFoot = true;
|
|
||||||
}
|
|
||||||
else if(_animationStage == ANIM_RIGHT_FOOT) {
|
|
||||||
_animationStage = ANIM_NO_FOOT;
|
|
||||||
_leftFoot = false;
|
|
||||||
}
|
|
||||||
_animationTimer.Start();
|
|
||||||
}
|
|
||||||
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][_animationStage]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_showHealthBar && (_healthBarDuration.GetTicks() >= 5000)) {
|
if(xVel == 0.0f && yVel == 0.0f)
|
||||||
_healthBarDuration.Stop();
|
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][ANIM_NO_FOOT]);
|
||||||
_showHealthBar = false;
|
else {
|
||||||
}
|
if(_animationTimer.GetTicks() > ANIMATION_SPEED) {
|
||||||
|
if(_animationStage == ANIM_NO_FOOT) {
|
||||||
|
if(_leftFoot == true)
|
||||||
|
_animationStage = ANIM_RIGHT_FOOT;
|
||||||
|
else
|
||||||
|
_animationStage = ANIM_LEFT_FOOT;
|
||||||
|
}
|
||||||
|
else if(_animationStage == ANIM_LEFT_FOOT) {
|
||||||
|
_animationStage = ANIM_NO_FOOT;
|
||||||
|
_leftFoot = true;
|
||||||
|
}
|
||||||
|
else if(_animationStage == ANIM_RIGHT_FOOT) {
|
||||||
|
_animationStage = ANIM_NO_FOOT;
|
||||||
|
_leftFoot = false;
|
||||||
|
}
|
||||||
|
_animationTimer.Start();
|
||||||
|
}
|
||||||
|
ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][_animationStage]);
|
||||||
|
}
|
||||||
|
|
||||||
if(_showHealthBar) {
|
if(_showHealthBar && (_healthBarDuration.GetTicks() >= 5000)) {
|
||||||
_healthBar.Draw();
|
_healthBarDuration.Stop();
|
||||||
}
|
_showHealthBar = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_showHealthBar) {
|
||||||
|
_healthBar.Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::Update(void) {
|
void Character::Update(void) {
|
||||||
_healthBar.SetProgress((float)_health / 100.0f);
|
_healthBar.SetProgress((float)_health / 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::OnAttack(void) {
|
void Character::OnAttack(void) {
|
||||||
_healthBarDuration.Start();
|
_healthBarDuration.Start();
|
||||||
_showHealthBar = true;
|
_showHealthBar = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::Move(void) {
|
void Character::HealthBarScroll(void) {
|
||||||
_healthBar.SetXY((int)x, (int)(y - _healthBar.GetHeight() - 5));
|
_healthBar.SetXY((int)x, (int)(y - _healthBar.GetHeight() - 5));
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Move(void);
|
void HealthBarScroll(void);
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include "NPC.h"
|
#include "NPC.h"
|
||||||
|
|
||||||
NPC::NPC(LevelGen* mapArg) : Character(mapArg) {
|
NPC::NPC(LevelGen* mapArg) : Character(mapArg) {
|
||||||
_moveTimer.Start();
|
_moveTimer.Start();
|
||||||
|
|
||||||
_moveChangeFrequency = 14000;
|
_moveChangeFrequency = 14000;
|
||||||
_moveDurationMax = 3000;
|
_moveDurationMax = 3000;
|
||||||
_moveDurationMin = 1000;
|
_moveDurationMin = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
NPC::~NPC(void) {
|
NPC::~NPC(void) {
|
||||||
@ -13,51 +13,51 @@ NPC::~NPC(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) {
|
||||||
if(_moving && _moveTimer.GetTicks() > _moveDurationMax) {
|
if(_moving && _moveTimer.GetTicks() > _moveDurationMax) {
|
||||||
xVel = 0.0f;
|
xVel = 0.0f;
|
||||||
yVel = 0.0f;
|
yVel = 0.0f;
|
||||||
_moving = false;
|
_moving = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_moving && _moveTimer.GetTicks() >= _moveDurationCurrent) {
|
if(_moving && _moveTimer.GetTicks() >= _moveDurationCurrent) {
|
||||||
xVel = 0.0f;
|
xVel = 0.0f;
|
||||||
yVel = 0.0f;
|
yVel = 0.0f;
|
||||||
_moving = false;
|
_moving = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_moveTimer.GetTicks() > _moveChangeFrequency) {
|
if(_moveTimer.GetTicks() > _moveChangeFrequency) {
|
||||||
_moveTimer.Start();
|
_moveTimer.Start();
|
||||||
_moveDurationCurrent = _moveDurationMin + (rand() % (_moveDurationMax - _moveDurationMin));
|
_moveDurationCurrent = _moveDurationMin + (rand() % (_moveDurationMax - _moveDurationMin));
|
||||||
if(rand() % 2) {
|
if(rand() % 2) {
|
||||||
yVel = 0.0f;
|
yVel = 0.0f;
|
||||||
if(rand() % 2)
|
if(rand() % 2)
|
||||||
xVel = CHARACTER_SPEED;
|
xVel = CHARACTER_SPEED;
|
||||||
else
|
else
|
||||||
xVel = -CHARACTER_SPEED;
|
xVel = -CHARACTER_SPEED;
|
||||||
} else {
|
} else {
|
||||||
xVel = 0.0f;
|
xVel = 0.0f;
|
||||||
if(rand() % 2)
|
if(rand() % 2)
|
||||||
yVel = CHARACTER_SPEED;
|
yVel = CHARACTER_SPEED;
|
||||||
else
|
else
|
||||||
yVel = -CHARACTER_SPEED;
|
yVel = -CHARACTER_SPEED;
|
||||||
}
|
}
|
||||||
_moving = true;
|
_moving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
map->MoveIfPossible(this, xVel, yVel, false);
|
map->MoveIfPossible(this, xVel, yVel, false);
|
||||||
Character::Move();
|
Character::HealthBarScroll();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user