# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../src/battle/BattleState.cpp \
+../src/battle/Hero.cpp \
../src/battle/Monster.cpp \
../src/battle/PartyLayout.cpp
OBJS += \
./src/battle/BattleState.o \
+./src/battle/Hero.o \
./src/battle/Monster.o \
./src/battle/PartyLayout.o
CPP_DEPS += \
./src/battle/BattleState.d \
+./src/battle/Hero.d \
./src/battle/Monster.d \
./src/battle/PartyLayout.d
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../src/battle/BattleState.cpp \
+../src/battle/Hero.cpp \
../src/battle/Monster.cpp \
../src/battle/PartyLayout.cpp
OBJS += \
./src/battle/BattleState.o \
+./src/battle/Hero.o \
./src/battle/Monster.o \
./src/battle/PartyLayout.o
CPP_DEPS += \
./src/battle/BattleState.d \
+./src/battle/Hero.d \
./src/battle/Monster.d \
./src/battle/PartyLayout.d
monsters.push_back(m);
}
+void BattleState::AddHero(const Hero &h) {
+ if (heroes.size() >= heroesLayout->NumPositions()) {
+ throw std::overflow_error("too many heroes for layout");
+ }
+ heroes.push_back(h);
+}
+
void BattleState::Resize(int w, int h) {
for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
monsters[i].Sprite()->DrawCenterBottom(screen, Point<int>(monsterPositions[i].X() + destRect.x, monsterPositions[i].Y() + destRect.y));
}
+
+ for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+ heroes[i].Sprite()->DrawCenterBottom(screen, Point<int>(heroesPositions[i].X() + destRect.x, heroesPositions[i].Y() + destRect.y));
+ }
}
}
#ifndef BATTLE_BATTLESTATE_H_
#define BATTLE_BATTLESTATE_H_
+#include "Hero.h"
#include "Monster.h"
#include "../app/State.h"
#include "../geometry/Point.h"
public:
void AddMonster(const Monster &);
+ void AddHero(const Hero &);
public:
virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
std::vector<geometry::Point<int> > monsterPositions;
std::vector<geometry::Point<int> > heroesPositions;
std::vector<Monster> monsters;
+ std::vector<Hero> heroes;
};
--- /dev/null
+/*
+ * Hero.cpp
+ *
+ * Created on: Aug 6, 2012
+ * Author: holy
+ */
+
+#include "Hero.h"
+
+namespace battle {
+
+Hero::Hero() {
+ // TODO Auto-generated constructor stub
+
+}
+
+Hero::~Hero() {
+ // TODO Auto-generated destructor stub
+
+}
+
+}
--- /dev/null
+/*
+ * Hero.h
+ *
+ * Created on: Aug 6, 2012
+ * Author: holy
+ */
+
+#ifndef BATTLE_HERO_H_
+#define BATTLE_HERO_H_
+
+#include <SDL.h>
+
+namespace graphics { class Sprite; }
+
+namespace battle {
+
+class Hero {
+
+public:
+ Hero();
+ ~Hero();
+
+public:
+ const char *Name() const { return name; }
+ Uint8 Level() const { return level; }
+ const graphics::Sprite *Sprite() const { return sprite; }
+
+ Uint16 MaxHealth() const { return maxHealth; }
+ Uint16 Health() const { return health; }
+ int RelativeHealth(int max) { return health * max / maxHealth; }
+
+ Uint16 MaxMana() const { return maxMana; }
+ Uint16 Mana() const { return mana; }
+ int RelativeMana(int max) { return mana * max / maxMana; }
+
+ Uint16 Attack() const { return attack; }
+ Uint16 Defense() const { return defense; }
+ Uint16 Agility() const { return agility; }
+ Uint16 Intelligence() const { return intelligence; }
+ Uint16 Gut() const { return gut; }
+ Uint16 MagicResistance() const { return magicResistance; }
+
+// temporary setters until loader is implemented
+public:
+ void SetSprite(graphics::Sprite *s) { sprite = s; }
+
+private:
+ const char *name;
+ graphics::Sprite *sprite;
+ // TODO: equipment and spells lists
+
+ Uint16 maxHealth, health;
+ Uint16 maxMana, mana;
+
+ Uint16 attack;
+ Uint16 defense;
+ Uint16 agility;
+ Uint16 intelligence;
+ Uint16 gut;
+ Uint16 magicResistance;
+
+ Uint8 level;
+
+};
+
+}
+
+#endif /* BATTLE_HERO_H_ */
#include "app/Application.h"
#include "battle/BattleState.h"
+#include "battle/Hero.h"
#include "battle/Monster.h"
#include "battle/PartyLayout.h"
#include "geometry/Point.h"
using app::Application;
using battle::BattleState;
+using battle::Hero;
using battle::Monster;
using battle::PartyLayout;
using geometry::Point;
monstersLayout.AddPosition(Point<Uint8>(150, 100));
monstersLayout.AddPosition(Point<Uint8>(200, 100));
PartyLayout heroesLayout;
- heroesLayout.AddPosition(Point<Uint8>(45, 132));
- heroesLayout.AddPosition(Point<Uint8>(174, 136));
- heroesLayout.AddPosition(Point<Uint8>(110, 143));
- heroesLayout.AddPosition(Point<Uint8>(239, 148));
- SDL_Surface *white100(SDL_CreateRGBSurface(0, 100, 100, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
- SDL_FillRect(white100, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
- Sprite dummyMonsterSprite(white100, 100, 100);
+ heroesLayout.AddPosition(Point<Uint8>(27, 219));
+ heroesLayout.AddPosition(Point<Uint8>(104, 227));
+ heroesLayout.AddPosition(Point<Uint8>(66, 238));
+ heroesLayout.AddPosition(Point<Uint8>(143, 246));
+ SDL_Surface *white96(SDL_CreateRGBSurface(0, 96, 96, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
+ SDL_FillRect(white96, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
+ Sprite dummySprite(white96, 96, 96);
Monster monster;
- monster.SetSprite(&dummyMonsterSprite);
+ monster.SetSprite(&dummySprite);
+ Hero hero;
+ hero.SetSprite(&dummySprite);
try {
InitSDL sdl;
battleState->AddMonster(monster);
battleState->AddMonster(monster);
battleState->AddMonster(monster);
+ battleState->AddHero(hero);
+ battleState->AddHero(hero);
+ battleState->AddHero(hero);
+ battleState->AddHero(hero);
Application app(&screen, battleState);
app.Run();