]> git.localhorst.tv Git - l2e.git/commitdiff
added battle move menu
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 7 Aug 2012 10:23:10 +0000 (12:23 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 7 Aug 2012 10:23:10 +0000 (12:23 +0200)
14 files changed:
Debug/src/battle/subdir.mk
Release/src/battle/subdir.mk
src/battle/AttackTypeMenu.cpp
src/battle/AttackTypeMenu.h
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.h
src/battle/HeroTag.cpp
src/battle/HeroTag.h
src/battle/Monster.h
src/battle/MoveMenu.cpp [new file with mode: 0644]
src/battle/MoveMenu.h [new file with mode: 0644]
src/main.cpp
test-data/move-icons.png [new file with mode: 0644]

index 0ef38a1b92aefccd8627c8a6907311e2479db677..d967ca2be744e327827160cf3326583b94979021 100644 (file)
@@ -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 
 
 
index e59a859652022563eaf1b08ba2749c3c254adf33..2ae5c5935d56a92fd8e45714ff4dba24f6d607df 100644 (file)
@@ -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 
 
 
index b881d8b6f5ee57d5a95e515109bf5e132d9c3148..bee794f453a813e53355816a3c0ffa6d33cd36a0 100644 (file)
@@ -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<int> &position) {
        Vector<int> swordOffset(IconWidth(), IconHeight());
        Vector<int> magicOffset(IconWidth(), 0);
index 08caf7f4160c3e93e4bed77eb4425770af317518..26a9dd9d07089ea128fe566c884c01fd0d30d045 100644 (file)
@@ -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<int> &position);
 
index 758d9d8224a097d2b0cdd731dfc00dac17117b59..a2c306a2ef7050d1fd9d0a468d768d152962229b 100644 (file)
@@ -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<int> &offset) {
@@ -112,7 +144,7 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset)
        tagPosition[3] = Point<int>(tagWidth + attackTypeMenu.IconWidth(), uiOffset + tagHeight + attackTypeMenu.IconHeight());
 
        for (vector<HeroTag>::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<int> &o
        attackTypeMenu.Render(screen, position + offset);
 }
 
+void BattleState::RenderMoveMenu(SDL_Surface *screen, const Vector<int> &offset) {
+       Point<int> position(
+                       (background->w - moveMenu.Width()) / 2,
+                       (background->h * 3 / 4) - (moveMenu.Height() / 2));
+       moveMenu.Render(screen, position + offset);
+}
+
 }
index 8fa7d951ac393bcf5dd5917cc36d2b34f44bbce5..daf1cae65f10c0f4c85267cdfc34bf39368360a1 100644 (file)
@@ -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<int> &offset);
        void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderAttackTypeMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
+       void RenderMoveMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
        SDL_Surface *background;
        const PartyLayout *monstersLayout;
        const PartyLayout *heroesLayout;
        AttackTypeMenu attackTypeMenu;
+       MoveMenu moveMenu;
        std::vector<geometry::Point<int> > monsterPositions;
        std::vector<geometry::Point<int> > heroesPositions;
        std::vector<Monster> monsters;
        std::vector<Hero> heroes;
        std::vector<HeroTag> heroTags;
+       int moveChoice;
+       int activeHero;
 
 };
 
index ec87f4944cec872225fdff869c9306c3cf229968..59512b61e3e067c5bc3772e6eed7a98a54159758 100644 (file)
@@ -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;
 
 };
 
index 2461e4de92363b2a19b0c020e1dd5eb1ec6c64c1..d67368ff9b98bf4d0d097e97c03633b0416993c1 100644 (file)
@@ -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<int> position) const {
+void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> 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<int> 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<int> heroOffset(
+                       (align == LEFT) ? 3 : width - hero->Sprite()->Width() - 3,
+                       height - hero->Sprite()->Height() - 3);
+       hero->Sprite()->Draw(screen, position + heroOffset);
 }
 
 }
index e0d3a5aa4ac381f9600305cb19a4caa79241f509..c60634853035bf58b76800c48e71b2e90d2f1426 100644 (file)
@@ -29,7 +29,7 @@ public:
        ~HeroTag() { }
 
 public:
-       void Render(SDL_Surface *screen, int width, int height, geometry::Point<int> position) const;
+       void Render(SDL_Surface *screen, int width, int height, geometry::Point<int> position, bool active) const;
 
 private:
        const Hero *hero;
index e77a14b9e326a1e4eae1ec1fb980bafcbe271a0e..1c9218413fef2a78bd72655fb977051ba5781fcc 100644 (file)
@@ -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 (file)
index 0000000..4d5ff79
--- /dev/null
@@ -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<int> &position) {
+       Vector<int> attackOffset(0, IconHeight());
+       Vector<int> changeOffset(0, 0);
+       Vector<int> 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 (file)
index 0000000..771fcb8
--- /dev/null
@@ -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<int> &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_ */
index 4ea0e0e3f067c530f33a4ffa17721ddb6d84d980..bd8ff4a48c0850c58232857a6b439d23bdff3853 100644 (file)
@@ -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 (file)
index 0000000..93a6b10
Binary files /dev/null and b/test-data/move-icons.png differ