]> git.localhorst.tv Git - l2e.git/commitdiff
added battle party layout class
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 5 Aug 2012 16:37:39 +0000 (18:37 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 5 Aug 2012 16:37:39 +0000 (18:37 +0200)
Debug/src/battle/subdir.mk
Release/src/battle/subdir.mk
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/PartyLayout.cpp [new file with mode: 0644]
src/battle/PartyLayout.h [new file with mode: 0644]
src/main.cpp

index 6cc1a8f15db610e49a9e942448cc58291ad24ee3..8eb479bc75ebddd1c30207db1ecb49c8a7a954c0 100644 (file)
@@ -5,15 +5,18 @@
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
 ../src/battle/BattleState.cpp \
-../src/battle/Monster.cpp 
+../src/battle/Monster.cpp \
+../src/battle/PartyLayout.cpp 
 
 OBJS += \
 ./src/battle/BattleState.o \
-./src/battle/Monster.o 
+./src/battle/Monster.o \
+./src/battle/PartyLayout.o 
 
 CPP_DEPS += \
 ./src/battle/BattleState.d \
-./src/battle/Monster.d 
+./src/battle/Monster.d \
+./src/battle/PartyLayout.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
index c2080a7ded4f7eff26a3f08fa2e1101f9df4e8a3..123e7f8522050b43d31f5af9575955063c57e7cd 100644 (file)
@@ -5,15 +5,18 @@
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
 ../src/battle/BattleState.cpp \
-../src/battle/Monster.cpp 
+../src/battle/Monster.cpp \
+../src/battle/PartyLayout.cpp 
 
 OBJS += \
 ./src/battle/BattleState.o \
-./src/battle/Monster.o 
+./src/battle/Monster.o \
+./src/battle/PartyLayout.o 
 
 CPP_DEPS += \
 ./src/battle/BattleState.d \
-./src/battle/Monster.d 
+./src/battle/Monster.d \
+./src/battle/PartyLayout.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
index 25fb09c0e59b171100f1de77f0bee853337e0243..df83c328d2b5a6c32330a1b76cc65444922b2cf0 100644 (file)
@@ -7,12 +7,14 @@
 
 #include "BattleState.h"
 
+#include "PartyLayout.h"
+
 using app::Application;
 
 namespace battle {
 
 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
-
+       monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
 }
 
 void BattleState::ExitState() {
index b88bae3b30b8a7151d45c3db34041ac4ac8b6fcb..05bd7c95128ae6352b9360d3b1cc34243aab89a4 100644 (file)
 
 #include "Monster.h"
 #include "../app/State.h"
+#include "../geometry/Point.h"
 
 #include <vector>
 #include <SDL.h>
 
 namespace battle {
 
+class PartyLayout;
+
 class BattleState
 : public app::State {
 
 public:
-       explicit BattleState(SDL_Surface *background)
-       : background(background) { }
+       BattleState(SDL_Surface *background, const PartyLayout &monstersLayout)
+       : background(background)
+       , monstersLayout(&monstersLayout) { }
 
 public:
        virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
@@ -33,6 +37,8 @@ public:
 
 private:
        SDL_Surface *background;
+       const PartyLayout *monstersLayout;
+       std::vector<geometry::Point<int> > monsterPositions;
        std::vector<Monster> monsters;
 
 };
diff --git a/src/battle/PartyLayout.cpp b/src/battle/PartyLayout.cpp
new file mode 100644 (file)
index 0000000..e1fd33f
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * PartyLayout.cpp
+ *
+ *  Created on: Aug 5, 2012
+ *      Author: holy
+ */
+
+#include "PartyLayout.h"
+
+using geometry::Point;
+using std::vector;
+
+namespace battle {
+
+}
diff --git a/src/battle/PartyLayout.h b/src/battle/PartyLayout.h
new file mode 100644 (file)
index 0000000..1456f15
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * PartyLayout.h
+ *
+ *  Created on: Aug 5, 2012
+ *      Author: holy
+ */
+
+#ifndef BATTLE_PARTYLAYOUT_H_
+#define BATTLE_PARTYLAYOUT_H_
+
+#include "../geometry/Point.h"
+
+#include <vector>
+#include <SDL.h>
+
+namespace battle {
+
+class PartyLayout {
+
+public:
+       PartyLayout() { }
+
+public:
+       int NumPositions() const { return positions.size(); }
+       template<class U>
+       void CalculatePositions(U width, U height, std::vector<geometry::Point<U> > &dest) const {
+               dest.clear();
+               dest.reserve(positions.size());
+               for (std::vector<geometry::Point<Uint8> >::const_iterator i(positions.begin()), end(positions.end()); i != end; ++i) {
+                       dest.push_back(geometry::Point<U>(
+                                       i->X() * 256 / width,
+                                       i->Y() * 256 / height
+                                       ));
+               }
+       }
+
+public:
+       void AddPosition(const geometry::Point<Uint8> &p) {
+               positions.push_back(p);
+       }
+
+private:
+       std::vector<geometry::Point<Uint8> > positions;
+
+};
+
+}
+
+#endif /* BATTLE_PARTYLAYOUT_H_ */
index 780b8c27b70c85e004d77d45e0a1a3b6e8358971..4e5fb471543cf5378bfddd98c77c9e14533e3a92 100644 (file)
@@ -7,6 +7,8 @@
 
 #include "app/Application.h"
 #include "battle/BattleState.h"
+#include "battle/PartyLayout.h"
+#include "geometry/Point.h"
 #include "sdl/InitScreen.h"
 #include "sdl/InitSDL.h"
 
@@ -15,6 +17,8 @@
 
 using app::Application;
 using battle::BattleState;
+using battle::PartyLayout;
+using geometry::Point;
 using sdl::InitScreen;
 using sdl::InitSDL;
 
@@ -30,12 +34,17 @@ int main(int argc, char **argv) {
        // temporary
        SDL_Surface *bg(SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
        SDL_FillRect(bg, 0, SDL_MapRGB(bg->format, 0, 0, 0));
+       PartyLayout monstersLayout;
+       monstersLayout.AddPosition(Point<Uint8>(50, 50));
+       monstersLayout.AddPosition(Point<Uint8>(100, 50));
+       monstersLayout.AddPosition(Point<Uint8>(150, 50));
+       monstersLayout.AddPosition(Point<Uint8>(200, 50));
 
        try {
                InitSDL sdl;
                InitScreen screen(width, height);
 
-               Application app(screen.Screen(), new BattleState(bg));
+               Application app(screen.Screen(), new BattleState(bg, monstersLayout));
                app.Run();
 
                return 0;