]> git.localhorst.tv Git - l2e.git/commitdiff
added Hero class for battle state
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 11:44:55 +0000 (13:44 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 11:44:55 +0000 (13:44 +0200)
Debug/src/battle/subdir.mk
Release/src/battle/subdir.mk
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.cpp [new file with mode: 0644]
src/battle/Hero.h [new file with mode: 0644]
src/main.cpp

index 8eb479bc75ebddd1c30207db1ecb49c8a7a954c0..52e0e02ff429823c32b8a22ba7f4d5d2cd4ff84f 100644 (file)
@@ -5,16 +5,19 @@
 # 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 
 
index 123e7f8522050b43d31f5af9575955063c57e7cd..6cff662588de8f10fc4da35013998ded97394a24 100644 (file)
@@ -5,16 +5,19 @@
 # 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 
 
index d1a983f23d198787daef4af3aac198e1d08db759..511d29e2dc930ec182667fcc9df8b24db52ddd91 100644 (file)
@@ -26,6 +26,13 @@ void BattleState::AddMonster(const Monster &m) {
        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) {
 
@@ -65,6 +72,10 @@ void BattleState::Render(SDL_Surface *screen) {
        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));
+       }
 }
 
 }
index 06b8fbd8291fbf3cd41136013d901da28028b3aa..205397a46a72db682f3085bf015a9ad266d36700 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef BATTLE_BATTLESTATE_H_
 #define BATTLE_BATTLESTATE_H_
 
+#include "Hero.h"
 #include "Monster.h"
 #include "../app/State.h"
 #include "../geometry/Point.h"
@@ -30,6 +31,7 @@ public:
 
 public:
        void AddMonster(const Monster &);
+       void AddHero(const Hero &);
 
 public:
        virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
@@ -48,6 +50,7 @@ private:
        std::vector<geometry::Point<int> > monsterPositions;
        std::vector<geometry::Point<int> > heroesPositions;
        std::vector<Monster> monsters;
+       std::vector<Hero> heroes;
 
 };
 
diff --git a/src/battle/Hero.cpp b/src/battle/Hero.cpp
new file mode 100644 (file)
index 0000000..faaf841
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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
+
+}
+
+}
diff --git a/src/battle/Hero.h b/src/battle/Hero.h
new file mode 100644 (file)
index 0000000..ec87f49
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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_ */
index 2ecdbb64ed02e100d4083b949a0033498b9441e7..3ec99459014e6687127018e181b84b2c9b2bbea6 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "app/Application.h"
 #include "battle/BattleState.h"
+#include "battle/Hero.h"
 #include "battle/Monster.h"
 #include "battle/PartyLayout.h"
 #include "geometry/Point.h"
@@ -19,6 +20,7 @@
 
 using app::Application;
 using battle::BattleState;
+using battle::Hero;
 using battle::Monster;
 using battle::PartyLayout;
 using geometry::Point;
@@ -50,15 +52,17 @@ int main(int argc, char **argv) {
        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;
@@ -69,6 +73,10 @@ int main(int argc, char **argv) {
                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();