void Projectile::update(float dt) { BattleBoy* game = BattleBoy::instance(); Actor::update(dt); if( game->isOutOfBounds(this) ) { setDestroyed(true); } else { // check for collisions for( std::vector<Actor*>::iterator it = game->getActors().begin(); it != game->getActors().end(); it++ ) { if( (*it)->collidedWith(this) ) { Unit* otherUnit = dynamic_cast<Unit*>(*it); if( otherUnit && otherUnit->getTeamIdx() != mInstigator->getTeamIdx() ) { game->addActor(new Explosion(getPos().x, getPos().y, 2, 5, otherUnit->getTeamIdx() == 0 ? 0xff00ffff : 0xffff0000)); otherUnit->takeDamage(mInstigator); setDestroyed(true); break; } } } } }
void Package::update (uint32_t deltaTime) { CollectableEntity::update(deltaTime); if (_addRopeJointTo) { addRopeJoint(_addRopeJointTo); _addRopeJointTo = nullptr; } if ((_arrived || _delivered || isDestroyed()) && _ropeJoint) { removeRopeJoint(); } if (isCollected()) { setLinearDamping(0.0f); setAngularDamping(0.0); } if (!_target) { _target = _map.getPackageTarget(); // if we can't find a package target, we will destroy the package if (!_target) setDestroyed(); } if (!isCounted() && isDelivered()) { _map.countTransferedPackage(); setCounted(); } }
void Actor::init() { size = 20; setDestroyed(false); setShouldErase(true); game = NULL; }
void Package::onContact (b2Contact* contact, IEntity* entity) { const bool oldCollectedState = isCollected(); CollectableEntity::onContact(contact, entity); if (!oldCollectedState && isCollected()) { _addRopeJointTo = entity; } else { if (entity->isSolid() || entity->isStone() || entity->isPackage()) { setLinearDamping(3.0f); setAngularDamping(1.0); if (isImpactVelocityMoreThan(contact, 1.5f)) _map.sendSound(getVisMask(), SoundTypes::SOUND_PACKAGE_COLLIDE, getPos()); } else if (entity->isBorder()) { const Border *b = assert_cast<const Border*, const IEntity*>(entity); if (!b->isTop()) { setLinearDamping(4.0f); setAngularDamping(1.0); } } else if (entity->isNpcAttacking()) { setDestroyed(true); } } }