public:
void Update(Time delta) {
for (typename std::list<TimerData<Time> >::iterator i(data.begin()), end(data.end()); i != end;) {
+ TimerData<Time> &t(*i);
if (i->target > 0) {
Time intervalTime(i->time);
while (intervalTime > i->target) intervalTime -= i->target;
void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
for (int i(0); i < numHeroes; ++i) {
- int row(heroes[i].Health() > 0 ? 0 : 2);
- heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset, 1, row);
+ if (HeroAnimationAt(i).Running()) {
+ HeroAnimationAt(i).DrawCenterBottom(screen, heroesPositions[i] + offset);
+ } else {
+ int row(heroes[i].Health() > 0 ? 0 : 2);
+ heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset, 1, row);
+ }
}
}
#include "../app/State.h"
#include "../geometry/Point.h"
#include "../geometry/Vector.h"
+#include "../graphics/Animation.h"
#include "../graphics/Menu.h"
#include <vector>
Monster &MonsterAt(int index) { return monsters[index]; }
const Monster &MonsterAt(int index) const { return monsters[index]; }
+ graphics::Animation &HeroAnimationAt(int index) { return heroAnimations[index]; }
+ const graphics::Animation &HeroAnimationAt(int index) const { return heroAnimations[index]; }
+
const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
std::vector<geometry::Point<int> > heroesPositions;
std::vector<Monster> monsters;
Hero heroes[4];
+ graphics::Animation heroAnimations[4];
graphics::Menu<const common::Spell *> spellMenus[4];
graphics::Menu<const common::Item *> itemMenu;
graphics::Menu<const common::Item *> ikariMenus[4];
bool HasJewel() const { return jewel; }
int AttackFrames() const { return attackFrames; }
+ int AttackFrameTime() const { return attackFrameTime; }
int SpellFrames() const { return spellFrames; }
+ int SpellFrameTime() const { return spellFrameTime; }
// temporary setters until loader is implemented
public:
void AddSpell(const common::Spell *s) { spells.push_back(s); }
- void SetAttackFrames(int num) { attackFrames = num; }
- void SetSpellFrames(int num) { spellFrames = num; }
+ void SetAttackFrames(int num, int time) { attackFrames = num; attackFrameTime = time; }
+ void SetSpellFrames(int num, int time) { spellFrames = num; spellFrameTime = time; }
private:
const char *name;
std::vector<const common::Spell *> spells;
int attackFrames;
+ int attackFrameTime;
int spellFrames;
+ int spellFrameTime;
Uint16 maxHealth, health;
Uint16 maxMana, mana;
#include "../../common/Spell.h"
#include "../../geometry/operators.h"
#include "../../geometry/Point.h"
+#include "../../graphics/Animation.h"
#include "../../graphics/Font.h"
#include "../../graphics/Frame.h"
using app::Input;
using geometry::Point;
using geometry::Vector;
+using graphics::Animation;
namespace battle {
ctrl->PopState();
}
} else {
+ if (cursor == 0) {
+ battle->HeroAnimationAt(battle->NumHeroes() - 1).Stop();
+ }
titleBarText = battle->MonsterAt(cursor).Name();
}
} else {
+ const AttackChoice &ac(battle->AttackChoiceAt(cursor));
if (titleBarText) {
titleBarText = 0;
+
+ switch (ac.GetType()) {
+ case AttackChoice::SWORD:
+ battle->HeroAnimationAt(cursor) = Animation(
+ battle->HeroAt(cursor).Sprite(),
+ battle->HeroAt(cursor).AttackFrameTime(),
+ battle->HeroAt(cursor).AttackFrames(), 2);
+ break;
+ case AttackChoice::MAGIC:
+ battle->HeroAnimationAt(cursor) = Animation(
+ battle->HeroAt(cursor).Sprite(),
+ battle->HeroAt(cursor).SpellFrameTime(),
+ battle->HeroAt(cursor).SpellFrames(), 3);
+ break;
+ case AttackChoice::DEFEND:
+ break;
+ case AttackChoice::IKARI:
+ if (ac.GetItem()->HasIkari()) {
+ if (ac.GetItem()->GetIkari()->IsMagical()) {
+ battle->HeroAnimationAt(cursor) = Animation(
+ battle->HeroAt(cursor).Sprite(),
+ battle->HeroAt(cursor).SpellFrameTime(),
+ battle->HeroAt(cursor).SpellFrames(), 3);
+ } else {
+ battle->HeroAnimationAt(cursor) = Animation(
+ battle->HeroAt(cursor).Sprite(),
+ battle->HeroAt(cursor).AttackFrameTime(),
+ battle->HeroAt(cursor).AttackFrames(), 2);
+ }
+ }
+ break;
+ case AttackChoice::ITEM:
+ break;
+ case AttackChoice::UNDECIDED:
+ break;
+ }
+ battle->HeroAnimationAt(cursor).Start(*this);
+
++cursor;
if (cursor == battle->NumHeroes()) {
cursor = 0;
monsters = true;
}
} else {
- const AttackChoice &ac(battle->AttackChoiceAt(cursor));
+ if (cursor > 0) {
+ battle->HeroAnimationAt(cursor - 1).Stop();
+ }
switch (ac.GetType()) {
case AttackChoice::SWORD:
titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
void Draw(SDL_Surface *dest, geometry::Point<int> position) {
sprite->Draw(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row);
}
+ void DrawCenterBottom(SDL_Surface *dest, geometry::Point<int> position) const {
+ sprite->DrawCenterBottom(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row);
+ }
private:
const Sprite *sprite;
maxim.SetMaxMana(20);
maxim.SetMana(20);
maxim.SetIP(0);
- maxim.SetAttackFrames(3);
- maxim.SetSpellFrames(2);
+ maxim.SetAttackFrames(3, 125);
+ maxim.SetSpellFrames(2, 125);
SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
Sprite selanSprite(selanImg, 64, 64);
selan.SetMaxMana(23);
selan.SetMana(23);
selan.SetIP(1);
- selan.SetAttackFrames(3);
- selan.SetSpellFrames(4);
+ selan.SetAttackFrames(3, 125);
+ selan.SetSpellFrames(4, 125);
SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
Sprite guySprite(guyImg, 64, 64);
guy.SetMaxMana(0);
guy.SetMana(0);
guy.SetIP(254);
- guy.SetAttackFrames(3);
- guy.SetSpellFrames(0);
+ guy.SetAttackFrames(3, 125);
+ guy.SetSpellFrames(0, 125);
SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
Sprite dekarSprite(dekarImg, 64, 64);
dekar.SetMaxMana(0);
dekar.SetMana(0);
dekar.SetIP(255);
- dekar.SetAttackFrames(3);
- dekar.SetSpellFrames(3);
+ dekar.SetAttackFrames(3, 125);
+ dekar.SetSpellFrames(3, 125);
battle::Resources battleRes;