summary refs log tree commit diff stats
path: root/src/game.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 16:13:11 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 16:13:11 -0400
commit44324ba5d6cac01048cc5cbecbff255ee56f2fc0 (patch)
tree63e859067d214bfccf1d75520e1cedece0e91963 /src/game.cpp
parent5990e7802c84b3f407de3934a1d75721115d1da7 (diff)
downloadtherapy-44324ba5d6cac01048cc5cbecbff255ee56f2fc0.tar.gz
therapy-44324ba5d6cac01048cc5cbecbff255ee56f2fc0.tar.bz2
therapy-44324ba5d6cac01048cc5cbecbff255ee56f2fc0.zip
Wrote simple factory to read map and entity data from XML files
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp34
1 files changed, 5 insertions, 29 deletions
diff --git a/src/game.cpp b/src/game.cpp index b149392..7ec4460 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -2,12 +2,10 @@
2#include "renderer.h" 2#include "renderer.h"
3#include "components.h" 3#include "components.h"
4#include "muxer.h" 4#include "muxer.h"
5#include "entityfactory.h"
5 6
6Game::Game() 7Game::Game()
7{ 8{
8 m.setLeftMap(&m2);
9 m2.setRightMap(&m);
10
11 player = std::make_shared<Entity>(); 9 player = std::make_shared<Entity>();
12 player->position = std::make_pair(100.0,100.0); 10 player->position = std::make_pair(100.0,100.0);
13 player->size = std::make_pair(10.0,12.0); 11 player->size = std::make_pair(10.0,12.0);
@@ -116,32 +114,10 @@ void Game::loadMap(const Map& map)
116 auto map_collision = std::make_shared<MapCollisionComponent>(map); 114 auto map_collision = std::make_shared<MapCollisionComponent>(map);
117 mapEn->addComponent(map_collision); 115 mapEn->addComponent(map_collision);
118 116
117 // Map in the back, player on top, rest of entities in between
119 nextEntities.clear(); 118 nextEntities.clear();
120 nextEntities.push_back(mapEn); 119 nextEntities.push_back(mapEn);
121 120 map.createEntities(nextEntities);
122 // this is cheating but is just for testing
123 if (&map == &m2)
124 {
125 auto saveEn = std::make_shared<Entity>();
126 saveEn->position = std::make_pair(257.0, 160.0);
127 saveEn->size = std::make_pair(8.0, 11.0);
128
129 auto save_render = std::make_shared<StaticImageComponent>("../res/keyring.png");
130 saveEn->addComponent(save_render);
131
132 auto save_physics = std::make_shared<PhysicsBodyComponent>();
133 saveEn->addComponent(save_physics);
134
135 auto save_collide = std::make_shared<SimpleColliderComponent>([&] (Entity& collider) {
136 playSound("../res/Pickup_Coin23.wav", 0.25);
137
138 saveGame(map, collider.position);
139 });
140 saveEn->addComponent(save_collide);
141
142 nextEntities.push_back(saveEn);
143 }
144
145 nextEntities.push_back(player); 121 nextEntities.push_back(player);
146 122
147 newWorld = true; 123 newWorld = true;
@@ -160,9 +136,9 @@ void Game::saveGame(const Map& map, std::pair<double, double> position)
160 save = {&map, position}; 136 save = {&map, position};
161} 137}
162 138
163void Game::schedule(double time, std::function<void ()>&& callback) 139void Game::schedule(double time, std::function<void ()> callback)
164{ 140{
165 scheduled.emplace_front(time, callback); 141 scheduled.emplace_front(time, std::move(callback));
166} 142}
167 143
168void Game::playerDie(Entity& player, const Map& curMap) 144void Game::playerDie(Entity& player, const Map& curMap)