summary refs log tree commit diff stats
path: root/src/systems
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-04-21 14:50:52 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-04-21 14:50:52 -0400
commit8142a9c87a13cecc7a3698e877f24d89f128c074 (patch)
treecbee6ae85c5c674dd313c7cfe1420477ee55ca95 /src/systems
parent0f70db34d9b47de55b00c558ac3c445f30b7b6a5 (diff)
downloadtherapy-8142a9c87a13cecc7a3698e877f24d89f128c074.tar.gz
therapy-8142a9c87a13cecc7a3698e877f24d89f128c074.tar.bz2
therapy-8142a9c87a13cecc7a3698e877f24d89f128c074.zip
Started working on prototype objects proto-objs
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/mapping.cpp14
-rw-r--r--src/systems/playing.cpp33
-rw-r--r--src/systems/playing.h2
-rw-r--r--src/systems/pondering.cpp88
-rw-r--r--src/systems/pondering.h9
5 files changed, 139 insertions, 7 deletions
diff --git a/src/systems/mapping.cpp b/src/systems/mapping.cpp index a3a17ec..c7c2f9d 100644 --- a/src/systems/mapping.cpp +++ b/src/systems/mapping.cpp
@@ -195,4 +195,18 @@ void MappingSystem::loadMap(size_t mapId)
195 MappableComponent::Boundary::Type::danger); 195 MappableComponent::Boundary::Type::danger);
196 } 196 }
197 } 197 }
198
199 for (const Map::Object& object : map.getObjects())
200 {
201 const Prototype& prototype = game_.getPrototypeManager().
202 getPrototype(object.getType());
203
204 id_type emplacedObject = prototype.instantiate(
205 game_,
206 object.getX(),
207 object.getY(),
208 object.getItems());
209
210 mappable.getInstances()[object.getIndex()] = emplacedObject;
211 }
198} 212}
diff --git a/src/systems/playing.cpp b/src/systems/playing.cpp index 40d9706..5077f8a 100644 --- a/src/systems/playing.cpp +++ b/src/systems/playing.cpp
@@ -5,6 +5,7 @@
5#include "components/playable.h" 5#include "components/playable.h"
6#include "components/controllable.h" 6#include "components/controllable.h"
7#include "components/orientable.h" 7#include "components/orientable.h"
8#include "components/mappable.h"
8#include "systems/mapping.h" 9#include "systems/mapping.h"
9#include "systems/pondering.h" 10#include "systems/pondering.h"
10#include "systems/orienting.h" 11#include "systems/orienting.h"
@@ -84,7 +85,8 @@ void PlayingSystem::initPlayer()
84 85
85 game_.getSystemManager().getSystem<PonderingSystem>().initializeBody( 86 game_.getSystemManager().getSystem<PonderingSystem>().initializeBody(
86 player, 87 player,
87 PonderableComponent::Type::freefalling); 88 PonderableComponent::BodyType::freefalling,
89 PonderableComponent::ColliderType::player);
88 90
89 game_.getEntityManager().emplaceComponent<ControllableComponent>(player); 91 game_.getEntityManager().emplaceComponent<ControllableComponent>(player);
90 game_.getEntityManager().emplaceComponent<OrientableComponent>(player); 92 game_.getEntityManager().emplaceComponent<OrientableComponent>(player);
@@ -173,3 +175,32 @@ void PlayingSystem::die()
173 }); 175 });
174 } 176 }
175} 177}
178
179void PlayingSystem::save()
180{
181 playSound("res/Pickup_Coin23.wav", 0.25);
182
183 auto players = game_.getEntityManager().getEntitiesWithComponents<
184 TransformableComponent,
185 PlayableComponent>();
186
187 auto maps = game_.getEntityManager().getEntitiesWithComponents<
188 MappableComponent>();
189
190 auto& mappable = game_.getEntityManager().
191 getComponent<MappableComponent>(*maps.begin());
192
193 for (id_type player : players)
194 {
195 auto& transformable = game_.getEntityManager().
196 getComponent<TransformableComponent>(player);
197
198 auto& playable = game_.getEntityManager().
199 getComponent<PlayableComponent>(player);
200
201 playable.checkpointMapId = mappable.getMapId();
202 playable.checkpointX = transformable.getX();
203 playable.checkpointY = transformable.getY();
204 playable.checkpointObjectActivated = false;
205 }
206}
diff --git a/src/systems/playing.h b/src/systems/playing.h index ff16808..d7f5072 100644 --- a/src/systems/playing.h +++ b/src/systems/playing.h
@@ -23,6 +23,8 @@ public:
23 23
24 void die(); 24 void die();
25 25
26 void save();
27
26}; 28};
27 29
28#endif /* end of include guard: PLAYING_H_70A54F7D */ 30#endif /* end of include guard: PLAYING_H_70A54F7D */
diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 02d5cfc..9115988 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp
@@ -39,7 +39,7 @@ void PonderingSystem::tick(double dt)
39 ponderable.setVelocityY( 39 ponderable.setVelocityY(
40 ponderable.getVelocityY() + ponderable.getAccelY() * dt); 40 ponderable.getVelocityY() + ponderable.getAccelY() * dt);
41 41
42 if ((ponderable.getType() == PonderableComponent::Type::freefalling) 42 if ((ponderable.getBodyType() == PonderableComponent::BodyType::freefalling)
43 && (ponderable.getVelocityY() > TERMINAL_VELOCITY)) 43 && (ponderable.getVelocityY() > TERMINAL_VELOCITY))
44 { 44 {
45 ponderable.setVelocityY(TERMINAL_VELOCITY); 45 ponderable.setVelocityY(TERMINAL_VELOCITY);
@@ -58,7 +58,7 @@ void PonderingSystem::tick(double dt)
58 58
59 std::priority_queue<Collision> collisions; 59 std::priority_queue<Collision> collisions;
60 60
61 // Find collisions 61 // Find map collisions
62 for (id_type mapEntity : maps) 62 for (id_type mapEntity : maps)
63 { 63 {
64 auto& mappable = game_.getEntityManager(). 64 auto& mappable = game_.getEntityManager().
@@ -366,6 +366,51 @@ void PonderingSystem::tick(double dt)
366 } 366 }
367 } 367 }
368 368
369 // Find body collisions
370 for (id_type body : entities)
371 {
372 // Can't collide with self
373 if (body == entity)
374 {
375 continue;
376 }
377
378 // Make sure the body is collidable
379 auto& colliderPonderable =
380 game_.getEntityManager().getComponent<PonderableComponent>(body);
381
382 if (!colliderPonderable.isCollidable())
383 {
384 continue;
385 }
386
387 // Test if the body was already colliding
388 auto& colliderTransformable =
389 game_.getEntityManager().getComponent<TransformableComponent>(body);
390
391 if ((oldRight > colliderTransformable.getX())
392 && (oldX < colliderTransformable.getX() + colliderTransformable.getW())
393 && (oldBottom > colliderTransformable.getY())
394 && (oldY < colliderTransformable.getY() + colliderTransformable.getH()))
395 {
396 continue;
397 }
398
399 // Test if there is a new collision
400 if (!((newX + transformable.getW() > colliderTransformable.getX())
401 && (newX < colliderTransformable.getX() + colliderTransformable.getW())
402 && (newY + transformable.getH() > colliderTransformable.getY())
403 && (newY <
404 colliderTransformable.getY() + colliderTransformable.getH())))
405 {
406 continue;
407 }
408
409 // Process the collision
410 processBodyCollision(entity, body);
411 processBodyCollision(body, entity);
412 }
413
369 // Move 414 // Move
370 transformable.setX(newX); 415 transformable.setX(newX);
371 transformable.setY(newY); 416 transformable.setY(newY);
@@ -399,13 +444,46 @@ void PonderingSystem::tick(double dt)
399 444
400void PonderingSystem::initializeBody( 445void PonderingSystem::initializeBody(
401 id_type entity, 446 id_type entity,
402 PonderableComponent::Type type) 447 PonderableComponent::BodyType bodyType,
448 PonderableComponent::ColliderType colliderType)
403{ 449{
404 auto& ponderable = game_.getEntityManager(). 450 auto& ponderable = game_.getEntityManager().
405 emplaceComponent<PonderableComponent>(entity, type); 451 emplaceComponent<PonderableComponent>(entity, bodyType, colliderType);
406 452
407 if (type == PonderableComponent::Type::freefalling) 453 if (bodyType == PonderableComponent::BodyType::freefalling)
408 { 454 {
409 ponderable.setAccelY(NORMAL_GRAVITY); 455 ponderable.setAccelY(NORMAL_GRAVITY);
410 } 456 }
411} 457}
458
459void PonderingSystem::processBodyCollision(id_type body, id_type collider)
460{
461 auto& bodyPonderable = game_.getEntityManager().
462 getComponent<PonderableComponent>(body);
463
464 auto& colliderPonderable = game_.getEntityManager().
465 getComponent<PonderableComponent>(collider);
466
467 switch (colliderPonderable.getColliderType())
468 {
469 case PonderableComponent::ColliderType::event:
470 {
471 auto& callback = colliderPonderable.
472 getEventCallback(bodyPonderable.getColliderType());
473
474 if (callback)
475 {
476 callback(game_);
477 }
478
479 break;
480 }
481
482 default:
483 {
484 // Do nothing.
485
486 break;
487 }
488 }
489}
diff --git a/src/systems/pondering.h b/src/systems/pondering.h index d70525b..7e342df 100644 --- a/src/systems/pondering.h +++ b/src/systems/pondering.h
@@ -14,7 +14,14 @@ public:
14 14
15 void tick(double dt); 15 void tick(double dt);
16 16
17 void initializeBody(id_type entity, PonderableComponent::Type type); 17 void initializeBody(
18 id_type entity,
19 PonderableComponent::BodyType bodyType,
20 PonderableComponent::ColliderType colliderType);
21
22private:
23
24 void processBodyCollision(id_type body, id_type collider);
18 25
19}; 26};
20 27