| 37 | , _face(nullptr) { } |
| 38 | |
| 39 | bool Bullet::init() { |
| 40 | if (!Body::init()) return false; |
| 41 | Bullet::setFaceRight(_emitter->isFaceRight()); |
| 42 | Bullet::setTag(_bulletDef->tag); |
| 43 | Body::setReceivingContact(true); |
| 44 | Body::setOwner(_emitter); |
| 45 | filterContact = [](Body*) { |
| 46 | return false; |
| 47 | }; |
| 48 | contactStart += std::make_pair(this, &Bullet::onBodyContact); |
| 49 | Vec2 v = _bulletDef->getVelocity(); |
| 50 | Body::setVelocity((isFaceRight() ? v.x : -v.x), v.y); |
| 51 | Body::setGroup(SharedData.getGroupDetection()); |
| 52 | Face* face = _bulletDef->getFace(); |
| 53 | if (face) { |
| 54 | Node* node = face->toNode(); |
| 55 | Bullet::setFace(node); |
| 56 | } |
| 57 | Playable* playable = _emitter->getPlayable(); |
| 58 | Vec2 offset = (playable ? playable->getKeyPoint(Def::BulletKey) : Vec2::zero); |
| 59 | Bullet::setPosition(_emitter->getPosition() + offset); |
| 60 | if (Body::getBodyDef()->getLinearAcceleration() != Vec2::zero) { |
| 61 | Bullet::setAngle(-bx::toDeg(std::atan2(v.y, _emitter->isFaceRight() ? v.x : -v.x))); |
| 62 | } |
| 63 | hitTarget += [](Bullet* bullet, Unit* target, Vec2 point, Vec2 normal) { |
| 64 | bullet->emit("HitTarget"_slice, bullet, target, point, normal); |
| 65 | return bullet->isHitStop(); |
| 66 | }; |
| 67 | this->scheduleUpdate(); |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | void Bullet::updatePhysics() { |
| 72 | if (!_pWorld || !_pWorld->getPrWorld()) { |
nothing calls this directly
no test coverage detected