]> git.localhorst.tv Git - l2e.git/commitdiff
implemented capsule/class selection
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 18 Dec 2012 20:29:13 +0000 (21:29 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 18 Dec 2012 20:29:13 +0000 (21:29 +0100)
src/common/Capsule.cpp
src/common/Capsule.h
src/common/GameState.h
src/main.cpp
src/map/MapState.cpp
src/menu/CapsuleChangeMenu.cpp
src/menu/CapsuleChangeMenu.h
src/menu/CapsuleMenu.cpp
test-data/capsules.l2s
test-data/flash.png

index 302af8f774197d022f676570a045ca97bd32bbf9..008514776fb259d581e505d5b1223a10dcc9df30 100644 (file)
@@ -85,6 +85,20 @@ void Capsule::UpgradeClass() {
        ++curClass;
 }
 
+void Capsule::NextClass() {
+       ++curClass;
+       if (curClass >= maxClass) {
+               curClass = 0;
+       }
+}
+
+void Capsule::PreviousClass() {
+       --curClass;
+       if (curClass < 0) {
+               curClass = maxClass - 1;
+       }
+}
+
 
 Sprite *Capsule::BattleSprite() {
        return GetClass().battleSprite;
index c70d07fdf28cb41368160f3dfb314208dcf2e68a..f168506b21d59c5dfcd9870ff804b0832387c2e4 100644 (file)
@@ -40,6 +40,8 @@ public:
        const graphics::Sprite *AlignmentSprite() const { return alignmentSprite; }
 
        void UpgradeClass();
+       void NextClass();
+       void PreviousClass();
 
        Uint16 MaxHealth() const;
 
index 4080630a21e84e79681c7a029dc8c5fa2bda8c0e..55ae6dfb3374e5bfb75d7dec673aaa6e407ee382 100644 (file)
@@ -19,8 +19,10 @@ struct GameState {
        int partySize;
 
        Capsule capsules[7];
+       int capsule;
        int NumCapsules() const { return 7; }
-       Capsule *capsule;
+       Capsule &GetCapsule() { return capsules[capsule]; }
+       const Capsule &GetCapsule() const { return capsules[capsule]; }
 
        Inventory inventory;
 
index ca54210181f34e52b8a9e0c2f17060b985a8a5c9..96bfad7c7da9966d4d2a843728b6ba2bf3d89119 100644 (file)
@@ -198,7 +198,10 @@ int main(int argc, char **argv) {
 
                gameState.capsules[1] = *caster.GetCapsule("flash");
                gameState.capsules[1].UpgradeClass();
-               gameState.capsule = &gameState.capsules[1];
+               gameState.capsules[1].UpgradeClass();
+               gameState.capsules[1].UpgradeClass();
+               gameState.capsules[1].UpgradeClass();
+               gameState.capsule = 1;
 
                GameConfig gameConfig;
                gameConfig.state = &gameState;
index 35c0c5c76f9a09a53b38e68ac5f8228d524c8449..b223f4fd6a2d4a111bb0394a39ccd10d612fa561 100644 (file)
@@ -297,7 +297,7 @@ bool MapState::CheckMonster() {
                                        }
                                }
                                if (game->state->capsule) {
-                                       battleState->SetCapsule(game->state->capsule);
+                                       battleState->SetCapsule(&game->state->GetCapsule());
                                }
                                for (battle::Monster **monster((*e)->MonstersBegin()); monster != (*e)->MonstersEnd(); ++monster) {
                                        battleState->AddMonster(**monster);
index cac2056aecab713fe075f0c5fb3205010cb0b996..912f81aa513b6fde2e19d0bc2fc638256b3e0802 100644 (file)
@@ -54,8 +54,52 @@ void CapsuleChangeMenu::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_B)) {
                Ctrl().PopState();
        }
+
+       if (input.JustPressed(Input::PAD_UP)) {
+               NextClass();
+       }
+       if (input.JustPressed(Input::PAD_RIGHT)) {
+               NextCapsule();
+       }
+       if (input.JustPressed(Input::PAD_DOWN)) {
+               PreviousClass();
+       }
+       if (input.JustPressed(Input::PAD_LEFT)) {
+               PreviousCapsule();
+       }
 }
 
+void CapsuleChangeMenu::NextCapsule() {
+       int &index = parent->Game().state->capsule;
+       ++index;
+       index %= parent->Game().state->NumCapsules();
+       // skip unexplored
+       while (parent->Game().state->GetCapsule().MaxClass() <= 0) {
+               ++index;
+               index %= parent->Game().state->NumCapsules();
+       }
+}
+
+void CapsuleChangeMenu::PreviousCapsule() {
+       int &index = parent->Game().state->capsule;
+       --index;
+       if (index < 0) index += parent->Game().state->NumCapsules();
+       // skip unexplored
+       while (GetCapsule().MaxClass() <= 0) {
+               --index;
+               if (index < 0) index += parent->Game().state->NumCapsules();
+       }
+}
+
+void CapsuleChangeMenu::NextClass() {
+       GetCapsule().NextClass();
+}
+
+void CapsuleChangeMenu::PreviousClass() {
+       GetCapsule().PreviousClass();
+}
+
+
 void CapsuleChangeMenu::UpdateWorld(float deltaT) {
 
 }
@@ -116,7 +160,7 @@ void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector<int> &of
                        parent->Res().capsuleSelectLadder->Draw(
                                        screen, cursor,
                                        j < parent->Game().state->capsules[i].MaxClass(), j);
-                       if (&parent->Game().state->capsules[i] == parent->Game().state->capsule
+                       if (i == parent->Game().state->capsule
                                        && parent->Game().state->capsules[i].CurrentClass() == j) {
                                parent->Res().capsuleSelectCursor->Draw(screen, cursor);
                        }
@@ -149,6 +193,10 @@ int CapsuleChangeMenu::Height() const {
        return parent->Height();
 }
 
+Capsule &CapsuleChangeMenu::GetCapsule() {
+       return parent->GetCapsule();
+}
+
 const Capsule &CapsuleChangeMenu::GetCapsule() const {
        return parent->GetCapsule();
 }
index 0f8888f56f3fc2088f3e8062b933cddca6b8bde8..a48a6b2f0ffaa1a1367744c00d59f06445ab540d 100644 (file)
@@ -27,6 +27,11 @@ public:
        int Width() const;
        int Height() const;
 
+       void NextCapsule();
+       void PreviousCapsule();
+       void NextClass();
+       void PreviousClass();
+
 private:
        virtual void OnEnterState(SDL_Surface *screen);
        virtual void OnExitState(SDL_Surface *screen);
@@ -35,6 +40,7 @@ private:
 
        virtual void OnResize(int width, int height);
 
+       common::Capsule &GetCapsule();
        const common::Capsule &GetCapsule() const;
 
 private:
index 5a800a39294fd7d9a0ae699173c34a977e4a0de1..564b3bf5df928503418b20957b97d3d9020d7207 100644 (file)
@@ -180,7 +180,7 @@ void CapsuleMenu::RenderInfo(SDL_Surface *screen, const Vector<int> &offset) con
 
 void CapsuleMenu::RenderWheel(SDL_Surface *screen, const Vector<int> &offset) const {
        Res().capsuleAlignmentWheel->DrawCenter(screen, offset);
-       Res().capsuleAlignmentCursor->DrawCenter(screen, offset + Game().state->capsule->AlignmentOffset());
+       Res().capsuleAlignmentCursor->DrawCenter(screen, offset + Game().state->GetCapsule().AlignmentOffset());
 }
 
 void CapsuleMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
@@ -264,11 +264,11 @@ int CapsuleMenu::Height() const {
 }
 
 Capsule &CapsuleMenu::GetCapsule() {
-       return *Game().state->capsule;
+       return Game().state->GetCapsule();
 }
 
 const Capsule &CapsuleMenu::GetCapsule() const {
-       return *Game().state->capsule;
+       return Game().state->GetCapsule();
 }
 
 }
index 866e76f43828e4fd12990349a27a9bd53de6f4c6..a62695855dc68c9668e1f919f19b2cf4def095a6 100644 (file)
@@ -1,7 +1,27 @@
-Sprite flashSprite {
+Sprite flashSprite1 {
        image: :"flash.png",
        size: <96, 96>
 }
+Sprite flashSprite2 {
+       image: :"flash.png",
+       size: <96, 96>,
+       offset: <96, 0>
+}
+Sprite flashSprite3 {
+       image: :"flash.png",
+       size: <96, 96>,
+       offset: <192, 0>
+}
+Sprite flashSprite4 {
+       image: :"flash.png",
+       size: <96, 96>,
+       offset: <288, 0>
+}
+Sprite flashSpriteM {
+       image: :"flash.png",
+       size: <96, 96>,
+       offset: <384, 0>
+}
 
 export Capsule flash {
        name: "Flash",
@@ -26,7 +46,7 @@ export Capsule flash {
                {
                        name: "1 TODO",
                        tribe: "Shaggy",
-                       battleSprite: flashSprite,
+                       battleSprite: flashSprite1,
                        meleeAnimation: SimpleAnimation {
                                sprite: Sprite {
                                        image: :"melee-maxim.png",
@@ -36,7 +56,7 @@ export Capsule flash {
                                framecount: 4
                        },
                        attackAnimation: ComplexAnimation {
-                               sprite: flashSprite,
+                               sprite: flashSprite1,
                                frametime: fourFramesTime,
                                repeat: false,
                                frames:
@@ -51,7 +71,7 @@ export Capsule flash {
                {
                        name: "2 TODO",
                        tribe: "Sprite",
-                       battleSprite: flashSprite,
+                       battleSprite: flashSprite2,
                        meleeAnimation: SimpleAnimation {
                                sprite: Sprite {
                                        image: :"melee-maxim.png",
@@ -61,7 +81,7 @@ export Capsule flash {
                                framecount: 4
                        },
                        attackAnimation: ComplexAnimation {
-                               sprite: flashSprite,
+                               sprite: flashSprite2,
                                frametime: fourFramesTime,
                                repeat: false,
                                frames:
@@ -86,7 +106,7 @@ export Capsule flash {
                {
                        name: "3 TODO",
                        tribe: "Cupid",
-                       battleSprite: flashSprite,
+                       battleSprite: flashSprite3,
                        meleeAnimation: SimpleAnimation {
                                sprite: Sprite {
                                        image: :"melee-maxim.png",
@@ -96,7 +116,7 @@ export Capsule flash {
                                framecount: 4
                        },
                        attackAnimation: ComplexAnimation {
-                               sprite: flashSprite,
+                               sprite: flashSprite3,
                                frametime: fourFramesTime,
                                repeat: false,
                                frames:
@@ -121,7 +141,7 @@ export Capsule flash {
                {
                        name: "4",
                        tribe: "Twinkle",
-                       battleSprite: flashSprite,
+                       battleSprite: flashSprite4,
                        meleeAnimation: SimpleAnimation {
                                sprite: Sprite {
                                        image: :"melee-maxim.png",
@@ -131,7 +151,7 @@ export Capsule flash {
                                framecount: 4
                        },
                        attackAnimation: ComplexAnimation {
-                               sprite: flashSprite,
+                               sprite: flashSprite4,
                                frametime: fourFramesTime,
                                repeat: false,
                                frames:
@@ -156,7 +176,7 @@ export Capsule flash {
                {
                        name: "M TODO",
                        tribe: "Twinkle",
-                       battleSprite: flashSprite,
+                       battleSprite: flashSpriteM,
                        meleeAnimation: SimpleAnimation {
                                sprite: Sprite {
                                        image: :"melee-maxim.png",
@@ -166,7 +186,7 @@ export Capsule flash {
                                framecount: 4
                        },
                        attackAnimation: ComplexAnimation {
-                               sprite: flashSprite,
+                               sprite: flashSpriteM,
                                frametime: fourFramesTime,
                                repeat: false,
                                frames:
index 85fd123eb0b6dc04365fbeb63d569be2f3869385..4aa2c4e0d64e9a1984a94b974a5a36d246e396f8 100644 (file)
Binary files a/test-data/flash.png and b/test-data/flash.png differ