diff options
Diffstat (limited to 'src/systems/pondering.cpp')
-rw-r--r-- | src/systems/pondering.cpp | 89 |
1 files changed, 48 insertions, 41 deletions
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 | } |