diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-13 14:02:07 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-13 14:02:07 -0400 |
| commit | bdf50ff543c73c83cc7a06426bc2a6fe66616b87 (patch) | |
| tree | 6d789280fa0829ec32cc37ce73a2773d4a5cd9d1 /src | |
| parent | 9cf2d327476d00b696254b170c03dd6b8548e1d0 (diff) | |
| download | therapy-bdf50ff543c73c83cc7a06426bc2a6fe66616b87.tar.gz therapy-bdf50ff543c73c83cc7a06426bc2a6fe66616b87.tar.bz2 therapy-bdf50ff543c73c83cc7a06426bc2a6fe66616b87.zip | |
Added a checkpoint
Diffstat (limited to 'src')
| -rw-r--r-- | src/components.cpp | 27 | ||||
| -rw-r--r-- | src/components.h | 18 | ||||
| -rw-r--r-- | src/game.cpp | 23 |
3 files changed, 68 insertions, 0 deletions
| diff --git a/src/components.cpp b/src/components.cpp index 5f67934..26aa5d2 100644 --- a/src/components.cpp +++ b/src/components.cpp | |||
| @@ -585,3 +585,30 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli | |||
| 585 | 585 | ||
| 586 | return false; | 586 | return false; |
| 587 | } | 587 | } |
| 588 | |||
| 589 | // Static image | ||
| 590 | |||
| 591 | StaticImageComponent::StaticImageComponent(const char* filename) : sprite(Texture(filename)) | ||
| 592 | { | ||
| 593 | |||
| 594 | } | ||
| 595 | |||
| 596 | void StaticImageComponent::render(Game&, Entity& entity, Texture& buffer) | ||
| 597 | { | ||
| 598 | buffer.blit(sprite, sprite.entirety(), {(int) entity.position.first, (int) entity.position.second, entity.size.first, entity.size.second}); | ||
| 599 | } | ||
| 600 | |||
| 601 | // Simple collision | ||
| 602 | |||
| 603 | SimpleColliderComponent::SimpleColliderComponent(std::function<void (Entity& collider)> callback) : callback(callback) | ||
| 604 | { | ||
| 605 | |||
| 606 | } | ||
| 607 | |||
| 608 | void SimpleColliderComponent::receive(Game&, Entity&, const Message& msg) | ||
| 609 | { | ||
| 610 | if (msg.type == Message::Type::collision) | ||
| 611 | { | ||
| 612 | callback(*(msg.collisionEntity)); | ||
| 613 | } | ||
| 614 | } | ||
| diff --git a/src/components.h b/src/components.h index c66db47..f5c66d4 100644 --- a/src/components.h +++ b/src/components.h | |||
| @@ -100,4 +100,22 @@ class MapCollisionComponent : public Component { | |||
| 100 | const Map& map; | 100 | const Map& map; |
| 101 | }; | 101 | }; |
| 102 | 102 | ||
| 103 | class StaticImageComponent : public Component { | ||
| 104 | public: | ||
| 105 | StaticImageComponent(const char* filename); | ||
| 106 | void render(Game& game, Entity& entity, Texture& buffer); | ||
| 107 | |||
| 108 | private: | ||
| 109 | Texture sprite; | ||
| 110 | }; | ||
| 111 | |||
| 112 | class SimpleColliderComponent : public Component { | ||
| 113 | public: | ||
| 114 | SimpleColliderComponent(std::function<void (Entity& collider)> callback); | ||
| 115 | void receive(Game& game, Entity& entity, const Message& msg); | ||
| 116 | |||
| 117 | private: | ||
| 118 | std::function<void (Entity& collider)> callback; | ||
| 119 | }; | ||
| 120 | |||
| 103 | #endif | 121 | #endif |
| diff --git a/src/game.cpp b/src/game.cpp index a494c5f..e2c1b9c 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
| @@ -120,6 +120,29 @@ void Game::loadMap(const Map& map) | |||
| 120 | nextEntities.push_back(mapEn); | 120 | nextEntities.push_back(mapEn); |
| 121 | nextEntities.push_back(player); | 121 | nextEntities.push_back(player); |
| 122 | 122 | ||
| 123 | // this is cheating but is just for testing | ||
| 124 | if (&map == &m2) | ||
| 125 | { | ||
| 126 | auto saveEn = std::make_shared<Entity>(); | ||
| 127 | saveEn->position = std::make_pair(257.0, 160.0); | ||
| 128 | saveEn->size = std::make_pair(8.0, 11.0); | ||
| 129 | |||
| 130 | auto save_render = std::make_shared<StaticImageComponent>("../res/keyring.png"); | ||
| 131 | saveEn->addComponent(save_render); | ||
| 132 | |||
| 133 | auto save_physics = std::make_shared<PhysicsBodyComponent>(); | ||
| 134 | saveEn->addComponent(save_physics); | ||
| 135 | |||
| 136 | auto save_collide = std::make_shared<SimpleColliderComponent>([&] (Entity& collider) { | ||
| 137 | playSound("../res/Pickup_Coin23.wav", 0.25); | ||
| 138 | |||
| 139 | saveGame(map, collider.position); | ||
| 140 | }); | ||
| 141 | saveEn->addComponent(save_collide); | ||
| 142 | |||
| 143 | nextEntities.push_back(saveEn); | ||
| 144 | } | ||
| 145 | |||
| 123 | newWorld = true; | 146 | newWorld = true; |
| 124 | } | 147 | } |
| 125 | 148 | ||
