diff options
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/controlling.cpp | 129 | ||||
| -rw-r--r-- | src/systems/controlling.h | 8 | ||||
| -rw-r--r-- | src/systems/mapping.cpp | 2 | ||||
| -rw-r--r-- | src/systems/orienting.cpp | 236 | ||||
| -rw-r--r-- | src/systems/orienting.h | 35 | ||||
| -rw-r--r-- | src/systems/pondering.cpp | 89 |
6 files changed, 332 insertions, 167 deletions
| diff --git a/src/systems/controlling.cpp b/src/systems/controlling.cpp index fa09d11..e1609bd 100644 --- a/src/systems/controlling.cpp +++ b/src/systems/controlling.cpp | |||
| @@ -1,14 +1,8 @@ | |||
| 1 | #include "controlling.h" | 1 | #include "controlling.h" |
| 2 | #include "game.h" | 2 | #include "game.h" |
| 3 | #include "components/controllable.h" | 3 | #include "components/controllable.h" |
| 4 | #include "components/ponderable.h" | ||
| 5 | #include "components/animatable.h" | ||
| 6 | #include "components/droppable.h" | ||
| 7 | #include "components/orientable.h" | 4 | #include "components/orientable.h" |
| 8 | #include "systems/animating.h" | 5 | #include "systems/orienting.h" |
| 9 | #include "direction.h" | ||
| 10 | #include "muxer.h" | ||
| 11 | #include "consts.h" | ||
| 12 | 6 | ||
| 13 | void ControllingSystem::tick(double) | 7 | void ControllingSystem::tick(double) |
| 14 | { | 8 | { |
| @@ -19,9 +13,6 @@ void ControllingSystem::tick(double) | |||
| 19 | 13 | ||
| 20 | auto entities = game_.getEntityManager().getEntitiesWithComponents< | 14 | auto entities = game_.getEntityManager().getEntitiesWithComponents< |
| 21 | ControllableComponent, | 15 | ControllableComponent, |
| 22 | PonderableComponent, | ||
| 23 | AnimatableComponent, | ||
| 24 | DroppableComponent, | ||
| 25 | OrientableComponent>(); | 16 | OrientableComponent>(); |
| 26 | 17 | ||
| 27 | for (auto entity : entities) | 18 | for (auto entity : entities) |
| @@ -29,6 +20,8 @@ void ControllingSystem::tick(double) | |||
| 29 | auto& controllable = game_.getEntityManager(). | 20 | auto& controllable = game_.getEntityManager(). |
| 30 | getComponent<ControllableComponent>(entity); | 21 | getComponent<ControllableComponent>(entity); |
| 31 | 22 | ||
| 23 | auto& orienting = game_.getSystemManager().getSystem<OrientingSystem>(); | ||
| 24 | |||
| 32 | if (action == GLFW_PRESS) | 25 | if (action == GLFW_PRESS) |
| 33 | { | 26 | { |
| 34 | if (key == controllable.getLeftKey()) | 27 | if (key == controllable.getLeftKey()) |
| @@ -37,7 +30,7 @@ void ControllingSystem::tick(double) | |||
| 37 | 30 | ||
| 38 | if (!controllable.isFrozen()) | 31 | if (!controllable.isFrozen()) |
| 39 | { | 32 | { |
| 40 | walkLeft(entity); | 33 | orienting.moveLeft(entity); |
| 41 | } | 34 | } |
| 42 | } else if (key == controllable.getRightKey()) | 35 | } else if (key == controllable.getRightKey()) |
| 43 | { | 36 | { |
| @@ -45,19 +38,19 @@ void ControllingSystem::tick(double) | |||
| 45 | 38 | ||
| 46 | if (!controllable.isFrozen()) | 39 | if (!controllable.isFrozen()) |
| 47 | { | 40 | { |
| 48 | walkRight(entity); | 41 | orienting.moveRight(entity); |
| 49 | } | 42 | } |
| 50 | } else if (key == controllable.getJumpKey()) | 43 | } else if (key == controllable.getJumpKey()) |
| 51 | { | 44 | { |
| 52 | if (!controllable.isFrozen()) | 45 | if (!controllable.isFrozen()) |
| 53 | { | 46 | { |
| 54 | jump(entity); | 47 | orienting.jump(entity); |
| 55 | } | 48 | } |
| 56 | } else if (key == controllable.getDropKey()) | 49 | } else if (key == controllable.getDropKey()) |
| 57 | { | 50 | { |
| 58 | if (!controllable.isFrozen()) | 51 | if (!controllable.isFrozen()) |
| 59 | { | 52 | { |
| 60 | drop(entity, true); | 53 | orienting.drop(entity); |
| 61 | } | 54 | } |
| 62 | } | 55 | } |
| 63 | } else if (action == GLFW_RELEASE) | 56 | } else if (action == GLFW_RELEASE) |
| @@ -70,9 +63,9 @@ void ControllingSystem::tick(double) | |||
| 70 | { | 63 | { |
| 71 | if (controllable.isHoldingRight()) | 64 | if (controllable.isHoldingRight()) |
| 72 | { | 65 | { |
| 73 | walkRight(entity); | 66 | orienting.moveRight(entity); |
| 74 | } else { | 67 | } else { |
| 75 | stopWalking(entity); | 68 | orienting.stopWalking(entity); |
| 76 | } | 69 | } |
| 77 | } | 70 | } |
| 78 | } else if (key == controllable.getRightKey()) | 71 | } else if (key == controllable.getRightKey()) |
| @@ -83,22 +76,22 @@ void ControllingSystem::tick(double) | |||
| 83 | { | 76 | { |
| 84 | if (controllable.isHoldingLeft()) | 77 | if (controllable.isHoldingLeft()) |
| 85 | { | 78 | { |
| 86 | walkLeft(entity); | 79 | orienting.moveLeft(entity); |
| 87 | } else { | 80 | } else { |
| 88 | stopWalking(entity); | 81 | orienting.stopWalking(entity); |
| 89 | } | 82 | } |
| 90 | } | 83 | } |
| 91 | } else if (key == controllable.getDropKey()) | 84 | } else if (key == controllable.getDropKey()) |
| 92 | { | 85 | { |
| 93 | if (!controllable.isFrozen()) | 86 | if (!controllable.isFrozen()) |
| 94 | { | 87 | { |
| 95 | drop(entity, false); | 88 | orienting.stopDropping(entity); |
| 96 | } | 89 | } |
| 97 | } else if (key == controllable.getJumpKey()) | 90 | } else if (key == controllable.getJumpKey()) |
| 98 | { | 91 | { |
| 99 | if (!controllable.isFrozen()) | 92 | if (!controllable.isFrozen()) |
| 100 | { | 93 | { |
| 101 | stopJumping(entity); | 94 | orienting.stopJumping(entity); |
| 102 | } | 95 | } |
| 103 | } | 96 | } |
| 104 | } | 97 | } |
| @@ -112,99 +105,3 @@ void ControllingSystem::input(int key, int action) | |||
| 112 | { | 105 | { |
| 113 | actions_.push(std::make_pair(key, action)); | 106 | actions_.push(std::make_pair(key, action)); |
| 114 | } | 107 | } |
| 115 | |||
| 116 | void ControllingSystem::walkLeft(id_type entity) | ||
| 117 | { | ||
| 118 | auto& ponderable = game_.getEntityManager().getComponent<PonderableComponent>(entity); | ||
| 119 | auto& orientable = game_.getEntityManager().getComponent<OrientableComponent>(entity); | ||
| 120 | |||
| 121 | orientable.setFacingRight(false); | ||
| 122 | ponderable.setVelocityX(-90); | ||
| 123 | |||
| 124 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 125 | |||
| 126 | if (ponderable.getState() == PonderableComponent::State::grounded) | ||
| 127 | { | ||
| 128 | animating.startAnimation(entity, "walkingLeft"); | ||
| 129 | } else { | ||
| 130 | animating.startAnimation(entity, "stillLeft"); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | void ControllingSystem::walkRight(id_type entity) | ||
| 135 | { | ||
| 136 | auto& ponderable = game_.getEntityManager().getComponent<PonderableComponent>(entity); | ||
| 137 | auto& orientable = game_.getEntityManager().getComponent<OrientableComponent>(entity); | ||
| 138 | |||
| 139 | orientable.setFacingRight(true); | ||
| 140 | ponderable.setVelocityX(90); | ||
| 141 | |||
| 142 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 143 | |||
| 144 | if (ponderable.getState() == PonderableComponent::State::grounded) | ||
| 145 | { | ||
| 146 | animating.startAnimation(entity, "walkingRight"); | ||
| 147 | } else { | ||
| 148 | animating.startAnimation(entity, "stillRight"); | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | void ControllingSystem::stopWalking(id_type entity) | ||
| 153 | { | ||
| 154 | auto& ponderable = game_.getEntityManager().getComponent<PonderableComponent>(entity); | ||
| 155 | auto& orientable = game_.getEntityManager().getComponent<OrientableComponent>(entity); | ||
| 156 | |||
| 157 | ponderable.setVelocityX(0); | ||
| 158 | |||
| 159 | if (ponderable.getState() == PonderableComponent::State::grounded) | ||
| 160 | { | ||
| 161 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 162 | |||
| 163 | if (orientable.isFacingRight()) | ||
| 164 | { | ||
| 165 | animating.startAnimation(entity, "stillRight"); | ||
| 166 | } else { | ||
| 167 | animating.startAnimation(entity, "stillLeft"); | ||
| 168 | } | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | void ControllingSystem::jump(id_type entity) | ||
| 173 | { | ||
| 174 | auto& ponderable = game_.getEntityManager().getComponent<PonderableComponent>(entity); | ||
| 175 | |||
| 176 | if (ponderable.getState() == PonderableComponent::State::grounded) | ||
| 177 | { | ||
| 178 | playSound("res/Randomize87.wav", 0.25); | ||
| 179 | |||
| 180 | ponderable.setVelocityY(JUMP_VELOCITY(TILE_HEIGHT*4.5, 0.3)); | ||
| 181 | ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*4.5, 0.3)); | ||
| 182 | ponderable.setState(PonderableComponent::State::jumping); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | void ControllingSystem::stopJumping(id_type entity) | ||
| 187 | { | ||
| 188 | auto& ponderable = game_.getEntityManager().getComponent<PonderableComponent>(entity); | ||
| 189 | |||
| 190 | if (ponderable.getState() == PonderableComponent::State::jumping) | ||
| 191 | { | ||
| 192 | ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*3.5, 0.233)); | ||
| 193 | ponderable.setState(PonderableComponent::State::falling); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | void ControllingSystem::drop(id_type entity, bool start) | ||
| 198 | { | ||
| 199 | auto& droppable = game_.getEntityManager().getComponent<DroppableComponent>(entity); | ||
| 200 | auto& ponderable = game_.getEntityManager().getComponent<PonderableComponent>(entity); | ||
| 201 | |||
| 202 | if (start && (ponderable.getState() == PonderableComponent::State::grounded)) | ||
| 203 | { | ||
| 204 | ponderable.setState(PonderableComponent::State::dropping); | ||
| 205 | } else if ((!start) && (ponderable.getState() == PonderableComponent::State::dropping)) | ||
| 206 | { | ||
| 207 | ponderable.setState(PonderableComponent::State::grounded); | ||
| 208 | } | ||
| 209 | droppable.setDroppable(start); | ||
| 210 | } | ||
| diff --git a/src/systems/controlling.h b/src/systems/controlling.h index 1f1e8a0..01ed7a0 100644 --- a/src/systems/controlling.h +++ b/src/systems/controlling.h | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | #include "system.h" | 4 | #include "system.h" |
| 5 | #include <queue> | 5 | #include <queue> |
| 6 | #include "entity_manager.h" | ||
| 7 | 6 | ||
| 8 | class ControllingSystem : public System { | 7 | class ControllingSystem : public System { |
| 9 | public: | 8 | public: |
| @@ -17,13 +16,6 @@ public: | |||
| 17 | 16 | ||
| 18 | private: | 17 | private: |
| 19 | 18 | ||
| 20 | void walkLeft(id_type entity); | ||
| 21 | void walkRight(id_type entity); | ||
| 22 | void stopWalking(id_type entity); | ||
| 23 | void jump(id_type entity); | ||
| 24 | void stopJumping(id_type entity); | ||
| 25 | void drop(id_type entity, bool start); | ||
| 26 | |||
| 27 | std::queue<std::pair<int,int>> actions_; | 19 | std::queue<std::pair<int,int>> actions_; |
| 28 | }; | 20 | }; |
| 29 | 21 | ||
| diff --git a/src/systems/mapping.cpp b/src/systems/mapping.cpp index 8723e16..5b63ded 100644 --- a/src/systems/mapping.cpp +++ b/src/systems/mapping.cpp | |||
| @@ -3,8 +3,6 @@ | |||
| 3 | #include "game.h" | 3 | #include "game.h" |
| 4 | #include "consts.h" | 4 | #include "consts.h" |
| 5 | 5 | ||
| 6 | #include <iostream> | ||
| 7 | |||
| 8 | template <typename Storage> | 6 | template <typename Storage> |
| 9 | inline void addBoundary( | 7 | inline void addBoundary( |
| 10 | Storage& boundaries, | 8 | Storage& boundaries, |
| diff --git a/src/systems/orienting.cpp b/src/systems/orienting.cpp new file mode 100644 index 0000000..187bebc --- /dev/null +++ b/src/systems/orienting.cpp | |||
| @@ -0,0 +1,236 @@ | |||
| 1 | #include "orienting.h" | ||
| 2 | #include "game.h" | ||
| 3 | #include "components/orientable.h" | ||
| 4 | #include "components/ponderable.h" | ||
| 5 | #include "systems/animating.h" | ||
| 6 | #include "consts.h" | ||
| 7 | #include "muxer.h" | ||
| 8 | |||
| 9 | void OrientingSystem::tick(double) | ||
| 10 | { | ||
| 11 | auto entities = game_.getEntityManager().getEntitiesWithComponents< | ||
| 12 | OrientableComponent, | ||
| 13 | PonderableComponent>(); | ||
| 14 | |||
| 15 | for (id_type entity : entities) | ||
| 16 | { | ||
| 17 | auto& orientable = game_.getEntityManager(). | ||
| 18 | getComponent<OrientableComponent>(entity); | ||
| 19 | |||
| 20 | auto& ponderable = game_.getEntityManager(). | ||
| 21 | getComponent<PonderableComponent>(entity); | ||
| 22 | |||
| 23 | switch (orientable.getWalkState()) | ||
| 24 | { | ||
| 25 | case OrientableComponent::WalkState::still: | ||
| 26 | { | ||
| 27 | ponderable.setVelocityX(0); | ||
| 28 | |||
| 29 | break; | ||
| 30 | } | ||
| 31 | |||
| 32 | case OrientableComponent::WalkState::left: | ||
| 33 | { | ||
| 34 | ponderable.setVelocityX(-WALK_SPEED); | ||
| 35 | |||
| 36 | break; | ||
| 37 | } | ||
| 38 | |||
| 39 | case OrientableComponent::WalkState::right: | ||
| 40 | { | ||
| 41 | ponderable.setVelocityX(WALK_SPEED); | ||
| 42 | |||
| 43 | break; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | if (orientable.isJumping() && (ponderable.getVelocityY() > 0)) | ||
| 48 | { | ||
| 49 | orientable.setJumping(false); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | void OrientingSystem::moveLeft(id_type entity) | ||
| 55 | { | ||
| 56 | auto& ponderable = game_.getEntityManager(). | ||
| 57 | getComponent<PonderableComponent>(entity); | ||
| 58 | |||
| 59 | auto& orientable = game_.getEntityManager(). | ||
| 60 | getComponent<OrientableComponent>(entity); | ||
| 61 | |||
| 62 | orientable.setFacingRight(false); | ||
| 63 | orientable.setWalkState(OrientableComponent::WalkState::left); | ||
| 64 | |||
| 65 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 66 | if (ponderable.isGrounded()) | ||
| 67 | { | ||
| 68 | animating.startAnimation(entity, "walkingLeft"); | ||
| 69 | } else { | ||
| 70 | animating.startAnimation(entity, "stillLeft"); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | void OrientingSystem::moveRight(id_type entity) | ||
| 75 | { | ||
| 76 | auto& ponderable = game_.getEntityManager(). | ||
| 77 | getComponent<PonderableComponent>(entity); | ||
| 78 | |||
| 79 | auto& orientable = game_.getEntityManager(). | ||
| 80 | getComponent<OrientableComponent>(entity); | ||
| 81 | |||
| 82 | orientable.setFacingRight(true); | ||
| 83 | orientable.setWalkState(OrientableComponent::WalkState::right); | ||
| 84 | |||
| 85 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 86 | if (ponderable.isGrounded()) | ||
| 87 | { | ||
| 88 | animating.startAnimation(entity, "walkingRight"); | ||
| 89 | } else { | ||
| 90 | animating.startAnimation(entity, "stillRight"); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | void OrientingSystem::stopWalking(id_type entity) | ||
| 95 | { | ||
| 96 | auto& ponderable = game_.getEntityManager(). | ||
| 97 | getComponent<PonderableComponent>(entity); | ||
| 98 | |||
| 99 | auto& orientable = game_.getEntityManager(). | ||
| 100 | getComponent<OrientableComponent>(entity); | ||
| 101 | |||
| 102 | orientable.setWalkState(OrientableComponent::WalkState::still); | ||
| 103 | |||
| 104 | if (ponderable.isGrounded()) | ||
| 105 | { | ||
| 106 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 107 | |||
| 108 | if (orientable.isFacingRight()) | ||
| 109 | { | ||
| 110 | animating.startAnimation(entity, "stillRight"); | ||
| 111 | } else { | ||
| 112 | animating.startAnimation(entity, "stillLeft"); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | void OrientingSystem::jump(id_type entity) | ||
| 118 | { | ||
| 119 | auto& ponderable = game_.getEntityManager(). | ||
| 120 | getComponent<PonderableComponent>(entity); | ||
| 121 | |||
| 122 | if (ponderable.isGrounded()) | ||
| 123 | { | ||
| 124 | auto& orientable = game_.getEntityManager(). | ||
| 125 | getComponent<OrientableComponent>(entity); | ||
| 126 | |||
| 127 | orientable.setJumping(true); | ||
| 128 | |||
| 129 | playSound("res/Randomize87.wav", 0.25); | ||
| 130 | |||
| 131 | ponderable.setVelocityY(JUMP_VELOCITY); | ||
| 132 | ponderable.setAccelY(JUMP_GRAVITY); | ||
| 133 | |||
| 134 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 135 | if (orientable.isFacingRight()) | ||
| 136 | { | ||
| 137 | animating.startAnimation(entity, "stillRight"); | ||
| 138 | } else { | ||
| 139 | animating.startAnimation(entity, "stillLeft"); | ||
| 140 | } | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | void OrientingSystem::stopJumping(id_type entity) | ||
| 145 | { | ||
| 146 | auto& orientable = game_.getEntityManager(). | ||
| 147 | getComponent<OrientableComponent>(entity); | ||
| 148 | |||
| 149 | if (orientable.isJumping()) | ||
| 150 | { | ||
| 151 | orientable.setJumping(false); | ||
| 152 | |||
| 153 | auto& ponderable = game_.getEntityManager(). | ||
| 154 | getComponent<PonderableComponent>(entity); | ||
| 155 | |||
| 156 | ponderable.setAccelY(NORMAL_GRAVITY); | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | void OrientingSystem::land(id_type entity) | ||
| 161 | { | ||
| 162 | auto& orientable = game_.getEntityManager(). | ||
| 163 | getComponent<OrientableComponent>(entity); | ||
| 164 | |||
| 165 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 166 | |||
| 167 | switch (orientable.getWalkState()) | ||
| 168 | { | ||
| 169 | case OrientableComponent::WalkState::still: | ||
| 170 | { | ||
| 171 | if (orientable.isFacingRight()) | ||
| 172 | { | ||
| 173 | animating.startAnimation(entity, "stillRight"); | ||
| 174 | } else { | ||
| 175 | animating.startAnimation(entity, "stillLeft"); | ||
| 176 | } | ||
| 177 | |||
| 178 | break; | ||
| 179 | } | ||
| 180 | |||
| 181 | case OrientableComponent::WalkState::left: | ||
| 182 | { | ||
| 183 | animating.startAnimation(entity, "walkingLeft"); | ||
| 184 | |||
| 185 | break; | ||
| 186 | } | ||
| 187 | |||
| 188 | case OrientableComponent::WalkState::right: | ||
| 189 | { | ||
| 190 | animating.startAnimation(entity, "walkingRight"); | ||
| 191 | |||
| 192 | break; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | void OrientingSystem::startFalling(id_type entity) | ||
| 198 | { | ||
| 199 | auto& orientable = game_.getEntityManager(). | ||
| 200 | getComponent<OrientableComponent>(entity); | ||
| 201 | |||
| 202 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | ||
| 203 | |||
| 204 | if (orientable.isFacingRight()) | ||
| 205 | { | ||
| 206 | animating.startAnimation(entity, "stillRight"); | ||
| 207 | } else { | ||
| 208 | animating.startAnimation(entity, "stillLeft"); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | void OrientingSystem::drop(id_type entity) | ||
| 213 | { | ||
| 214 | auto& orientable = game_.getEntityManager(). | ||
| 215 | getComponent<OrientableComponent>(entity); | ||
| 216 | |||
| 217 | auto& ponderable = game_.getEntityManager(). | ||
| 218 | getComponent<PonderableComponent>(entity); | ||
| 219 | |||
| 220 | if (ponderable.isGrounded() | ||
| 221 | && (orientable.getDropState() == OrientableComponent::DropState::none)) | ||
| 222 | { | ||
| 223 | orientable.setDropState(OrientableComponent::DropState::ready); | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | void OrientingSystem::stopDropping(id_type entity) | ||
| 228 | { | ||
| 229 | auto& orientable = game_.getEntityManager(). | ||
| 230 | getComponent<OrientableComponent>(entity); | ||
| 231 | |||
| 232 | if (orientable.getDropState() == OrientableComponent::DropState::ready) | ||
| 233 | { | ||
| 234 | orientable.setDropState(OrientableComponent::DropState::none); | ||
| 235 | } | ||
| 236 | } | ||
| diff --git a/src/systems/orienting.h b/src/systems/orienting.h new file mode 100644 index 0000000..4ded612 --- /dev/null +++ b/src/systems/orienting.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #ifndef ORIENTING_H_099F0C23 | ||
| 2 | #define ORIENTING_H_099F0C23 | ||
| 3 | |||
| 4 | #include "system.h" | ||
| 5 | |||
| 6 | class OrientingSystem : public System { | ||
| 7 | public: | ||
| 8 | |||
| 9 | OrientingSystem(Game& game) : System(game) | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | void tick(double dt); | ||
| 14 | |||
| 15 | void moveLeft(id_type entity); | ||
| 16 | |||
| 17 | void moveRight(id_type entity); | ||
| 18 | |||
| 19 | void stopWalking(id_type entity); | ||
| 20 | |||
| 21 | void jump(id_type entity); | ||
| 22 | |||
| 23 | void stopJumping(id_type entity); | ||
| 24 | |||
| 25 | void land(id_type entity); | ||
| 26 | |||
| 27 | void startFalling(id_type entity); | ||
| 28 | |||
| 29 | void drop(id_type entity); | ||
| 30 | |||
| 31 | void stopDropping(id_type entity); | ||
| 32 | |||
| 33 | }; | ||
| 34 | |||
| 35 | #endif /* end of include guard: ORIENTING_H_099F0C23 */ | ||
| diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 26a6f56..4a165b1 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp | |||
| @@ -2,7 +2,9 @@ | |||
| 2 | #include "game.h" | 2 | #include "game.h" |
| 3 | #include "components/ponderable.h" | 3 | #include "components/ponderable.h" |
| 4 | #include "components/transformable.h" | 4 | #include "components/transformable.h" |
| 5 | #include "components/droppable.h" | 5 | #include "components/orientable.h" |
| 6 | #include "components/mappable.h" | ||
| 7 | #include "systems/orienting.h" | ||
| 6 | #include "consts.h" | 8 | #include "consts.h" |
| 7 | 9 | ||
| 8 | void PonderingSystem::tick(double dt) | 10 | void PonderingSystem::tick(double dt) |
| @@ -37,10 +39,8 @@ void PonderingSystem::tick(double dt) | |||
| 37 | double newX = oldX + ponderable.getVelocityX() * dt; | 39 | double newX = oldX + ponderable.getVelocityX() * dt; |
| 38 | double newY = oldY + ponderable.getVelocityY() * dt; | 40 | double newY = oldY + ponderable.getVelocityY() * dt; |
| 39 | 41 | ||
| 40 | if (ponderable.getVelocityY() > 0.0) | 42 | bool oldGrounded = ponderable.isGrounded(); |
| 41 | { | 43 | ponderable.setGrounded(false); |
| 42 | ponderable.setState(PonderableComponent::State::falling); | ||
| 43 | } | ||
| 44 | 44 | ||
| 45 | for (id_type mapEntity : maps) | 45 | for (id_type mapEntity : maps) |
| 46 | { | 46 | { |
| @@ -64,8 +64,6 @@ void PonderingSystem::tick(double dt) | |||
| 64 | newY, | 64 | newY, |
| 65 | it->first, | 65 | it->first, |
| 66 | it->second.getType()); | 66 | it->second.getType()); |
| 67 | |||
| 68 | break; | ||
| 69 | } | 67 | } |
| 70 | } | 68 | } |
| 71 | } else if (newX > oldX) | 69 | } else if (newX > oldX) |
| @@ -86,8 +84,6 @@ void PonderingSystem::tick(double dt) | |||
| 86 | newY, | 84 | newY, |
| 87 | it->first, | 85 | it->first, |
| 88 | it->second.getType()); | 86 | it->second.getType()); |
| 89 | |||
| 90 | break; | ||
| 91 | } | 87 | } |
| 92 | } | 88 | } |
| 93 | } | 89 | } |
| @@ -109,8 +105,6 @@ void PonderingSystem::tick(double dt) | |||
| 109 | newY, | 105 | newY, |
| 110 | it->first, | 106 | it->first, |
| 111 | it->second.getType()); | 107 | it->second.getType()); |
| 112 | |||
| 113 | break; | ||
| 114 | } | 108 | } |
| 115 | } | 109 | } |
| 116 | } else if (newY > oldY) | 110 | } else if (newY > oldY) |
| @@ -131,8 +125,6 @@ void PonderingSystem::tick(double dt) | |||
| 131 | newY, | 125 | newY, |
| 132 | it->first, | 126 | it->first, |
| 133 | it->second.getType()); | 127 | it->second.getType()); |
| 134 | |||
| 135 | break; | ||
| 136 | } | 128 | } |
| 137 | } | 129 | } |
| 138 | } | 130 | } |
| @@ -141,6 +133,31 @@ void PonderingSystem::tick(double dt) | |||
| 141 | // Move | 133 | // Move |
| 142 | transformable.setX(newX); | 134 | transformable.setX(newX); |
| 143 | transformable.setY(newY); | 135 | transformable.setY(newY); |
| 136 | |||
| 137 | // Perform cleanup for orientable entites | ||
| 138 | if (game_.getEntityManager().hasComponent<OrientableComponent>(entity)) | ||
| 139 | { | ||
| 140 | auto& orientable = game_.getEntityManager(). | ||
| 141 | getComponent<OrientableComponent>(entity); | ||
| 142 | |||
| 143 | // Handle changes in groundedness | ||
| 144 | if (ponderable.isGrounded() != oldGrounded) | ||
| 145 | { | ||
| 146 | if (ponderable.isGrounded()) | ||
| 147 | { | ||
| 148 | game_.getSystemManager().getSystem<OrientingSystem>().land(entity); | ||
| 149 | } else { | ||
| 150 | game_.getSystemManager(). | ||
| 151 | getSystem<OrientingSystem>().startFalling(entity); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | // Complete dropping, if necessary | ||
| 156 | if (orientable.getDropState() == OrientableComponent::DropState::active) | ||
| 157 | { | ||
| 158 | orientable.setDropState(OrientableComponent::DropState::none); | ||
| 159 | } | ||
| 160 | } | ||
| 144 | } | 161 | } |
| 145 | } | 162 | } |
| 146 | 163 | ||
| @@ -153,8 +170,7 @@ void PonderingSystem::initializeBody( | |||
| 153 | 170 | ||
| 154 | if (type == PonderableComponent::Type::freefalling) | 171 | if (type == PonderableComponent::Type::freefalling) |
| 155 | { | 172 | { |
| 156 | ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*3.5, 0.233)); | 173 | ponderable.setAccelY(NORMAL_GRAVITY); |
| 157 | ponderable.setState(PonderableComponent::State::falling); | ||
| 158 | } | 174 | } |
| 159 | } | 175 | } |
| 160 | 176 | ||
| @@ -172,6 +188,8 @@ void PonderingSystem::processCollision( | |||
| 172 | auto& transformable = game_.getEntityManager(). | 188 | auto& transformable = game_.getEntityManager(). |
| 173 | getComponent<TransformableComponent>(entity); | 189 | getComponent<TransformableComponent>(entity); |
| 174 | 190 | ||
| 191 | bool touchedGround = false; | ||
| 192 | |||
| 175 | switch (type) | 193 | switch (type) |
| 176 | { | 194 | { |
| 177 | case MappableComponent::Boundary::Type::wall: | 195 | case MappableComponent::Boundary::Type::wall: |
| @@ -204,13 +222,7 @@ void PonderingSystem::processCollision( | |||
| 204 | 222 | ||
| 205 | case Direction::down: | 223 | case Direction::down: |
| 206 | { | 224 | { |
| 207 | newY = axis - transformable.getH(); | 225 | touchedGround = true; |
| 208 | ponderable.setVelocityY(0.0); | ||
| 209 | |||
| 210 | if (ponderable.getState() == PonderableComponent::State::falling) | ||
| 211 | { | ||
| 212 | ponderable.setState(PonderableComponent::State::grounded); | ||
| 213 | } | ||
| 214 | 226 | ||
| 215 | break; | 227 | break; |
| 216 | } | 228 | } |
| @@ -221,31 +233,19 @@ void PonderingSystem::processCollision( | |||
| 221 | 233 | ||
| 222 | case MappableComponent::Boundary::Type::platform: | 234 | case MappableComponent::Boundary::Type::platform: |
| 223 | { | 235 | { |
| 224 | if (game_.getEntityManager().hasComponent<DroppableComponent>(entity)) | 236 | if (game_.getEntityManager().hasComponent<OrientableComponent>(entity)) |
| 225 | { | 237 | { |
| 226 | auto& droppable = game_.getEntityManager(). | 238 | auto& orientable = game_.getEntityManager(). |
| 227 | getComponent<DroppableComponent>(entity); | 239 | getComponent<OrientableComponent>(entity); |
| 228 | 240 | ||
| 229 | if (droppable.isDroppable()) | 241 | if (orientable.getDropState() != OrientableComponent::DropState::none) |
| 230 | { | 242 | { |
| 231 | droppable.setDroppable(false); | 243 | orientable.setDropState(OrientableComponent::DropState::active); |
| 232 | } else { | 244 | } else { |
| 233 | newY = axis - transformable.getH(); | 245 | touchedGround = true; |
| 234 | ponderable.setVelocityY(0.0); | ||
| 235 | |||
| 236 | if (ponderable.getState() == PonderableComponent::State::falling) | ||
| 237 | { | ||
| 238 | ponderable.setState(PonderableComponent::State::grounded); | ||
| 239 | } | ||
| 240 | } | 246 | } |
| 241 | } else { | 247 | } else { |
| 242 | newY = axis - transformable.getH(); | 248 | touchedGround = true; |
| 243 | ponderable.setVelocityY(0.0); | ||
| 244 | |||
| 245 | if (ponderable.getState() == PonderableComponent::State::falling) | ||
| 246 | { | ||
| 247 | ponderable.setState(PonderableComponent::State::grounded); | ||
| 248 | } | ||
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | break; | 251 | break; |
| @@ -258,4 +258,11 @@ void PonderingSystem::processCollision( | |||
| 258 | break; | 258 | break; |
| 259 | } | 259 | } |
| 260 | } | 260 | } |
| 261 | |||
| 262 | if (touchedGround) | ||
| 263 | { | ||
| 264 | newY = axis - transformable.getH(); | ||
| 265 | ponderable.setVelocityY(0.0); | ||
| 266 | ponderable.setGrounded(true); | ||
| 267 | } | ||
| 261 | } | 268 | } |
