../src/battle/Hero.cpp \
../src/battle/HeroTag.cpp \
../src/battle/Monster.cpp \
+../src/battle/MoveMenu.cpp \
../src/battle/PartyLayout.cpp
OBJS += \
./src/battle/Hero.o \
./src/battle/HeroTag.o \
./src/battle/Monster.o \
+./src/battle/MoveMenu.o \
./src/battle/PartyLayout.o
CPP_DEPS += \
./src/battle/Hero.d \
./src/battle/HeroTag.d \
./src/battle/Monster.d \
+./src/battle/MoveMenu.d \
./src/battle/PartyLayout.d
../src/battle/Hero.cpp \
../src/battle/HeroTag.cpp \
../src/battle/Monster.cpp \
+../src/battle/MoveMenu.cpp \
../src/battle/PartyLayout.cpp
OBJS += \
./src/battle/Hero.o \
./src/battle/HeroTag.o \
./src/battle/Monster.o \
+./src/battle/MoveMenu.o \
./src/battle/PartyLayout.o
CPP_DEPS += \
./src/battle/Hero.d \
./src/battle/HeroTag.d \
./src/battle/Monster.d \
+./src/battle/MoveMenu.d \
./src/battle/PartyLayout.d
#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);
#ifndef BATTLE_ATTACKTYPEMENU_H_
#define BATTLE_ATTACKTYPEMENU_H_
-namespace app { class Input; }
-
#include "../geometry/Point.h"
#include "../graphics/Sprite.h"
: 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);
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) {
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) {
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);
}
}
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);
+}
+
}
#include "Hero.h"
#include "HeroTag.h"
#include "Monster.h"
+#include "MoveMenu.h"
#include "../app/State.h"
#include "../geometry/Point.h"
#include "../geometry/Vector.h"
: 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 &);
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;
};
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; }
// 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;
Uint16 magicResistance;
Uint8 level;
+ Uint8 ip;
};
#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();
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);
}
}
~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;
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; }
--- /dev/null
+/*
+ * 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);
+}
+
+}
--- /dev/null
+/*
+ * 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_ */
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);