++numHeroes;
}
+void BattleState::SetCapsule(const Capsule &c) {
+ capsule = c;
+}
+
void BattleState::NextHero() {
++activeHero;
while (activeHero < numHeroes && heroes[activeHero].Health() == 0) {
smallHeroTags[i] = SmallHeroTag(this, i);
}
+ capsule.Position() = heroesLayout->CalculatePosition(4, background->w, background->h);
+
for (int i(0); i < int(monsters.size()); ++i) {
monsters[i].Position() = monstersLayout->CalculatePosition(i, background->w, background->h);
}
}
}
+void BattleState::RenderCapsule(SDL_Surface *screen, const Vector<int> &offset) {
+ if (capsule.Health() <= 0) return;
+ if (capsule.GetAnimation().Running()) {
+ capsule.GetAnimation().DrawCenter(screen, capsule.Position() + offset);
+ } else {
+ capsule.Sprite()->DrawCenter(screen, capsule.Position() + offset);
+ }
+}
+
void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
assert(screen);
int tagHeight(attackTypeMenu.Height());
#include "fwd.h"
#include "AttackTypeMenu.h"
+#include "Capsule.h"
#include "Hero.h"
#include "HeroTag.h"
#include "Monster.h"
public:
void AddMonster(const Monster &);
void AddHero(const Hero &);
+ void SetCapsule(const Capsule &);
public:
virtual void HandleEvents(const app::Input &);
void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ void RenderCapsule(SDL_Surface *screen, const geometry::Vector<int> &offset);
void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
SmallHeroTag smallHeroTags[4];
geometry::Vector<int> heroTagPositions[4];
geometry::Vector<int> smallHeroTagPositions[4];
+ Capsule capsule;
int numHeroes;
int activeHero;
int attackCursor;
--- /dev/null
+#include "Capsule.h"
+
+namespace battle {
+
+Capsule::Capsule()
+: name(0)
+
+, maxHealth(0)
+, health(0)
+, maxMana(0)
+, mana(0)
+
+, level(0)
+
+, battleSprite(0)
+, meleeAnimation(0)
+, attackAnimation(0)
+, spellAnimation(0) {
+
+}
+
+
+void Capsule::SubtractHealth(int amount) {
+ if (amount > health) {
+ health = 0;
+ } else {
+ health -= amount;
+ }
+}
+
+}
--- /dev/null
+#ifndef BATTLE_CAPSULE_H_
+#define BATTLE_CAPSULE_H_
+
+#include "AttackChoice.h"
+#include "../common/fwd.h"
+#include "../common/Stats.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Animation.h"
+#include "../graphics/fwd.h"
+#include "../graphics/Menu.h"
+
+#include <vector>
+#include <SDL.h>
+
+namespace battle {
+
+class Capsule {
+
+public:
+ Capsule();
+
+public:
+ const char *Name() const { return name; }
+ Uint8 Level() const { return level; }
+ const graphics::Sprite *Sprite() const { return battleSprite; }
+
+ Uint16 MaxHealth() const { return maxHealth; }
+ Uint16 Health() const { return health; }
+ int RelativeHealth(int max) const { return Health() * max / MaxHealth(); }
+ void SubtractHealth(int amount);
+
+ Uint16 MaxMana() const { return maxMana; }
+ Uint16 Mana() const { return mana; }
+ int RelativeMana(int max) const { return MaxMana() == 0 ? 0 : Mana() * max / MaxMana(); }
+ bool CanUseMagic() const { return MaxMana() > 0; }
+
+ common::Stats &GetStats() { return stats; }
+ const common::Stats &GetStats() const { return stats; }
+
+ graphics::AnimationRunner &GetAnimation() { return animation; }
+ const graphics::AnimationRunner &GetAnimation() const { return animation; }
+ void SetAnimation(const graphics::AnimationRunner &a) { animation = a; }
+
+ const graphics::Animation *MeleeAnimation() const { return meleeAnimation; }
+ const graphics::Animation *AttackAnimation() const { return attackAnimation; }
+ const graphics::Animation *SpellAnimation() const { return spellAnimation; }
+
+ geometry::Vector<int> &Position() { return position; }
+ const geometry::Vector<int> &Position() const { return position; }
+
+ AttackChoice &GetAttackChoice() { return attackChoice; }
+ const AttackChoice &GetAttackChoice() const { return attackChoice; }
+
+// temporary setters
+public:
+ void SetName(const char *n) { name = n; }
+ void SetHealth(int max, int cur) { maxHealth = max; health = cur; }
+ void SetMana(int max, int cur) { maxMana = max; mana = cur; }
+ void SetLevel(int l) { level = l; }
+ void SetBattleSprite(graphics::Sprite *s) { battleSprite = s; }
+ void SetMeleeAnimation(graphics::Animation *a) { meleeAnimation = a; }
+ void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; }
+ void SetSpellAnimation(graphics::Animation *a) { spellAnimation = a; }
+
+private:
+ const char *name;
+
+ int maxHealth, health;
+ int maxMana, mana;
+
+ int level;
+
+ graphics::Sprite *battleSprite;
+ graphics::Animation *meleeAnimation;
+ graphics::Animation *attackAnimation;
+ graphics::Animation *spellAnimation;
+
+ graphics::AnimationRunner animation;
+ geometry::Vector<int> position;
+ AttackChoice attackChoice;
+ common::Stats stats;
+
+};
+
+}
+
+#endif /* BATTLE_CAPSULE_H_ */
class AttackChoice;
class AttackTypeMenu;
class BattleState;
+class Capsule;
class Hero;
class HeroTag;
class Monster;
#include "../BattleState.h"
#include "../Hero.h"
#include "../Monster.h"
+#include "../TargetSelection.h"
#include "../../app/Application.h"
#include "../../app/Input.h"
#include "../../common/Ikari.h"
battle->RenderBackground(screen, offset);
battle->RenderMonsters(screen, offset);
battle->RenderHeroes(screen, offset);
+ battle->RenderCapsule(screen, offset);
battle->RenderSmallHeroTags(screen, offset);
RenderTitleBar(screen, offset);
RenderNumbers(screen, offset);
#include "../../app/State.h"
-#include "../BattleState.h"
#include "../NumberAnimation.h"
#include "../../geometry/Vector.h"
#include "../../graphics/Animation.h"
namespace battle {
+class BattleState;
+class TargetSelection;
+
class PerformAttacks
: public app::State {
#include "app/Arguments.h"
#include "app/Input.h"
#include "battle/BattleState.h"
+#include "battle/Capsule.h"
#include "battle/Hero.h"
#include "battle/Monster.h"
#include "battle/PartyLayout.h"
using app::Arguments;
using app::Input;
using battle::BattleState;
+using battle::Capsule;
using battle::Monster;
using battle::PartyLayout;
using common::GameConfig;
app::State *state(0);
if (battle) {
+ graphics::Sprite flashSprite(IMG_Load("test-data/flash.png"), 96, 96);
+ Capsule capsule;
+ capsule.SetName("Flash");
+ capsule.SetHealth(13, 13);
+ capsule.SetBattleSprite(&flashSprite);
+
BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
battleState->AddMonster(monster);
battleState->AddMonster(monster);
battleState->AddMonster(monster);
battleState->AddMonster(monster);
+ battleState->SetCapsule(capsule);
battleState->AddHero(gameState.heroes[0]);
battleState->AddHero(gameState.heroes[1]);
battleState->AddHero(gameState.heroes[2]);
< 48,136>,
<128,136>,
< 80,152>,
- <160,152>
+ <160,152>,
+ <216,144>
]
}