diff options
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/src/game.cpp b/src/game.cpp index 50c01f5..b2de5e9 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "game.h" | 1 | #include "game.h" |
2 | #include "renderer.h" | 2 | #include "renderer.h" |
3 | #include "components.h" | 3 | #include "components.h" |
4 | #include "muxer.h" | ||
4 | 5 | ||
5 | Game::Game() | 6 | Game::Game() |
6 | { | 7 | { |
@@ -132,33 +133,27 @@ void Game::saveGame(const Map& map, std::pair<double, double> position) | |||
132 | save = {&map, position}; | 133 | save = {&map, position}; |
133 | } | 134 | } |
134 | 135 | ||
135 | void Game::loadGame(const Map& curMap) | 136 | void Game::schedule(int frames, std::function<void ()>&& callback) |
136 | { | 137 | { |
137 | if (&curMap == save.map) | 138 | scheduled.emplace_front(frames, callback); |
138 | { | ||
139 | entities.remove(player); | ||
140 | } | ||
141 | |||
142 | player = std::make_shared<Entity>(); | ||
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 | } | 139 | } |
160 | 140 | ||
161 | void Game::schedule(int frames, std::function<void ()>&& callback) | 141 | void Game::playerDie(Entity& player, const Map& curMap) |
162 | { | 142 | { |
163 | scheduled.emplace_front(frames, callback); | 143 | Message msg(Message::Type::die); |
144 | player.send(*this, msg); | ||
145 | |||
146 | playSound("../res/Hit_Hurt5.wav", 0.25); | ||
147 | |||
148 | schedule(FRAMES_PER_SECOND * 0.75, [&] () { | ||
149 | if (&curMap != save.map) | ||
150 | { | ||
151 | loadMap(*(save.map)); | ||
152 | } | ||
153 | |||
154 | player.position = save.position; | ||
155 | |||
156 | Message msg2(Message::Type::stopDying); | ||
157 | player.send(*this, msg2); | ||
158 | }); | ||
164 | } | 159 | } |