From 47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 12 Mar 2015 22:46:32 -0400 Subject: Fixed bug that would prevent player from continuing to move after dying, and also refactored collisions and dying a bit --- src/game.cpp | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'src/game.cpp') 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 @@ #include "game.h" #include "renderer.h" #include "components.h" +#include "muxer.h" Game::Game() { @@ -132,33 +133,27 @@ void Game::saveGame(const Map& map, std::pair position) save = {&map, position}; } -void Game::loadGame(const Map& curMap) +void Game::schedule(int frames, std::function&& callback) { - if (&curMap == save.map) - { - entities.remove(player); - } - - player = std::make_shared(); - player->position = save.position; - player->size = std::make_pair(10.0,12.0); - - auto player_input = std::make_shared(); - player->addComponent(player_input); - - auto player_physics = std::make_shared(); - player->addComponent(player_physics); - - auto player_anim = std::make_shared(); - player->addComponent(player_anim); - - if (&curMap != save.map) - { - loadMap(*(save.map)); - } + scheduled.emplace_front(frames, callback); } -void Game::schedule(int frames, std::function&& callback) +void Game::playerDie(Entity& player, const Map& curMap) { - scheduled.emplace_front(frames, callback); + Message msg(Message::Type::die); + player.send(*this, msg); + + playSound("../res/Hit_Hurt5.wav", 0.25); + + schedule(FRAMES_PER_SECOND * 0.75, [&] () { + if (&curMap != save.map) + { + loadMap(*(save.map)); + } + + player.position = save.position; + + Message msg2(Message::Type::stopDying); + player.send(*this, msg2); + }); } -- cgit 1.4.1