MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / init

Method init

Source/Platformer/Bullet.cpp:39–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 , _face(nullptr) { }
38
39bool 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
71void Bullet::updatePhysics() {
72 if (!_pWorld || !_pWorld->getPrWorld()) {

Callers

nothing calls this directly

Calls 15

setOwnerFunction · 0.85
make_pairFunction · 0.85
setPositionFunction · 0.85
toDegFunction · 0.85
getVelocityMethod · 0.80
getGroupDetectionMethod · 0.80
toNodeMethod · 0.80
getPlayableMethod · 0.80
getLinearAccelerationMethod · 0.80
isHitStopMethod · 0.80
initFunction · 0.50
atan2Function · 0.50

Tested by

no test coverage detected