From: Daniel Karbach Date: Tue, 7 Aug 2012 10:23:10 +0000 (+0200) Subject: added battle move menu X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=628b3a7276d0b330719e05504b23bafcf88f8fca;p=l2e.git added battle move menu --- diff --git a/Debug/src/battle/subdir.mk b/Debug/src/battle/subdir.mk index 0ef38a1..d967ca2 100644 --- a/Debug/src/battle/subdir.mk +++ b/Debug/src/battle/subdir.mk @@ -9,6 +9,7 @@ CPP_SRCS += \ ../src/battle/Hero.cpp \ ../src/battle/HeroTag.cpp \ ../src/battle/Monster.cpp \ +../src/battle/MoveMenu.cpp \ ../src/battle/PartyLayout.cpp OBJS += \ @@ -17,6 +18,7 @@ OBJS += \ ./src/battle/Hero.o \ ./src/battle/HeroTag.o \ ./src/battle/Monster.o \ +./src/battle/MoveMenu.o \ ./src/battle/PartyLayout.o CPP_DEPS += \ @@ -25,6 +27,7 @@ CPP_DEPS += \ ./src/battle/Hero.d \ ./src/battle/HeroTag.d \ ./src/battle/Monster.d \ +./src/battle/MoveMenu.d \ ./src/battle/PartyLayout.d diff --git a/Release/src/battle/subdir.mk b/Release/src/battle/subdir.mk index e59a859..2ae5c59 100644 --- a/Release/src/battle/subdir.mk +++ b/Release/src/battle/subdir.mk @@ -9,6 +9,7 @@ CPP_SRCS += \ ../src/battle/Hero.cpp \ ../src/battle/HeroTag.cpp \ ../src/battle/Monster.cpp \ +../src/battle/MoveMenu.cpp \ ../src/battle/PartyLayout.cpp OBJS += \ @@ -17,6 +18,7 @@ OBJS += \ ./src/battle/Hero.o \ ./src/battle/HeroTag.o \ ./src/battle/Monster.o \ +./src/battle/MoveMenu.o \ ./src/battle/PartyLayout.o CPP_DEPS += \ @@ -25,6 +27,7 @@ CPP_DEPS += \ ./src/battle/Hero.d \ ./src/battle/HeroTag.d \ ./src/battle/Monster.d \ +./src/battle/MoveMenu.d \ ./src/battle/PartyLayout.d diff --git a/src/battle/AttackTypeMenu.cpp b/src/battle/AttackTypeMenu.cpp index b881d8b..bee794f 100644 --- a/src/battle/AttackTypeMenu.cpp +++ b/src/battle/AttackTypeMenu.cpp @@ -7,31 +7,15 @@ #include "AttackTypeMenu.h" -#include "../app/Input.h" #include "../geometry/operators.h" #include "../geometry/Vector.h" #include "../graphics/Sprite.h" -using app::Input; using geometry::Point; using geometry::Vector; namespace battle { -void AttackTypeMenu::ReadInput(const Input &input) { - if (input.IsDown(Input::PAD_UP)) { - selected = MAGIC; - } else if (input.IsDown(Input::PAD_RIGHT)) { - selected = DEFEND; - } else if (input.IsDown(Input::PAD_DOWN)) { - selected = IKARI; - } else if (input.IsDown(Input::PAD_LEFT)) { - selected = ITEM; - } else { - selected = SWORD; - } -} - void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Point &position) { Vector swordOffset(IconWidth(), IconHeight()); Vector magicOffset(IconWidth(), 0); diff --git a/src/battle/AttackTypeMenu.h b/src/battle/AttackTypeMenu.h index 08caf7f..26a9dd9 100644 --- a/src/battle/AttackTypeMenu.h +++ b/src/battle/AttackTypeMenu.h @@ -8,8 +8,6 @@ #ifndef BATTLE_ATTACKTYPEMENU_H_ #define BATTLE_ATTACKTYPEMENU_H_ -namespace app { class Input; } - #include "../geometry/Point.h" #include "../graphics/Sprite.h" @@ -33,7 +31,7 @@ public: : icons(icons), selected(SWORD) { } public: - void ReadInput(const app::Input &); + void Select(Icon i) { selected = i; } Icon Selected() const { return selected; } void Render(SDL_Surface *screen, const geometry::Point &position); diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 758d9d8..a2c306a 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -58,7 +58,35 @@ void BattleState::ExitState() { void BattleState::HandleInput(const Input &input) { - attackTypeMenu.ReadInput(input); + if (moveChoice == -1) { + if (input.IsDown(Input::PAD_UP)) { + moveMenu.Select(MoveMenu::CHANGE); + } else if (input.IsDown(Input::PAD_DOWN)) { + moveMenu.Select(MoveMenu::RUN); + } else { + moveMenu.Select(MoveMenu::ATTACK); + } + + if (input.JustPressed(Input::ACTION_A)) { + moveChoice = moveMenu.Selected(); + } + } else { + if (input.IsDown(Input::PAD_UP)) { + attackTypeMenu.Select(AttackTypeMenu::MAGIC); + } else if (input.IsDown(Input::PAD_RIGHT)) { + attackTypeMenu.Select(AttackTypeMenu::DEFEND); + } else if (input.IsDown(Input::PAD_DOWN)) { + attackTypeMenu.Select(AttackTypeMenu::IKARI); + } else if (input.IsDown(Input::PAD_LEFT)) { + attackTypeMenu.Select(AttackTypeMenu::ITEM); + } else { + attackTypeMenu.Select(AttackTypeMenu::SWORD); + } + + if (input.JustPressed(Input::ACTION_A)) { + activeHero = (activeHero + 1) % 4; + } + } } void BattleState::UpdateWorld(float deltaT) { @@ -74,7 +102,11 @@ void BattleState::Render(SDL_Surface *screen) { RenderMonsters(screen, offset); // RenderHeroes(screen, offset); RenderHeroTags(screen, offset); - RenderAttackTypeMenu(screen, offset); + if (moveChoice == -1) { + RenderMoveMenu(screen, offset); + } else { + RenderAttackTypeMenu(screen, offset); + } } void BattleState::RenderBackground(SDL_Surface *screen, const Vector &offset) { @@ -112,7 +144,7 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector &offset) tagPosition[3] = Point(tagWidth + attackTypeMenu.IconWidth(), uiOffset + tagHeight + attackTypeMenu.IconHeight()); for (vector::size_type i(0), end(heroTags.size()); i < end; ++i) { - heroTags[i].Render(screen, tagWidth, tagHeight, tagPosition[i] + offset); + heroTags[i].Render(screen, tagWidth, tagHeight, tagPosition[i] + offset, i == activeHero); } } @@ -123,4 +155,11 @@ void BattleState::RenderAttackTypeMenu(SDL_Surface *screen, const Vector &o attackTypeMenu.Render(screen, position + offset); } +void BattleState::RenderMoveMenu(SDL_Surface *screen, const Vector &offset) { + Point position( + (background->w - moveMenu.Width()) / 2, + (background->h * 3 / 4) - (moveMenu.Height() / 2)); + moveMenu.Render(screen, position + offset); +} + } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 8fa7d95..daf1cae 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -12,6 +12,7 @@ #include "Hero.h" #include "HeroTag.h" #include "Monster.h" +#include "MoveMenu.h" #include "../app/State.h" #include "../geometry/Point.h" #include "../geometry/Vector.h" @@ -31,11 +32,14 @@ class BattleState : public app::State { public: - BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons) + BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons, const graphics::Sprite *moveIcons) : background(background) , monstersLayout(&monstersLayout) , heroesLayout(&heroesLayout) - , attackTypeMenu(attackIcons) { } + , attackTypeMenu(attackIcons) + , moveMenu(moveIcons) + , moveChoice(-1) + , activeHero(0) { } public: void AddMonster(const Monster &); @@ -57,17 +61,21 @@ private: void RenderHeroes(SDL_Surface *screen, const geometry::Vector &offset); void RenderHeroTags(SDL_Surface *screen, const geometry::Vector &offset); void RenderAttackTypeMenu(SDL_Surface *screen, const geometry::Vector &offset); + void RenderMoveMenu(SDL_Surface *screen, const geometry::Vector &offset); private: SDL_Surface *background; const PartyLayout *monstersLayout; const PartyLayout *heroesLayout; AttackTypeMenu attackTypeMenu; + MoveMenu moveMenu; std::vector > monsterPositions; std::vector > heroesPositions; std::vector monsters; std::vector heroes; std::vector heroTags; + int moveChoice; + int activeHero; }; diff --git a/src/battle/Hero.h b/src/battle/Hero.h index ec87f49..59512b6 100644 --- a/src/battle/Hero.h +++ b/src/battle/Hero.h @@ -27,11 +27,14 @@ public: Uint16 MaxHealth() const { return maxHealth; } Uint16 Health() const { return health; } - int RelativeHealth(int max) { return health * max / maxHealth; } + int RelativeHealth(int max) const { return health * max / maxHealth; } Uint16 MaxMana() const { return maxMana; } Uint16 Mana() const { return mana; } - int RelativeMana(int max) { return mana * max / maxMana; } + int RelativeMana(int max) const { return mana * max / maxMana; } + + Uint8 IP() const { return ip; } + int RelativeIP(int max) const { return ip * max / 256; } Uint16 Attack() const { return attack; } Uint16 Defense() const { return defense; } @@ -42,8 +45,16 @@ public: // temporary setters until loader is implemented public: + void SetName(const char *n) { name = n; } + void SetLevel(Uint8 l) { level = l; } void SetSprite(graphics::Sprite *s) { sprite = s; } + void SetMaxHealth(Uint16 h) { maxHealth = h; } + void SetHealth(Uint16 h) { health = h; } + void SetMaxMana(Uint16 m) { maxMana = m; } + void SetMana(Uint16 m) { mana = m; } + void SetIP(Uint8 i) { ip = i; } + private: const char *name; graphics::Sprite *sprite; @@ -60,6 +71,7 @@ private: Uint16 magicResistance; Uint8 level; + Uint8 ip; }; diff --git a/src/battle/HeroTag.cpp b/src/battle/HeroTag.cpp index 2461e4d..d67368f 100644 --- a/src/battle/HeroTag.cpp +++ b/src/battle/HeroTag.cpp @@ -7,11 +7,17 @@ #include "HeroTag.h" +#include "Hero.h" +#include "../geometry/operators.h" +#include "../geometry/Vector.h" +#include "../graphics/Sprite.h" + using geometry::Point; +using geometry::Vector; namespace battle { -void HeroTag::Render(SDL_Surface *screen, int width, int height, Point position) const { +void HeroTag::Render(SDL_Surface *screen, int width, int height, Point position, bool active) const { SDL_Rect destRect; destRect.x = position.X(); destRect.y = position.Y(); @@ -22,13 +28,18 @@ void HeroTag::Render(SDL_Surface *screen, int width, int height, Point posi destRect.y += 1; destRect.w -= 2; destRect.h -= 2; - SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF)); + SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0xFF, active ? 0 : 0xFF, active ? 0 : 0xFF)); destRect.x += 1; destRect.y += 1; destRect.w -= 2; destRect.h -= 2; SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0, 0, 0)); + + Vector heroOffset( + (align == LEFT) ? 3 : width - hero->Sprite()->Width() - 3, + height - hero->Sprite()->Height() - 3); + hero->Sprite()->Draw(screen, position + heroOffset); } } diff --git a/src/battle/HeroTag.h b/src/battle/HeroTag.h index e0d3a5a..c606348 100644 --- a/src/battle/HeroTag.h +++ b/src/battle/HeroTag.h @@ -29,7 +29,7 @@ public: ~HeroTag() { } public: - void Render(SDL_Surface *screen, int width, int height, geometry::Point position) const; + void Render(SDL_Surface *screen, int width, int height, geometry::Point position, bool active) const; private: const Hero *hero; diff --git a/src/battle/Monster.h b/src/battle/Monster.h index e77a14b..1c92184 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -27,11 +27,11 @@ public: Uint16 MaxHealth() const { return maxHealth; } Uint16 Health() const { return health; } - int RelativeHealth(int max) { return health * max / maxHealth; } + int RelativeHealth(int max) const { return health * max / maxHealth; } Uint16 MaxMana() const { return maxMana; } Uint16 Mana() const { return mana; } - int RelativeMana(int max) { return mana * max / maxMana; } + int RelativeMana(int max) const { return mana * max / maxMana; } Uint16 Attack() const { return attack; } Uint16 Defense() const { return defense; } diff --git a/src/battle/MoveMenu.cpp b/src/battle/MoveMenu.cpp new file mode 100644 index 0000000..4d5ff79 --- /dev/null +++ b/src/battle/MoveMenu.cpp @@ -0,0 +1,29 @@ +/* + * MoveMenu.cpp + * + * Created on: Aug 7, 2012 + * Author: holy + */ + +#include "MoveMenu.h" + +#include "../geometry/operators.h" +#include "../geometry/Vector.h" +#include "../graphics/Sprite.h" + +using geometry::Point; +using geometry::Vector; + +namespace battle { + +void MoveMenu::Render(SDL_Surface *screen, const geometry::Point &position) { + Vector attackOffset(0, IconHeight()); + Vector changeOffset(0, 0); + Vector runOffset(0, 2 * IconHeight()); + + icons->Draw(screen, position + attackOffset, ATTACK, (selected == ATTACK) ? 1 : 0); + icons->Draw(screen, position + changeOffset, CHANGE, (selected == CHANGE) ? 1 : 0); + icons->Draw(screen, position + runOffset, RUN, (selected == RUN) ? 1 : 0); +} + +} diff --git a/src/battle/MoveMenu.h b/src/battle/MoveMenu.h new file mode 100644 index 0000000..771fcb8 --- /dev/null +++ b/src/battle/MoveMenu.h @@ -0,0 +1,48 @@ +/* + * MoveMenu.h + * + * Created on: Aug 7, 2012 + * Author: holy + */ + +#ifndef BATTLE_MOVEMENU_H_ +#define BATTLE_MOVEMENU_H_ + +#include "../geometry/Point.h" +#include "../graphics/Sprite.h" + +namespace battle { + +class MoveMenu { + +public: + enum Icon { + ATTACK, + CHANGE, + RUN + }; + +public: + explicit MoveMenu(const graphics::Sprite *icons) + : icons(icons), selected(ATTACK) { } + ~MoveMenu() { } + +public: + void Select(Icon i) { selected = i; } + Icon Selected() const { return selected; } + void Render(SDL_Surface *screen, const geometry::Point &position); + + int Width() const { return IconWidth(); } + int Height() const { return 3 * IconHeight(); } + int IconWidth() const { return icons->Width(); } + int IconHeight() const { return icons->Height(); } + +private: + const graphics::Sprite *icons; + Icon selected; + +}; + +} + +#endif /* BATTLE_MOVEMENU_H_ */ diff --git a/src/main.cpp b/src/main.cpp index 4ea0e0e..bd8ff4a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,12 +73,21 @@ int main(int argc, char **argv) { Monster monster; monster.SetSprite(&dummySprite); Hero hero; + hero.SetName("Name"); + hero.SetLevel(34); hero.SetSprite(&dummySprite); + hero.SetMaxHealth(100); + hero.SetHealth(50); + hero.SetMaxMana(100); + hero.SetMana(66); + hero.SetIP(160); SDL_Surface *attackIcons(IMG_Load("test-data/attack-type-icons.png")); Sprite attackIconsSprite(attackIcons, 32, 32); + SDL_Surface *moveIcons(IMG_Load("test-data/move-icons.png")); + Sprite moveIconsSprite(moveIcons, 32, 32); - BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite)); + BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite)); battleState->AddMonster(monster); battleState->AddMonster(monster); battleState->AddMonster(monster); diff --git a/test-data/move-icons.png b/test-data/move-icons.png new file mode 100644 index 0000000..93a6b10 Binary files /dev/null and b/test-data/move-icons.png differ