From: Daniel Karbach Date: Tue, 18 Dec 2012 20:29:13 +0000 (+0100) Subject: implemented capsule/class selection X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=988ba6d1b4e18a4ae5d30a892224f76cee2355cc;p=l2e.git implemented capsule/class selection --- diff --git a/src/common/Capsule.cpp b/src/common/Capsule.cpp index 302af8f..0085147 100644 --- a/src/common/Capsule.cpp +++ b/src/common/Capsule.cpp @@ -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; diff --git a/src/common/Capsule.h b/src/common/Capsule.h index c70d07f..f168506 100644 --- a/src/common/Capsule.h +++ b/src/common/Capsule.h @@ -40,6 +40,8 @@ public: const graphics::Sprite *AlignmentSprite() const { return alignmentSprite; } void UpgradeClass(); + void NextClass(); + void PreviousClass(); Uint16 MaxHealth() const; diff --git a/src/common/GameState.h b/src/common/GameState.h index 4080630..55ae6df 100644 --- a/src/common/GameState.h +++ b/src/common/GameState.h @@ -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; diff --git a/src/main.cpp b/src/main.cpp index ca54210..96bfad7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 35c0c5c..b223f4f 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -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); diff --git a/src/menu/CapsuleChangeMenu.cpp b/src/menu/CapsuleChangeMenu.cpp index cac2056..912f81a 100644 --- a/src/menu/CapsuleChangeMenu.cpp +++ b/src/menu/CapsuleChangeMenu.cpp @@ -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 &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(); } diff --git a/src/menu/CapsuleChangeMenu.h b/src/menu/CapsuleChangeMenu.h index 0f8888f..a48a6b2 100644 --- a/src/menu/CapsuleChangeMenu.h +++ b/src/menu/CapsuleChangeMenu.h @@ -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: diff --git a/src/menu/CapsuleMenu.cpp b/src/menu/CapsuleMenu.cpp index 5a800a3..564b3bf 100644 --- a/src/menu/CapsuleMenu.cpp +++ b/src/menu/CapsuleMenu.cpp @@ -180,7 +180,7 @@ void CapsuleMenu::RenderInfo(SDL_Surface *screen, const Vector &offset) con void CapsuleMenu::RenderWheel(SDL_Surface *screen, const Vector &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 &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(); } } diff --git a/test-data/capsules.l2s b/test-data/capsules.l2s index 866e76f..a626958 100644 --- a/test-data/capsules.l2s +++ b/test-data/capsules.l2s @@ -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: diff --git a/test-data/flash.png b/test-data/flash.png index 85fd123..4aa2c4e 100644 Binary files a/test-data/flash.png and b/test-data/flash.png differ