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.cpp38
1 files changed, 36 insertions, 2 deletions
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)
77 { 77 {
78 entity->tick(*this); 78 entity->tick(*this);
79 } 79 }
80
81 // Do any scheduled tasks
82 for (auto& task : scheduled)
83 {
84 task.first--;
85
86 if (task.first == 0)
87 {
88 task.second();
89 }
90 }
91
92 scheduled.remove_if([] (std::pair<int, std::function<void ()>> value) { return value.first == 0; });
80 93
81 // Do rendering 94 // Do rendering
82 buffer.fill(buffer.entirety(), 0, 0, 0); 95 buffer.fill(buffer.entirety(), 0, 0, 0);
@@ -121,10 +134,31 @@ void Game::saveGame(const Map& map, std::pair<double, double> position)
121 134
122void Game::loadGame(const Map& curMap) 135void Game::loadGame(const Map& curMap)
123{ 136{
124 if (&curMap != save.map) 137 if (&curMap == save.map)
125 { 138 {
126 loadMap(*(save.map)); 139 entities.remove(player);
127 } 140 }
128 141
142 player = std::make_shared<Entity>();
129 player->position = save.position; 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}
160
161void Game::schedule(int frames, std::function<void ()>&& callback)
162{
163 scheduled.emplace(begin(scheduled), frames, callback);
130} 164}