From e02068d51f5e7f82d4d3195e9a9ce5c9d76f727d Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 7 Oct 2012 16:15:50 +0200 Subject: [PATCH] added map transition state --- Debug/src/map/subdir.mk | 3 ++ Release/src/map/subdir.mk | 3 ++ src/map/MapState.cpp | 13 ++++++-- src/map/MapState.h | 1 + src/map/TransitionState.cpp | 64 +++++++++++++++++++++++++++++++++++++ src/map/TransitionState.h | 46 ++++++++++++++++++++++++++ src/map/fwd.h | 1 + 7 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 src/map/TransitionState.cpp create mode 100644 src/map/TransitionState.h diff --git a/Debug/src/map/subdir.mk b/Debug/src/map/subdir.mk index 01eb787..5faffc5 100644 --- a/Debug/src/map/subdir.mk +++ b/Debug/src/map/subdir.mk @@ -9,6 +9,7 @@ CPP_SRCS += \ ../src/map/Map.cpp \ ../src/map/MapState.cpp \ ../src/map/Tile.cpp \ +../src/map/TransitionState.cpp \ ../src/map/Trigger.cpp OBJS += \ @@ -17,6 +18,7 @@ OBJS += \ ./src/map/Map.o \ ./src/map/MapState.o \ ./src/map/Tile.o \ +./src/map/TransitionState.o \ ./src/map/Trigger.o CPP_DEPS += \ @@ -25,6 +27,7 @@ CPP_DEPS += \ ./src/map/Map.d \ ./src/map/MapState.d \ ./src/map/Tile.d \ +./src/map/TransitionState.d \ ./src/map/Trigger.d diff --git a/Release/src/map/subdir.mk b/Release/src/map/subdir.mk index cf8c41a..78e65f3 100644 --- a/Release/src/map/subdir.mk +++ b/Release/src/map/subdir.mk @@ -9,6 +9,7 @@ CPP_SRCS += \ ../src/map/Map.cpp \ ../src/map/MapState.cpp \ ../src/map/Tile.cpp \ +../src/map/TransitionState.cpp \ ../src/map/Trigger.cpp OBJS += \ @@ -17,6 +18,7 @@ OBJS += \ ./src/map/Map.o \ ./src/map/MapState.o \ ./src/map/Tile.o \ +./src/map/TransitionState.o \ ./src/map/Trigger.o CPP_DEPS += \ @@ -25,6 +27,7 @@ CPP_DEPS += \ ./src/map/Map.d \ ./src/map/MapState.d \ ./src/map/Tile.d \ +./src/map/TransitionState.d \ ./src/map/Trigger.d diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 791cc0b..64c2547 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -9,20 +9,24 @@ #include "Map.h" #include "Tile.h" +#include "TransitionState.h" #include "Trigger.h" #include "../app/Application.h" #include "../app/Input.h" +#include "../graphics/ColorFade.h" #include using app::Application; using app::Input; using geometry::Vector; +using graphics::ColorFade; namespace map { MapState::MapState(Map *map) -: map(map) +: ctrl(0) +, map(map) , controlled(0) , tempTarget(20, 20) , camera(100, 100, &tempTarget) @@ -35,7 +39,8 @@ MapState::MapState(Map *map) } -void MapState::EnterState(Application &ctrl, SDL_Surface *screen) { +void MapState::EnterState(Application &c, SDL_Surface *screen) { + ctrl = &c; camera.Resize(screen->w, screen->h); LoadMap(map); } @@ -235,7 +240,9 @@ void MapState::CheckTrigger() { if (trigger) { // TODO: run trigger script if (trigger->map) { - Transition(trigger->map, trigger->target); + ctrl->PushState(new ColorFade(this, 0, 500, true)); + ctrl->PushState(new TransitionState(this, trigger->map, trigger->target)); + ctrl->PushState(new ColorFade(this, 0, 500, false)); } } diff --git a/src/map/MapState.h b/src/map/MapState.h index 0e49100..dc352f6 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -64,6 +64,7 @@ private: void CheckTrigger(); private: + app::Application *ctrl; Map *map; Entity *controlled; app::Timer moveTimer; diff --git a/src/map/TransitionState.cpp b/src/map/TransitionState.cpp new file mode 100644 index 0000000..9a1d699 --- /dev/null +++ b/src/map/TransitionState.cpp @@ -0,0 +1,64 @@ +/* + * TransitionState.cpp + * + * Created on: Oct 7, 2012 + * Author: holy + */ + +#include "TransitionState.h" + +#include "MapState.h" +#include "../app/Application.h" + +using app::Application; +using app::State; +using app::Input; +using geometry::Vector; + +namespace map { + +TransitionState::TransitionState(MapState *ms, Map *map, const Vector &coordinates) +: ctrl(0) +, ms(ms) +, map(map) +, coordinates(coordinates) { + +} + +void TransitionState::EnterState(Application &c, SDL_Surface *screen) { + ctrl = &c; +} + +void TransitionState::ExitState(Application &, SDL_Surface *screen) { + +} + +void TransitionState::ResumeState(Application &ctrl, SDL_Surface *screen) { + +} + +void TransitionState::PauseState(Application &ctrl, SDL_Surface *screen) { + +} + + +void TransitionState::Resize(int width, int height) { + +} + + +void TransitionState::HandleEvents(const Input &input) { + ms->Transition(map, coordinates); + ctrl->PopState(); +} + + +void TransitionState::UpdateWorld(float deltaT) { + +} + +void TransitionState::Render(SDL_Surface *screen) { +// ms->Render(screen); +} + +} diff --git a/src/map/TransitionState.h b/src/map/TransitionState.h new file mode 100644 index 0000000..ee832a8 --- /dev/null +++ b/src/map/TransitionState.h @@ -0,0 +1,46 @@ +/* + * TransitionState.h + * + * Created on: Oct 7, 2012 + * Author: holy + */ + +#ifndef MAP_TRANSITIONSTATE_H_ +#define MAP_TRANSITIONSTATE_H_ + +#include "fwd.h" +#include "../app/State.h" +#include "../geometry/Vector.h" + +namespace map { + +class TransitionState +: public app::State { + +public: + TransitionState(MapState *, Map *, const geometry::Vector &); + virtual ~TransitionState() { } + +public: + virtual void EnterState(app::Application &ctrl, SDL_Surface *screen); + virtual void ExitState(app::Application &ctrl, SDL_Surface *screen); + virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen); + virtual void PauseState(app::Application &ctrl, SDL_Surface *screen); + + virtual void Resize(int width, int height); + + virtual void HandleEvents(const app::Input &); + virtual void UpdateWorld(float deltaT); + virtual void Render(SDL_Surface *); + +private: + app::Application *ctrl; + MapState *ms; + Map *map; + const geometry::Vector &coordinates; + +}; + +} + +#endif /* MAP_TRANSITIONSTATE_H_ */ diff --git a/src/map/fwd.h b/src/map/fwd.h index 8f2603c..464bb6f 100644 --- a/src/map/fwd.h +++ b/src/map/fwd.h @@ -15,6 +15,7 @@ class Entity; class Map; class MapState; class Tile; +class TransitionState; class Trigger; } -- 2.39.2