| 256 | } |
| 257 | |
| 258 | void Projectile::update(float dt, uint64_t) { |
| 259 | m_movementController->setTimestep(dt); |
| 260 | |
| 261 | if (isMaster()) { |
| 262 | m_timeToLive -= dt; |
| 263 | if (m_timeToLive < 0) |
| 264 | m_timeToLive = 0; |
| 265 | |
| 266 | m_effectEmitter->addEffectSources("normal", m_config->emitters); |
| 267 | |
| 268 | if (m_referenceVelocity) |
| 269 | m_movementController->setVelocity(m_movementController->velocity() - *m_referenceVelocity); |
| 270 | |
| 271 | m_scriptComponent.update(m_scriptComponent.updateDt(dt)); |
| 272 | m_movementController->accelerate(m_movementController->velocity().normalized() * m_acceleration); |
| 273 | |
| 274 | if (m_referenceVelocity) |
| 275 | m_movementController->setVelocity(m_movementController->velocity() + *m_referenceVelocity); |
| 276 | |
| 277 | m_movementController->tickMaster(dt); |
| 278 | m_travelLine.min() = m_travelLine.max(); |
| 279 | m_travelLine.max() = m_movementController->position(); |
| 280 | |
| 281 | tickShared(dt); |
| 282 | |
| 283 | if (m_trackSourceEntity) { |
| 284 | if (auto sourceEntity = world()->entity(m_sourceEntity)) { |
| 285 | Vec2F newEntityPosition = sourceEntity->position(); |
| 286 | m_movementController->translate(newEntityPosition - m_lastEntityPosition); |
| 287 | m_lastEntityPosition = newEntityPosition; |
| 288 | } else { |
| 289 | m_trackSourceEntity = false; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if (m_movementController->atWorldLimit()) |
| 294 | m_timeToLive = 0.0f; |
| 295 | |
| 296 | if ((m_movementController->isColliding() || m_movementController->stickingDirection()) && !m_movementController->isNullColliding()) { |
| 297 | if (!m_wasColliding) |
| 298 | m_collisionEvent.trigger(); |
| 299 | m_wasColliding = true; |
| 300 | } else { |
| 301 | m_wasColliding = false; |
| 302 | } |
| 303 | |
| 304 | if (m_movementController->isColliding()) { |
| 305 | if (m_movementController->isNullColliding()) { |
| 306 | // Don't trigger collision action, just silently die if we collide with a |
| 307 | // null block. |
| 308 | m_timeToLive = 0.0f; |
| 309 | } else if (m_bounces != 0) { |
| 310 | m_scriptComponent.invoke("bounce"); |
| 311 | if (m_bounces > 0) |
| 312 | --m_bounces; |
| 313 | } else if (m_falldown && !(m_movementController->onGround() || m_movementController->isCollisionStuck() || m_movementController->stickingDirection())) { |
| 314 | // Wait til this projectile actually hits the ground before dying |
| 315 |
nothing calls this directly
no test coverage detected