diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-14 19:25:23 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-14 19:25:23 -0400 |
| commit | 6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b (patch) | |
| tree | 0a884ddd12b4e5b0afcc9c4ecaea5ecc73605b57 /src/game.cpp | |
| parent | d9349f10d6d1972e87aea76d502703fae128a0e5 (diff) | |
| download | therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.tar.gz therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.tar.bz2 therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.zip | |
Added sound when you hit the ground
Also split up components.cpp into files for each class, fixed a bug concerning falling off the screen when you change maps, and converted collision data into doubles.
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 19 |
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 | ||
| 8 | Game::Game() | 11 | Game::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 | ||
| 29 | void key_callback(GLFWwindow* window, int key, int, int action, int) | 32 | void 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 | ||
| 109 | void Game::loadMap(const Map& map) | 114 | void 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 = ↦ | 132 | currentMap = ↦ |
| 133 | nextPosition = position; | ||
| 128 | } | 134 | } |
| 129 | 135 | ||
| 130 | void Game::detectCollision(Entity& collider, std::pair<double, double> old_position) | 136 | void 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 | } |
