diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-12 13:48:10 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-12 13:48:10 -0400 |
commit | 1a392a79b0491c5acc766705698191ed2ed6c2e6 (patch) | |
tree | 787441b612f1aa03d777477fb32fdcb78c6a0197 /src/game.cpp | |
parent | ea0a959c2405511255080cae9f9558f2711a887f (diff) | |
download | therapy-1a392a79b0491c5acc766705698191ed2ed6c2e6.tar.gz therapy-1a392a79b0491c5acc766705698191ed2ed6c2e6.tar.bz2 therapy-1a392a79b0491c5acc766705698191ed2ed6c2e6.zip |
Added death to my game
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/game.cpp b/src/game.cpp index e392923..043c82b 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -77,6 +77,19 @@ void Game::execute(GLFWwindow* window) | |||
77 | { | 77 | { |
78 | entity->tick(*this); | 78 | entity->tick(*this); |
79 | } | 79 | } |
80 | |||
81 | // Do any scheduled tasks | ||
82 | for (auto& task : scheduled) | ||
83 | { | ||
84 | task.first--; | ||
85 | |||
86 | if (task.first == 0) | ||
87 | { | ||
88 | task.second(); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | scheduled.remove_if([] (std::pair<int, std::function<void ()>> value) { return value.first == 0; }); | ||
80 | 93 | ||
81 | // Do rendering | 94 | // Do rendering |
82 | buffer.fill(buffer.entirety(), 0, 0, 0); | 95 | buffer.fill(buffer.entirety(), 0, 0, 0); |
@@ -121,10 +134,31 @@ void Game::saveGame(const Map& map, std::pair<double, double> position) | |||
121 | 134 | ||
122 | void Game::loadGame(const Map& curMap) | 135 | void Game::loadGame(const Map& curMap) |
123 | { | 136 | { |
124 | if (&curMap != save.map) | 137 | if (&curMap == save.map) |
125 | { | 138 | { |
126 | loadMap(*(save.map)); | 139 | entities.remove(player); |
127 | } | 140 | } |
128 | 141 | ||
142 | player = std::make_shared<Entity>(); | ||
129 | player->position = save.position; | 143 | player->position = save.position; |
144 | player->size = std::make_pair(10.0,12.0); | ||
145 | |||
146 | auto player_input = std::make_shared<UserMovementComponent>(); | ||
147 | player->addComponent(player_input); | ||
148 | |||
149 | auto player_physics = std::make_shared<PlayerPhysicsComponent>(); | ||
150 | player->addComponent(player_physics); | ||
151 | |||
152 | auto player_anim = std::make_shared<PlayerSpriteComponent>(); | ||
153 | player->addComponent(player_anim); | ||
154 | |||
155 | if (&curMap != save.map) | ||
156 | { | ||
157 | loadMap(*(save.map)); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | void Game::schedule(int frames, std::function<void ()>&& callback) | ||
162 | { | ||
163 | scheduled.emplace(begin(scheduled), frames, callback); | ||
130 | } | 164 | } |