From 1a392a79b0491c5acc766705698191ed2ed6c2e6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 12 Mar 2015 13:48:10 -0400 Subject: Added death to my game --- src/game.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/game.cpp') 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) { entity->tick(*this); } + + // Do any scheduled tasks + for (auto& task : scheduled) + { + task.first--; + + if (task.first == 0) + { + task.second(); + } + } + + scheduled.remove_if([] (std::pair> value) { return value.first == 0; }); // Do rendering buffer.fill(buffer.entirety(), 0, 0, 0); @@ -121,10 +134,31 @@ void Game::saveGame(const Map& map, std::pair position) void Game::loadGame(const Map& curMap) { - if (&curMap != save.map) + if (&curMap == save.map) { - loadMap(*(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)); + } +} + +void Game::schedule(int frames, std::function&& callback) +{ + scheduled.emplace(begin(scheduled), frames, callback); } -- cgit 1.4.1