]> git.localhorst.tv Git - l2e.git/commitdiff
animated victory messages
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 7 Feb 2013 06:55:08 +0000 (07:55 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 7 Feb 2013 06:55:08 +0000 (07:55 +0100)
src/battle/states/VictoryState.cpp
src/battle/states/VictoryState.h

index c1e5ea422c646826c12ca0aa34b46540230dc115..831f08eef002b268f50c6c831ce235fa926195cc 100644 (file)
@@ -100,20 +100,30 @@ void VictoryState::HandleEvents(const Input &input) {
                ++cursor;
                timer = GraphicsTimers().StartInterval(150);
        } else if (input.IsDown(Input::ACTION_A)
-                       && timer.JustHit()
-                       && timer.Iteration() > 3) {
-               ++cursor;
+                       && timer.JustHit()) {
+               if (timer.Iteration() > 3) {
+                       ++cursor;
+                       stalling = false;
+               } else {
+                       stalling = true;
+               }
        } else if (input.JustPressed(Input::SHOULDER_LEFT)) {
                ++cursor;
                timer = GraphicsTimers().StartInterval(150);
        } else if (input.IsDown(Input::SHOULDER_LEFT)
-                       && timer.JustHit()
-                       && timer.Iteration() > 3) {
-               ++cursor;
+                       && timer.JustHit()) {
+               if (timer.Iteration() > 3) {
+                       ++cursor;
+                       stalling = false;
+               } else {
+                       stalling = true;
+               }
        }
-       if (!input.IsDown(Input::ACTION_A)
+       if (timer.JustHit()
+                       && !input.IsDown(Input::ACTION_A)
                        && !input.IsDown(Input::SHOULDER_LEFT)) {
                timer.Clear();
+               stalling = false;
        }
        if (cursor >= int(lines.size())) {
                Ctrl().PopState(); // pop self
@@ -140,10 +150,31 @@ void VictoryState::RenderFrame(SDL_Surface *screen) {
 void VictoryState::RenderLines(SDL_Surface *screen) {
        // naive implementation
        const Font &font = *parent->Res().normalFont;
+       const Vector<int> lineBreak = Vector<int>(
+                       0, font.CharHeight() * 5 / 4);
+       const int start = cursor > 7 ? cursor - 8 : 0;
        Vector<int> position = textPosition;
-       for (int i = 0; i <= cursor && i < int(lines.size()); ++i) {
+
+       int end = cursor + 1;
+
+       if (start > 0) {
+               if (timer.Running() && !stalling) {
+                       position += lineBreak;
+                       const int correction = timer.IterationElapsed();
+                       if (correction > 0) {
+               //              ++start;
+                               position.Y() -= lineBreak.Y() * correction / timer.TargetTime();
+                       } else {
+                               --end;
+                       }
+               }
+       }
+
+       if (end > int(lines.size())) end = lines.size();
+
+       for (int i = start; i < end; ++i) {
                font.DrawString(lines[i].c_str(), screen, position);
-               position.Y() += font.CharHeight();
+               position += lineBreak;
        }
 }
 
index d14ec76e9a9c69467862558bb99aaf9f646d5c04..4dca6e9663373dbc1d275647aff813b04dd6ecbb 100644 (file)
@@ -23,7 +23,8 @@ public:
                        BattleState *parent)
        : battle(battle)
        , parent(parent)
-       , cursor(0) { }
+       , cursor(0)
+       , stalling(false) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -52,6 +53,7 @@ private:
        math::Vector<int> frameSize;
        math::Vector<int> textPosition;
        int cursor;
+       bool stalling;
 
 };