From: Daniel Karbach Date: Sun, 5 Aug 2012 16:37:39 +0000 (+0200) Subject: added battle party layout class X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=95bfa881f3fa427b67d9ce21e6a10f80f7be5439;p=l2e.git added battle party layout class --- diff --git a/Debug/src/battle/subdir.mk b/Debug/src/battle/subdir.mk index 6cc1a8f..8eb479b 100644 --- a/Debug/src/battle/subdir.mk +++ b/Debug/src/battle/subdir.mk @@ -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 diff --git a/Release/src/battle/subdir.mk b/Release/src/battle/subdir.mk index c2080a7..123e7f8 100644 --- a/Release/src/battle/subdir.mk +++ b/Release/src/battle/subdir.mk @@ -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 diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 25fb09c..df83c32 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -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() { diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index b88bae3..05bd7c9 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -10,18 +10,22 @@ #include "Monster.h" #include "../app/State.h" +#include "../geometry/Point.h" #include #include 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 > monsterPositions; std::vector monsters; }; diff --git a/src/battle/PartyLayout.cpp b/src/battle/PartyLayout.cpp new file mode 100644 index 0000000..e1fd33f --- /dev/null +++ b/src/battle/PartyLayout.cpp @@ -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 index 0000000..1456f15 --- /dev/null +++ b/src/battle/PartyLayout.h @@ -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 +#include + +namespace battle { + +class PartyLayout { + +public: + PartyLayout() { } + +public: + int NumPositions() const { return positions.size(); } + template + void CalculatePositions(U width, U height, std::vector > &dest) const { + dest.clear(); + dest.reserve(positions.size()); + for (std::vector >::const_iterator i(positions.begin()), end(positions.end()); i != end; ++i) { + dest.push_back(geometry::Point( + i->X() * 256 / width, + i->Y() * 256 / height + )); + } + } + +public: + void AddPosition(const geometry::Point &p) { + positions.push_back(p); + } + +private: + std::vector > positions; + +}; + +} + +#endif /* BATTLE_PARTYLAYOUT_H_ */ diff --git a/src/main.cpp b/src/main.cpp index 780b8c2..4e5fb47 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(50, 50)); + monstersLayout.AddPosition(Point(100, 50)); + monstersLayout.AddPosition(Point(150, 50)); + monstersLayout.AddPosition(Point(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;