]> git.localhorst.tv Git - l2e.git/commitdiff
added Maxim's melee animation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 14 Aug 2012 19:51:57 +0000 (21:51 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 14 Aug 2012 19:51:57 +0000 (21:51 +0200)
src/app/Application.cpp
src/battle/AttackAnimation.cpp
src/battle/AttackAnimation.h
src/battle/Hero.h
src/battle/states/PerformAttacks.cpp
src/battle/states/PerformAttacks.h
src/main.cpp
test-data/melee-maxim.png [new file with mode: 0644]

index c1e4f15311526ec5f767078d5faf30d5d9a72eb5..6e46203aa94184de00c55d90ff41025b7433d12d 100644 (file)
@@ -121,7 +121,7 @@ void Application::Loop() {
        Uint32 now(SDL_GetTicks());
        Uint32 deltaT(now - last);
        GlobalTimers().Update(deltaT);
-       if (deltaT > 34) deltaT = 34;
+       if (deltaT > 30) deltaT = 30;
 
        if (CurrentState()) {
                CurrentState()->GraphicsTimers().Update(deltaT);
index 0aedf18610aa2f8043c0f444d3b21c0c4093962f..07148db291dbed61d748d2f9826177bcf142780f 100644 (file)
@@ -160,6 +160,10 @@ bool AttackAnimation::ExecuteWaitAnimations() {
 }
 
 
+bool AttackAnimation::Running() const {
+       return cursor >= 0 && !Finished();
+}
+
 bool AttackAnimation::Finished() const {
        return cursor >= int(text.size());
 }
index 7758bb89594989f5828cb10ccdc2d8541742cf3e..48b1a5d65cfc590a3de0bdce16417c75162f0c02 100644 (file)
@@ -40,6 +40,7 @@ public:
 public:
        void Start(BattleState *, app::State *);
        void Update();
+       bool Running() const;
        bool Finished() const;
        void Render(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
 
index 97a21c23377d177d855db1bbdcda0194266bbf24..c0bd41a024d8f6db16b6accfcf3a345cbbe6b089 100644 (file)
@@ -22,6 +22,8 @@ namespace graphics {
 
 namespace battle {
 
+class AttackAnimation;
+
 class Hero {
 
 public:
@@ -69,6 +71,8 @@ public:
        bool HasRing() const { return ring; }
        bool HasJewel() const { return jewel; }
 
+       class AttackAnimation *MeleeAnimation() { return meleeAnimation; }
+       const class AttackAnimation *MeleeAnimation() const { return meleeAnimation; }
        graphics::Animation *AttackAnimation() { return attackAnimation; }
        const graphics::Animation *AttackAnimation() const { return attackAnimation; }
        graphics::Animation *SpellAnimation() { return spellAnimation; }
@@ -95,6 +99,7 @@ public:
 
        void AddSpell(const common::Spell *s) { spells.push_back(s); }
 
+       void SetMeleeAnimation(class AttackAnimation *a) { meleeAnimation = a; }
        void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; }
        void SetSpellAnimation(graphics::Animation *a) { spellAnimation = a; }
 
@@ -109,6 +114,7 @@ private:
        const common::Item *ring;
        const common::Item *jewel;
 
+       class AttackAnimation *meleeAnimation;
        graphics::Animation *attackAnimation;
        graphics::Animation *spellAnimation;
 
index dd0e0df1cd0a27de4102081e4b8a6e470e945f01..6c318aaf04138e86c627a94429dcdec23e260911 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "PerformAttacks.h"
 
+#include "../AttackAnimation.h"
 #include "../BattleState.h"
 #include "../Hero.h"
 #include "../Monster.h"
@@ -57,6 +58,7 @@ void PerformAttacks::Resize(int width, int height) {
 
 
 void PerformAttacks::HandleEvents(const Input &input) {
+       if (attackAnimation) attackAnimation->Update();
        CheckNumberAnimation();
        if (HasAnimationsRunning()) return;
        ResetAnimation();
@@ -77,8 +79,19 @@ void PerformAttacks::HandleEvents(const Input &input) {
 
                switch (ac.GetType()) {
                        case AttackChoice::SWORD:
-                               titleBarText = hero.HasWeapon() ? hero.Weapon()->Name() : "Melee attack!";
-                               moveAnimation = hero.AttackAnimation();
+                               if (hero.HasWeapon()) {
+                                       titleBarText = hero.Weapon()->Name();
+                                       moveAnimation = hero.AttackAnimation();
+                               } else {
+                                       titleBarText = "Melee attack!";
+                                       if (hero.MeleeAnimation()) {
+                                               moveAnimation = 0;
+                                               attackAnimation = hero.MeleeAnimation();
+                                       } else {
+                                               moveAnimation = hero.AttackAnimation();
+                                               attackAnimation = 0;
+                                       }
+                               }
                                numberAnimation.push_back(NumberAnimation(15, battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
                                if (ac.Selection().TargetsEnemies()) {
                                        numberPosition.push_back(
@@ -119,11 +132,15 @@ void PerformAttacks::HandleEvents(const Input &input) {
 
        if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(1500);
        if (moveAnimation) moveAnimation->Start(*this);
+       if (attackAnimation) attackAnimation->Start(battle, this);
 }
 
 void PerformAttacks::CheckNumberAnimation() {
        if (moveAnimation && moveAnimation->Running()) return;
-       if (!moveAnimation || moveAnimation->JustFinished()) {
+       if (attackAnimation && !attackAnimation->Finished()) return;
+       if (moveAnimation || attackAnimation) {
+               moveAnimation = 0;
+               attackAnimation = 0;
                for (vector<NumberAnimation>::iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) {
                        i->Start(*this);
                }
@@ -145,6 +162,7 @@ bool PerformAttacks::HasAnimationsRunning() const {
 
 void PerformAttacks::ResetAnimation() {
        if (moveAnimation) moveAnimation->Stop();
+       if (attackAnimation) attackAnimation = 0;
        titleBarTimer.Clear();
        numberAnimation.clear();
        numberPosition.clear();
@@ -175,6 +193,7 @@ void PerformAttacks::Render(SDL_Surface *screen) {
        battle->RenderSmallHeroTags(screen, offset);
        RenderTitleBar(screen, offset);
        RenderNumbers(screen, offset);
+       if (attackAnimation) attackAnimation->Render(screen, offset);
 }
 
 void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
index a5f3247b404a7fd2bf64fd0dd495453c18843d7d..a4d58dcc64f47ada4dd39f3a6bd0c53c67108cf0 100644 (file)
 
 namespace battle {
 
+class AttackAnimation;
+
 class PerformAttacks
 : public app::State {
 
 public:
        explicit PerformAttacks(BattleState *battle)
-       : ctrl(0), battle(battle), moveAnimation(0), titleBarText(0), cursor(-1) { }
+       : ctrl(0), battle(battle), moveAnimation(0), attackAnimation(0), titleBarText(0), cursor(-1) { }
 
 public:
        virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
@@ -53,6 +55,7 @@ private:
        app::Application *ctrl;
        BattleState *battle;
        graphics::Animation *moveAnimation;
+       AttackAnimation *attackAnimation;
        const char *titleBarText;
        app::Timer<Uint32> titleBarTimer;
        std::vector<BattleState::Order> order;
index 0fd129b98618401a1acc34f5f419ba448ba2d5cc..49a79b62e7b8d7bb34e166281fa5cac5cee9f8ad 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "app/Application.h"
 #include "app/Input.h"
+#include "battle/AttackAnimation.h"
 #include "battle/BattleState.h"
 #include "battle/Hero.h"
 #include "battle/Monster.h"
@@ -23,6 +24,7 @@
 #include "graphics/Frame.h"
 #include "graphics/Gauge.h"
 #include "graphics/Menu.h"
+#include "graphics/SimpleAnimation.h"
 #include "graphics/Sprite.h"
 #include "sdl/InitImage.h"
 #include "sdl/InitScreen.h"
@@ -35,6 +37,7 @@
 
 using app::Application;
 using app::Input;
+using battle::AttackAnimation;
 using battle::BattleState;
 using battle::Hero;
 using battle::Monster;
@@ -50,6 +53,7 @@ using graphics::Font;
 using graphics::Frame;
 using graphics::Gauge;
 using graphics::Menu;
+using graphics::SimpleAnimation;
 using graphics::Sprite;
 using sdl::InitImage;
 using sdl::InitScreen;
@@ -102,18 +106,29 @@ int main(int argc, char **argv) {
                maxim.SetMana(20);
                maxim.SetIP(0);
                ComplexAnimation maximAttackAnimation(&maximSprite, 30);
-               maximAttackAnimation.AddFrames(2, 0, Vector<int>(), 2);
-               maximAttackAnimation.AddFrames(2, 0, Vector<int>(4, 0), 2);
-               maximAttackAnimation.AddFrame(2, 1, Vector<int>(4, 0));
-               maximAttackAnimation.AddFrames(2, 1, Vector<int>(-2, 0), 2);
-               maximAttackAnimation.AddFrame(2, 1, Vector<int>(-8, 0));
-               maximAttackAnimation.AddFrames(2, 2, Vector<int>(-8, 0), 2);
-               maximAttackAnimation.AddFrame(2, 2, Vector<int>(-4, 0));
+               maximAttackAnimation.AddFrame(1, 0, Vector<int>(2, 0));
+               maximAttackAnimation.AddFrame(1, 0, Vector<int>(2, -1));
+               maximAttackAnimation.AddFrames(2, 0, Vector<int>(2, -2), 2);
+               maximAttackAnimation.AddFrame(2, 0, Vector<int>(4, -2));
+               maximAttackAnimation.AddFrame(2, 0, Vector<int>(3, -1));
+               maximAttackAnimation.AddFrames(2, 1, Vector<int>(3, -1), 2);
+               maximAttackAnimation.AddFrame(2, 1);
+               maximAttackAnimation.AddFrames(2, 2, Vector<int>(), 2);
                maxim.SetAttackAnimation(&maximAttackAnimation);
                ComplexAnimation maximSpellAnimation(&maximSprite, 150);
                maximSpellAnimation.AddFrames(3, 0, Vector<int>(), 2);
                maximSpellAnimation.AddFrame(3, 1);
                maxim.SetSpellAnimation(&maximSpellAnimation);
+               SDL_Surface *maximMeleeImg(IMG_Load("test-data/melee-maxim.png"));
+               Sprite maximMeleeSprite(maximMeleeImg, 96, 96);
+               SimpleAnimation maximMeleeAnimation(&maximMeleeSprite, 30, 4);
+               AttackAnimation maximMeleeScript;
+               maximMeleeScript.PlayAttackAnimation();
+               maximMeleeScript.StartTimer(150);
+               maximMeleeScript.WaitForTimer();
+               maximMeleeScript.PlayTargetAnimation(&maximMeleeAnimation);
+               maximMeleeScript.WaitForAnimations();
+               maxim.SetMeleeAnimation(&maximMeleeScript);
 
                SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
                Sprite selanSprite(selanImg, 64, 64);
@@ -442,7 +457,7 @@ int main(int argc, char **argv) {
                firestorm.GetTargetingMode().TargetAllEnemies();
                firestorm.SetPhysical();
                zircoSword.SetIkari(&firestorm);
-               maxim.SetWeapon(&zircoSword);
+//             maxim.SetWeapon(&zircoSword);
                Item zirconArmor;
                zirconArmor.SetName("Zircon armor");
                zirconArmor.SetMenuIcon(&armorIcon);
diff --git a/test-data/melee-maxim.png b/test-data/melee-maxim.png
new file mode 100644 (file)
index 0000000..3e296af
Binary files /dev/null and b/test-data/melee-maxim.png differ