summary refs log tree commit diff stats
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/game.cpp b/src/game.cpp index 6e79f75..20b8564 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -1,9 +1,12 @@
1#include "game.h" 1#include "game.h"
2#include "renderer.h" 2#include "renderer.h"
3#include "components.h"
4#include "muxer.h" 3#include "muxer.h"
5#include "entityfactory.h"
6#include "map.h" 4#include "map.h"
5#include "components/user_movement.h"
6#include "components/player_physics.h"
7#include "components/player_sprite.h"
8#include "components/map_render.h"
9#include "components/map_collision.h"
7 10
8Game::Game() 11Game::Game()
9{ 12{
@@ -23,7 +26,7 @@ Game::Game()
23 Map& startingMap = Map::getNamedMap("embarass"); 26 Map& startingMap = Map::getNamedMap("embarass");
24 save = {&startingMap, player->position}; 27 save = {&startingMap, player->position};
25 28
26 loadMap(startingMap); 29 loadMap(startingMap, player->position);
27} 30}
28 31
29void key_callback(GLFWwindow* window, int key, int, int action, int) 32void key_callback(GLFWwindow* window, int key, int, int action, int)
@@ -65,6 +68,8 @@ void Game::execute(GLFWwindow* window)
65 newWorld = false; 68 newWorld = false;
66 entities.clear(); 69 entities.clear();
67 entities = std::move(nextEntities); 70 entities = std::move(nextEntities);
71
72 player->position = nextPosition;
68 } 73 }
69 74
70 // Handle input 75 // Handle input
@@ -106,7 +111,7 @@ void Game::execute(GLFWwindow* window)
106 } 111 }
107} 112}
108 113
109void Game::loadMap(const Map& map) 114void Game::loadMap(const Map& map, std::pair<double, double> position)
110{ 115{
111 auto mapEn = std::make_shared<Entity>(); 116 auto mapEn = std::make_shared<Entity>();
112 117
@@ -125,6 +130,7 @@ void Game::loadMap(const Map& map)
125 newWorld = true; 130 newWorld = true;
126 131
127 currentMap = &map; 132 currentMap = &map;
133 nextPosition = position;
128} 134}
129 135
130void Game::detectCollision(Entity& collider, std::pair<double, double> old_position) 136void Game::detectCollision(Entity& collider, std::pair<double, double> old_position)
@@ -154,10 +160,11 @@ void Game::playerDie()
154 schedule(0.75, [&] () { 160 schedule(0.75, [&] () {
155 if (*currentMap != *save.map) 161 if (*currentMap != *save.map)
156 { 162 {
157 loadMap(*save.map); 163 loadMap(*save.map, save.position);
164 } else {
165 player->position = save.position;
158 } 166 }
159 167
160 player->position = save.position;
161 player->send(*this, Message::Type::stopDying); 168 player->send(*this, Message::Type::stopDying);
162 }); 169 });
163} 170}