# 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
# 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
#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() {
#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);
private:
SDL_Surface *background;
+ const PartyLayout *monstersLayout;
+ std::vector<geometry::Point<int> > monsterPositions;
std::vector<Monster> monsters;
};
--- /dev/null
+/*
+ * PartyLayout.cpp
+ *
+ * Created on: Aug 5, 2012
+ * Author: holy
+ */
+
+#include "PartyLayout.h"
+
+using geometry::Point;
+using std::vector;
+
+namespace battle {
+
+}
--- /dev/null
+/*
+ * 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_ */
#include "app/Application.h"
#include "battle/BattleState.h"
+#include "battle/PartyLayout.h"
+#include "geometry/Point.h"
#include "sdl/InitScreen.h"
#include "sdl/InitSDL.h"
using app::Application;
using battle::BattleState;
+using battle::PartyLayout;
+using geometry::Point;
using sdl::InitScreen;
using sdl::InitSDL;
// 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;