Revision | 3b3df6e74988772308f46e5407407b22c12bae91 (tree) |
---|---|
Time | 2016-10-04 03:23:53 |
Author | sebastian_ <bugiu@head...> |
Commiter | sebastian_ |
Added gate control.
@@ -13,7 +13,12 @@ | ||
13 | 13 | bool collided = false; |
14 | 14 | |
15 | 15 | public: |
16 | - EventProperties(std::unique_ptr<GameEvent::Event> event_) : event(std::move(event_)) | |
16 | +// EventProperties(std::unique_ptr<GameEvent::Event> event_) : event(std::move(event_)) | |
17 | +// { | |
18 | +// | |
19 | +// } | |
20 | + | |
21 | + EventProperties(std::shared_ptr<GameEvent::Event> event_) : event(event_) | |
17 | 22 | { |
18 | 23 | |
19 | 24 | } |
@@ -169,9 +169,22 @@ | ||
169 | 169 | // We need the playerEntity to create the level. |
170 | 170 | auto currentLevelStr = std::string("lvl") + std::string(std::to_string(currentLevel)); |
171 | 171 | std::string levelImage = currentLevelStr + ".png"; |
172 | - std::string levelClc = currentLevelStr + "_map.clc"; | |
172 | + std::vector<std::string> clcs; | |
173 | + if (currentLevel == 6 || currentLevel == 8) | |
174 | + { | |
175 | + std::string levelClcClosed = currentLevelStr + "_map_closed.clc"; | |
176 | + std::string levelClcOpened = currentLevelStr + "_map_opened.clc"; | |
177 | + clcs.push_back(levelClcClosed); | |
178 | + clcs.push_back(levelClcOpened); | |
179 | + } | |
180 | + else | |
181 | + { | |
182 | + std::string levelClc = currentLevelStr + "_map.clc"; | |
183 | + clcs.push_back(levelClc); | |
184 | + } | |
185 | + | |
173 | 186 | std::string levelCfg = currentLevelStr + "_cfg"; |
174 | - auto levelPtr = loadLevel(levelImage, levelClc, levelCfg, *world, *this); | |
187 | + auto levelPtr = loadLevel(levelImage, clcs, levelCfg, *world, *this); | |
175 | 188 | |
176 | 189 | auto& level = world->createEntity(); |
177 | 190 | level.addComponent(new LevelProperties(levelPtr, halfVisibleSize)); |
@@ -1,9 +1,16 @@ | ||
1 | 1 | #include "GateChange.h" |
2 | 2 | |
3 | -GateChangeEvent::GateChangeEvent(artemis::World& world_): Event(world_) | |
3 | +GateChangeEvent::GateChangeEvent(artemis::World& world_, artemis::Entity& entity_, artemis::Entity& gateControlEntity_) | |
4 | + : GenericBitmapChangeEvent(world_, entity_), gateControlEntity(gateControlEntity_) | |
4 | 5 | { |
5 | 6 | } |
6 | 7 | |
7 | 8 | void GateChangeEvent::operator()() |
8 | 9 | { |
10 | +// auto eventProperties = eventPropertiesMapper.get(entity); | |
11 | + auto gateControlEventProperties = eventPropertiesMapper.get(gateControlEntity); | |
12 | + if (gateControlEventProperties->getEventDone()) | |
13 | + { | |
14 | + GenericBitmapChangeEvent::operator()(); | |
15 | + } | |
9 | 16 | } |
@@ -1,12 +1,14 @@ | ||
1 | 1 | #ifndef _GATE_CHANGE_H_ |
2 | 2 | #define _GATE_CHANGE_H_ |
3 | -#include "Event.h" | |
3 | +#include "GenericBitmapChange.h" | |
4 | 4 | |
5 | -class GateChangeEvent : public GameEvent::Event | |
5 | +class GateChangeEvent : public GenericBitmapChangeEvent | |
6 | 6 | { |
7 | +private: | |
8 | + artemis::Entity& gateControlEntity; | |
7 | 9 | public: |
8 | 10 | |
9 | - explicit GateChangeEvent(artemis::World& world_); | |
11 | + explicit GateChangeEvent(artemis::World& world_, artemis::Entity& entity_, artemis::Entity& gateControlEntity_); | |
10 | 12 | |
11 | 13 | void operator()() override; |
12 | 14 | }; |
@@ -1,11 +1,22 @@ | ||
1 | 1 | #include "GateControl.h" |
2 | 2 | |
3 | -GateControlEvent::GateControlEvent(artemis::World& world_) | |
4 | - : Event(world_) | |
3 | +GateControlEvent::GateControlEvent(artemis::World& world_, Level& level_, artemis::Entity& entity_) | |
4 | + : Event(world_), level(level_), entity(entity_) | |
5 | 5 | { |
6 | +// entityPropertiesMapper.init(world); | |
7 | + eventPropertiesMapper.init(world); | |
8 | +// timedEventPropertiesMapper.init(world); | |
6 | 9 | } |
7 | 10 | |
8 | 11 | void GateControlEvent::operator()() |
9 | 12 | { |
13 | +// auto entityProperties = entityPropertiesMapper.get(entity); | |
14 | + auto eventProperties = eventPropertiesMapper.get(entity); | |
15 | +// auto timedEventProperties = timedEventPropertiesMapper.get(entity); | |
10 | 16 | |
17 | + if (!eventProperties->getEventDone()) | |
18 | + { | |
19 | + level.setCurentCollisionSet(1); | |
20 | + eventProperties->setEventDone(true); | |
21 | + } | |
11 | 22 | } |
@@ -1,13 +1,22 @@ | ||
1 | 1 | #ifndef _GATE_CONTROL_H_ |
2 | 2 | #define _GATE_CONTROL_H_ |
3 | 3 | #include "Event.h" |
4 | -#include <memory> | |
4 | +#include "Level.h" | |
5 | +//#include "TimedEventProperties.h" | |
6 | +//#include "EntityProperties.h" | |
7 | +#include "EventProperties.h" | |
8 | +#include "artemis/src/Artemis/ComponentMapper.h" | |
5 | 9 | |
6 | 10 | class GateControlEvent : public GameEvent::Event |
7 | 11 | { |
8 | 12 | private: |
13 | + Level& level; | |
14 | + artemis::Entity& entity; | |
15 | +// artemis::ComponentMapper<EntityProperties> entityPropertiesMapper; | |
16 | + artemis::ComponentMapper<EventProperties> eventPropertiesMapper; | |
17 | +// artemis::ComponentMapper<TimedEventProperties> timedEventPropertiesMapper; | |
9 | 18 | public: |
10 | - explicit GateControlEvent(artemis::World& world_); | |
19 | + explicit GateControlEvent(artemis::World& world_, Level& level_, artemis::Entity& entity_); | |
11 | 20 | |
12 | 21 | void operator()() override; |
13 | 22 |
@@ -14,7 +14,7 @@ | ||
14 | 14 | |
15 | 15 | class GenericBitmapChangeEvent : public GameEvent::Event |
16 | 16 | { |
17 | -private: | |
17 | +protected: | |
18 | 18 | artemis::Entity& entity; |
19 | 19 | artemis::ComponentMapper<EntityProperties> entityPropertiesMapper; |
20 | 20 | artemis::ComponentMapper<EventProperties> eventPropertiesMapper; |
@@ -13,6 +13,7 @@ | ||
13 | 13 | #include "EventList.h" |
14 | 14 | #include "GenericBitmapChange.h" |
15 | 15 | #include "TimedEvent.h" |
16 | +#include "GateChange.h" | |
16 | 17 | |
17 | 18 | USING_NS_CC; |
18 | 19 |
@@ -132,7 +133,7 @@ | ||
132 | 133 | else |
133 | 134 | { |
134 | 135 | // We have a rotation in coords.y |
135 | - sprite->setRotation(coords.y); | |
136 | + sprite->setRotation(getRotationFromFileFormat(coords.y)); | |
136 | 137 | } |
137 | 138 | entity.addComponent(entityProperties); |
138 | 139 | auto powerupProperties = new PowerupProperties(type); |
@@ -188,6 +189,14 @@ | ||
188 | 189 | auto& entity = world.createEntity(); |
189 | 190 | auto entityProperties = new EntityProperties(*sprite); |
190 | 191 | entityProperties->setMapPos(Vec2(coords.x, coords.y)); |
192 | + if (vec.size() == 2) | |
193 | + { | |
194 | + if (vec[1].x == -1) | |
195 | + { | |
196 | + // We also have a rotation. | |
197 | + sprite->setRotation(getRotationFromFileFormat(vec[1].y)); | |
198 | + } | |
199 | + } | |
191 | 200 | entity.addComponent(entityProperties); |
192 | 201 | std::unique_ptr<GameEvent::Event> genericBitmapChange(new GenericBitmapChangeEvent(world, entity)); |
193 | 202 | std::unique_ptr<EventList> events(new EventList(world)); |
@@ -210,6 +219,71 @@ | ||
210 | 219 | return genericBitmapChangeList; |
211 | 220 | } |
212 | 221 | |
222 | +std::vector<std::reference_wrapper<artemis::Entity>> Level::createBoilerConsoleList() | |
223 | +{ | |
224 | + std::vector<std::reference_wrapper<artemis::Entity>> boilerAndConsoleList; | |
225 | + auto pair = coordsMap.find(BOILER_CONSOLE); | |
226 | + if (pair != coordsMap.end()) | |
227 | + { | |
228 | + | |
229 | + } | |
230 | + return boilerAndConsoleList; | |
231 | +} | |
232 | + | |
233 | +std::vector<std::reference_wrapper<artemis::Entity>> Level::createGateList() | |
234 | +{ | |
235 | + std::vector<std::reference_wrapper<artemis::Entity>> gateAndGateControlList; | |
236 | + auto pair = coordsMap.find(GATE); | |
237 | + if (pair != coordsMap.end()) | |
238 | + { | |
239 | + for (auto& vec : pair->second) | |
240 | + { | |
241 | + auto gatePosCoords = vec[0]; | |
242 | + auto gateControlPosCoords = vec[1]; | |
243 | + | |
244 | + auto gateSprite = Sprite::createWithSpriteFrameName("gate.png"); | |
245 | + auto& gateEntity = world.createEntity(); | |
246 | + auto gateEntityProperties = new EntityProperties(*gateSprite); | |
247 | + gateEntityProperties->setMapPos(Vec2(gatePosCoords.x, gatePosCoords.y)); | |
248 | + gateEntity.addComponent(gateEntityProperties); | |
249 | + | |
250 | + auto gateControlSprite = Sprite::createWithSpriteFrameName("gate_control.png"); | |
251 | + auto& gateControlEntity = world.createEntity(); | |
252 | + auto gateControlEntityProperties = new EntityProperties(*gateControlSprite); | |
253 | + gateControlEntityProperties->setMapPos(Vec2(gateControlPosCoords.x, gateControlPosCoords.y)); | |
254 | + gateControlEntity.addComponent(gateControlEntityProperties); | |
255 | + | |
256 | + std::shared_ptr<GameEvent::Event> gateBitmapChange(new GateChangeEvent(world, gateEntity, gateControlEntity)); | |
257 | + std::unique_ptr<GameEvent::Event> gateControlBitmapChange(new GenericBitmapChangeEvent(world, gateControlEntity)); | |
258 | + std::unique_ptr<EventList> events(new EventList(world)); | |
259 | + | |
260 | + events->addEvent(gateBitmapChange); | |
261 | + events->addEvent(std::move(gateControlBitmapChange)); | |
262 | + | |
263 | + std::unique_ptr<GameEvent::TimedEvent> timedEvent(new GameEvent::TimedEvent(world, gateEntity, std::move(events))); | |
264 | + | |
265 | + auto gateEventProperties = new EventProperties(gateBitmapChange); | |
266 | + auto gateTimedEventProperties = new TimedEventProperties(); | |
267 | + gateTimedEventProperties->setBrokenBitmap("gate_opened.png"); | |
268 | + gateEntity.addComponent(gateEventProperties); | |
269 | + gateEntity.addComponent(gateTimedEventProperties); | |
270 | + gateEntity.refresh(); | |
271 | + | |
272 | + auto gateControlEventProperties = new EventProperties(std::move(timedEvent)); | |
273 | + auto gateControlTimedEventProperties = new TimedEventProperties(); | |
274 | + gateControlTimedEventProperties->setTotalCollidingTime(1000); | |
275 | + gateControlTimedEventProperties->setBrokenBitmap("gate_control_opened.png"); | |
276 | + gateControlEntity.addComponent(gateControlEventProperties); | |
277 | + gateControlEntity.addComponent(gateControlTimedEventProperties); | |
278 | + gateControlEntity.refresh(); | |
279 | + | |
280 | + gateAndGateControlList.push_back(std::reference_wrapper<artemis::Entity>(gateEntity)); | |
281 | + gateAndGateControlList.push_back(std::reference_wrapper<artemis::Entity>(gateControlEntity)); | |
282 | + } | |
283 | + } | |
284 | + return gateAndGateControlList; | |
285 | +} | |
286 | + | |
213 | 287 | void Level::extractBeginAndEndPositions() |
214 | 288 | { |
215 | 289 | auto beginningPosCoords = coordsMap.find(BEGINNING_POS)->second[0][0]; |
@@ -232,6 +306,8 @@ | ||
232 | 306 | auto assemblyLineList = createGenericBitmapChangeList(ASSEMBLY_); |
233 | 307 | auto waterCollerList = createGenericBitmapChangeList(WATER_COOLER_); |
234 | 308 | |
309 | + auto gateAndGateControlList = createGateList(); | |
310 | + | |
235 | 311 | addToScene(fileList); |
236 | 312 | addToScene(foodList); |
237 | 313 | addToScene(pinkSlipList); |
@@ -244,6 +320,8 @@ | ||
244 | 320 | addToScene(assemblyLineList); |
245 | 321 | addToScene(waterCollerList); |
246 | 322 | |
323 | + addToScene(gateAndGateControlList); | |
324 | + | |
247 | 325 | extractBeginAndEndPositions(); |
248 | 326 | |
249 | 327 | auto endConditions = coordsMap.find(COND_END)->second[0]; |
@@ -261,8 +339,8 @@ | ||
261 | 339 | } |
262 | 340 | } |
263 | 341 | |
264 | -Level::Level(cocos2d::Sprite& _map, CollisionSet _collisionSet, CoordsMap _coordsMap, artemis::World& world_, GameScene& gameScene_) : | |
265 | - map(_map), collisionSet(std::move(_collisionSet)), coordsMap(std::move(_coordsMap)), world(world_), gameScene(gameScene_) | |
342 | +Level::Level(cocos2d::Sprite& _map, std::vector<CollisionSet> collisionSetList_, CoordsMap _coordsMap, artemis::World& world_, GameScene& gameScene_) : | |
343 | + map(_map), collisionSetList(std::move(collisionSetList_)), coordsMap(std::move(_coordsMap)), world(world_), gameScene(gameScene_) | |
266 | 344 | { |
267 | 345 | extractDataFromCoordsMap(); |
268 | 346 |
@@ -282,8 +360,8 @@ | ||
282 | 360 | unsigned int currentBottom = ((short)currentX) << 16 | ((short)rightLowerCorner.y); |
283 | 361 | for (unsigned int i = 0; i < iterCount; ++i) |
284 | 362 | { |
285 | - CollisionSet::iterator xy1It = collisionSet.lower_bound(currentTop); | |
286 | - CollisionSet::iterator xy2It = collisionSet.upper_bound(currentBottom); | |
363 | + CollisionSet::iterator xy1It = collisionSetList[curentCollisionSet].lower_bound(currentTop); | |
364 | + CollisionSet::iterator xy2It = collisionSetList[curentCollisionSet].upper_bound(currentBottom); | |
287 | 365 | |
288 | 366 | unsigned int leftX = (*xy1It) >> 16; |
289 | 367 | unsigned int leftY = (*xy1It) & 0xffff; |
@@ -444,18 +522,25 @@ | ||
444 | 522 | return false; |
445 | 523 | } |
446 | 524 | |
447 | -LevelPtr loadLevel(std::string levelFile, std::string levelCollisionDataFile, std::string levelConfig, artemis::World& world, GameScene& gameScene) | |
525 | +LevelPtr loadLevel(std::string levelFile, std::vector<std::string> clcs, std::string levelConfig, artemis::World& world, GameScene& gameScene) | |
448 | 526 | { |
449 | 527 | auto mapSprite = Sprite::create(levelFile); |
450 | 528 | |
451 | - CollisionSet collisionSet; | |
529 | + std::vector<CollisionSet> collisionSetList; | |
530 | + | |
452 | 531 | LevelPtr value1; |
453 | - if (getLevelCollisionData(levelCollisionDataFile, collisionSet, value1)) return value1; | |
532 | + for (auto& levelCollisionDataFile : clcs) | |
533 | + { | |
534 | + CollisionSet collisionSet; | |
535 | + if (getLevelCollisionData(levelCollisionDataFile, collisionSet, value1)) return value1; | |
536 | + collisionSetList.push_back(std::move(collisionSet)); | |
537 | + } | |
538 | + | |
454 | 539 | |
455 | 540 | CoordsMap coordsMap; |
456 | 541 | if (getLevelConfig(levelConfig, coordsMap, value1)) return value1; |
457 | 542 | |
458 | - LevelPtr levelPtr(new Level(*mapSprite, collisionSet, coordsMap, world, gameScene)); | |
543 | + LevelPtr levelPtr(new Level(*mapSprite, collisionSetList, coordsMap, world, gameScene)); | |
459 | 544 | |
460 | 545 | return levelPtr; |
461 | 546 | } |
@@ -49,7 +49,7 @@ | ||
49 | 49 | |
50 | 50 | enum GenericBitmapEventType |
51 | 51 | { |
52 | - ASSEMBLY_, WATER_COOLER_ | |
52 | + ASSEMBLY_, WATER_COOLER_, BOILER_CONSOLE_, GATE_ | |
53 | 53 | }; |
54 | 54 | |
55 | 55 | class Level |
@@ -58,6 +58,8 @@ | ||
58 | 58 | GameScene& gameScene; |
59 | 59 | cocos2d::Sprite& map; |
60 | 60 | CollisionSet collisionSet; |
61 | + std::vector<CollisionSet> collisionSetList; | |
62 | + unsigned int curentCollisionSet = 0; | |
61 | 63 | CoordsMap coordsMap; |
62 | 64 | artemis::World& world; |
63 | 65 | cocos2d::Vec2 beginningPos; |
@@ -68,13 +70,15 @@ | ||
68 | 70 | std::vector<std::reference_wrapper<artemis::Entity>> createWorkerList(WorkerType type); |
69 | 71 | std::vector<std::reference_wrapper<artemis::Entity>> createPowerupList(PowerupType type); |
70 | 72 | std::vector<std::reference_wrapper<artemis::Entity>> createGenericBitmapChangeList(GenericBitmapEventType type); |
73 | + std::vector<std::reference_wrapper<artemis::Entity>> createBoilerConsoleList(); | |
74 | + std::vector<std::reference_wrapper<artemis::Entity>> createGateList(); | |
71 | 75 | void extractBeginAndEndPositions(); |
72 | 76 | void extractDataFromCoordsMap(); |
73 | 77 | void addToScene(std::vector<std::reference_wrapper<artemis::Entity>>& spriteList); |
74 | 78 | |
75 | 79 | public: |
76 | 80 | |
77 | - Level(cocos2d::Sprite& map, CollisionSet _collisionSet, CoordsMap coordsMap, artemis::World& world, GameScene& gameScene); | |
81 | + Level(cocos2d::Sprite& map, std::vector<CollisionSet> collisionSetList_, CoordsMap coordsMap, artemis::World& world, GameScene& gameScene); | |
78 | 82 | |
79 | 83 | bool checkCollisionCoarse(const cocos2d::Vec2& leftUpperCorner, const cocos2d::Vec2& rightLowerCorner); |
80 | 84 |
@@ -110,12 +114,23 @@ | ||
110 | 114 | { |
111 | 115 | return endCondition; |
112 | 116 | } |
117 | + | |
118 | + | |
119 | + unsigned getCurentCollisionSet() const | |
120 | + { | |
121 | + return curentCollisionSet; | |
122 | + } | |
123 | + | |
124 | + void setCurentCollisionSet(const unsigned curent_collision_set) | |
125 | + { | |
126 | + curentCollisionSet = curent_collision_set; | |
127 | + } | |
113 | 128 | }; |
114 | 129 | |
115 | 130 | typedef std::unique_ptr<Level> LevelPtr; |
116 | 131 | typedef std::shared_ptr<Level> LevelPtrShared; |
117 | 132 | |
118 | -LevelPtr loadLevel(std::string levelFile, std::string levelCollisionDataFile, std::string levelConfig, artemis::World& world, GameScene& gameScene); | |
133 | +LevelPtr loadLevel(std::string levelFile, std::vector<std::string> clcs, std::string levelConfig, artemis::World& world, GameScene& gameScene); | |
119 | 134 | |
120 | 135 | #endif |
121 | 136 |
@@ -20,7 +20,7 @@ | ||
20 | 20 | labelMainMenu->setPosition(getMenuTitlePosition(*labelMainMenu)); |
21 | 21 | addChild(labelMainMenu, 1); |
22 | 22 | |
23 | - int maxLevelReached = getMaxLevelReached(); | |
23 | + int maxLevelReached = 8;// getMaxLevelReached(); | |
24 | 24 | std::vector<std::string> titleList; |
25 | 25 | int titleStart = FIRST_LEVEL; |
26 | 26 | for (int i = 0; i < maxLevelReached; ++i) |
@@ -59,3 +59,19 @@ | ||
59 | 59 | { |
60 | 60 | return pre + " x: " + std::to_string(vec.x) + " y: " + std::to_string(vec.y); |
61 | 61 | } |
62 | + | |
63 | +float getRotationFromFileFormat(int rotation) | |
64 | +{ | |
65 | + switch (rotation) | |
66 | + { | |
67 | + case 0: | |
68 | + return 0.0f; | |
69 | + case 1: | |
70 | + return 90.0f; | |
71 | + case 2: | |
72 | + return 180.0f; | |
73 | + case 3: | |
74 | + return 270.0f; | |
75 | + } | |
76 | + return 0.0f; | |
77 | +} |
@@ -38,5 +38,7 @@ | ||
38 | 38 | |
39 | 39 | std::string toString(Vec2 vec, std::string pre); |
40 | 40 | |
41 | +float getRotationFromFileFormat(int rotation); | |
42 | + | |
41 | 43 | #endif |
42 | 44 |