summary refs log tree commit diff stats
path: root/src/game.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-03-12 22:46:32 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-03-12 22:46:32 -0400
commit47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e (patch)
tree14acad810f6ef199d7fc669fc1abe91972eb7f6a /src/game.cpp
parentcc75196b1baca28a142e66c69cd51200649d252a (diff)
downloadtherapy-47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e.tar.gz
therapy-47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e.tar.bz2
therapy-47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e.zip
Fixed bug that would prevent player from continuing to move after dying, and also refactored collisions and dying a bit
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp45
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
5Game::Game() 6Game::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
135void Game::loadGame(const Map& curMap) 136void 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
161void Game::schedule(int frames, std::function<void ()>&& callback) 141void 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}