]> git.localhorst.tv Git - l2e.git/commitdiff
added capsule mockup (battle)
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 2 Dec 2012 16:49:17 +0000 (17:49 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 2 Dec 2012 16:49:17 +0000 (17:49 +0100)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Capsule.cpp [new file with mode: 0644]
src/battle/Capsule.h [new file with mode: 0644]
src/battle/fwd.h
src/battle/states/PerformAttacks.cpp
src/battle/states/PerformAttacks.h
src/main.cpp
test-data/flash.png [new file with mode: 0644]
test-data/test.l2s

index 36b4af53752714d58d1fc356230709b2aeaec988..9830e8c6a0b976f41f26642f024d34d2032e6e6e 100644 (file)
@@ -47,6 +47,10 @@ void BattleState::AddHero(const Hero &h) {
        ++numHeroes;
 }
 
+void BattleState::SetCapsule(const Capsule &c) {
+       capsule = c;
+}
+
 void BattleState::NextHero() {
        ++activeHero;
        while (activeHero < numHeroes && heroes[activeHero].Health() == 0) {
@@ -83,6 +87,8 @@ void BattleState::OnEnterState(SDL_Surface *screen) {
                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);
        }
@@ -394,6 +400,15 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
        }
 }
 
+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());
index 0f51f237cd2a47138ac222127f269a15f477aca8..3a9500c5d5228d41c2bd71ba42a27d593c41a4a3 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "fwd.h"
 #include "AttackTypeMenu.h"
+#include "Capsule.h"
 #include "Hero.h"
 #include "HeroTag.h"
 #include "Monster.h"
@@ -47,6 +48,7 @@ public:
 public:
        void AddMonster(const Monster &);
        void AddHero(const Hero &);
+       void SetCapsule(const Capsule &);
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -120,6 +122,7 @@ public:
        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);
 
@@ -154,6 +157,7 @@ private:
        SmallHeroTag smallHeroTags[4];
        geometry::Vector<int> heroTagPositions[4];
        geometry::Vector<int> smallHeroTagPositions[4];
+       Capsule capsule;
        int numHeroes;
        int activeHero;
        int attackCursor;
diff --git a/src/battle/Capsule.cpp b/src/battle/Capsule.cpp
new file mode 100644 (file)
index 0000000..709ef3b
--- /dev/null
@@ -0,0 +1,31 @@
+#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;
+       }
+}
+
+}
diff --git a/src/battle/Capsule.h b/src/battle/Capsule.h
new file mode 100644 (file)
index 0000000..c16196c
--- /dev/null
@@ -0,0 +1,87 @@
+#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_ */
index 73827d891a4d234188a8eae427b0ed31a47bdee2..959b85650e8aa833f8592fd6a17a082c9aff7d36 100644 (file)
@@ -6,6 +6,7 @@ namespace battle {
 class AttackChoice;
 class AttackTypeMenu;
 class BattleState;
+class Capsule;
 class Hero;
 class HeroTag;
 class Monster;
index 665756fcf38d8639cbe2fcbf8216ab540f0fca95..fac7cdf855aa42a4c8422f38e5ebd715afd52608 100644 (file)
@@ -10,6 +10,7 @@
 #include "../BattleState.h"
 #include "../Hero.h"
 #include "../Monster.h"
+#include "../TargetSelection.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
 #include "../../common/Ikari.h"
@@ -216,6 +217,7 @@ void PerformAttacks::Render(SDL_Surface *screen) {
        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);
index 06ce1b89cd93329719988b561b272fcf1c6982e9..b8623698f5734715b3818c0fe6d375fa9a1b437c 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "../../app/State.h"
 
-#include "../BattleState.h"
 #include "../NumberAnimation.h"
 #include "../../geometry/Vector.h"
 #include "../../graphics/Animation.h"
@@ -19,6 +18,9 @@
 
 namespace battle {
 
+class BattleState;
+class TargetSelection;
+
 class PerformAttacks
 : public app::State {
 
index 31724d5b22acd42f67b0222f8a954234c77981ad..59348338391daea0d5c6ea5fdb1578fdd4f32fe3 100644 (file)
@@ -2,6 +2,7 @@
 #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"
@@ -53,6 +54,7 @@ using app::Application;
 using app::Arguments;
 using app::Input;
 using battle::BattleState;
+using battle::Capsule;
 using battle::Monster;
 using battle::PartyLayout;
 using common::GameConfig;
@@ -282,11 +284,18 @@ int main(int argc, char **argv) {
                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]);
diff --git a/test-data/flash.png b/test-data/flash.png
new file mode 100644 (file)
index 0000000..298ff83
Binary files /dev/null and b/test-data/flash.png differ
index 8491b37316fa9867848ba3cae311a35fa826ff14..616249a26b677e07ee86566c8c6d8029814744cf 100644 (file)
@@ -20,7 +20,8 @@ export PartyLayout heroesLayout {
                < 48,136>,
                <128,136>,
                < 80,152>,
-               <160,152>
+               <160,152>,
+               <216,144>
        ]
 }