diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-17 15:55:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-17 15:55:37 -0400 |
| commit | 90aadf3844386824140a20d7fbb847bc16009a94 (patch) | |
| tree | 6f83fce90e71abb22b1a8f3e09c79963b2a34d5d /src/systems/controlling.cpp | |
| parent | bc63fa57ced1c7329f7fdcfd168eaf7e290158bc (diff) | |
| parent | 86f0106d0523825549f1e74b835688c78a10cf6c (diff) | |
| download | therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.gz therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.bz2 therapy-90aadf3844386824140a20d7fbb847bc16009a94.zip | |
Merge pull request #7 from hatkirby/es-rewrite
The ECS rewrite exceeds the original branch in functionality, so it is time to merge it in.
Diffstat (limited to 'src/systems/controlling.cpp')
| -rw-r--r-- | src/systems/controlling.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
| diff --git a/src/systems/controlling.cpp b/src/systems/controlling.cpp new file mode 100644 index 0000000..e65c09a --- /dev/null +++ b/src/systems/controlling.cpp | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | #include "controlling.h" | ||
| 2 | #include "game.h" | ||
| 3 | #include "components/controllable.h" | ||
| 4 | #include "components/orientable.h" | ||
| 5 | #include "systems/orienting.h" | ||
| 6 | |||
| 7 | void ControllingSystem::tick(double) | ||
| 8 | { | ||
| 9 | while (!actions_.empty()) | ||
| 10 | { | ||
| 11 | int key = actions_.front().first; | ||
| 12 | int action = actions_.front().second; | ||
| 13 | |||
| 14 | auto entities = game_.getEntityManager().getEntitiesWithComponents< | ||
| 15 | ControllableComponent, | ||
| 16 | OrientableComponent>(); | ||
| 17 | |||
| 18 | for (auto entity : entities) | ||
| 19 | { | ||
| 20 | auto& controllable = game_.getEntityManager(). | ||
| 21 | getComponent<ControllableComponent>(entity); | ||
| 22 | |||
| 23 | auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>(); | ||
| 24 | |||
| 25 | if (action == GLFW_PRESS) | ||
| 26 | { | ||
| 27 | if (key == controllable.getLeftKey()) | ||
| 28 | { | ||
| 29 | controllable.setHoldingLeft(true); | ||
| 30 | |||
| 31 | if (!controllable.isFrozen()) | ||
| 32 | { | ||
| 33 | orienting.moveLeft(entity); | ||
| 34 | } | ||
| 35 | } else if (key == controllable.getRightKey()) | ||
| 36 | { | ||
| 37 | controllable.setHoldingRight(true); | ||
| 38 | |||
| 39 | if (!controllable.isFrozen()) | ||
| 40 | { | ||
| 41 | orienting.moveRight(entity); | ||
| 42 | } | ||
| 43 | } else if (key == controllable.getJumpKey()) | ||
| 44 | { | ||
| 45 | if (!controllable.isFrozen()) | ||
| 46 | { | ||
| 47 | orienting.jump(entity); | ||
| 48 | } | ||
| 49 | } else if (key == controllable.getDropKey()) | ||
| 50 | { | ||
| 51 | if (!controllable.isFrozen()) | ||
| 52 | { | ||
| 53 | orienting.drop(entity); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } else if (action == GLFW_RELEASE) | ||
| 57 | { | ||
| 58 | if (key == controllable.getLeftKey()) | ||
| 59 | { | ||
| 60 | controllable.setHoldingLeft(false); | ||
| 61 | |||
| 62 | if (!controllable.isFrozen()) | ||
| 63 | { | ||
| 64 | if (controllable.isHoldingRight()) | ||
| 65 | { | ||
| 66 | orienting.moveRight(entity); | ||
| 67 | } else { | ||
| 68 | orienting.stopWalking(entity); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } else if (key == controllable.getRightKey()) | ||
| 72 | { | ||
| 73 | controllable.setHoldingRight(false); | ||
| 74 | |||
| 75 | if (!controllable.isFrozen()) | ||
| 76 | { | ||
| 77 | if (controllable.isHoldingLeft()) | ||
| 78 | { | ||
| 79 | orienting.moveLeft(entity); | ||
| 80 | } else { | ||
| 81 | orienting.stopWalking(entity); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } else if (key == controllable.getDropKey()) | ||
| 85 | { | ||
| 86 | if (!controllable.isFrozen()) | ||
| 87 | { | ||
| 88 | orienting.stopDropping(entity); | ||
| 89 | } | ||
| 90 | } else if (key == controllable.getJumpKey()) | ||
| 91 | { | ||
| 92 | if (!controllable.isFrozen()) | ||
| 93 | { | ||
| 94 | orienting.stopJumping(entity); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | actions_.pop(); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | void ControllingSystem::input(int key, int action) | ||
| 105 | { | ||
| 106 | actions_.push(std::make_pair(key, action)); | ||
| 107 | } | ||
| 108 | |||
| 109 | void ControllingSystem::freeze(id_type entity) | ||
| 110 | { | ||
| 111 | auto& controllable = game_.getEntityManager(). | ||
| 112 | getComponent<ControllableComponent>(entity); | ||
| 113 | |||
| 114 | controllable.setFrozen(true); | ||
| 115 | } | ||
| 116 | |||
| 117 | void ControllingSystem::unfreeze(id_type entity) | ||
| 118 | { | ||
| 119 | auto& controllable = game_.getEntityManager(). | ||
| 120 | getComponent<ControllableComponent>(entity); | ||
| 121 | |||
| 122 | if (controllable.isFrozen()) | ||
| 123 | { | ||
| 124 | controllable.setFrozen(false); | ||
| 125 | |||
| 126 | auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>(); | ||
| 127 | |||
| 128 | if (controllable.isHoldingLeft()) | ||
| 129 | { | ||
| 130 | orienting.moveLeft(entity); | ||
| 131 | } else if (controllable.isHoldingRight()) | ||
| 132 | { | ||
| 133 | orienting.moveRight(entity); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | } | ||
