17 #ifndef MAGNETICATTRACTORLOGIC_H
18 #define MAGNETICATTRACTORLOGIC_H
20 #include <Box2D/Box2D.h>
21 #include <Engine/Logic.h>
22 #include <Engine/audio/SoundEffectInstance.h>
100 bool isOn()
const {
return mOn; }
105 void setOn(
bool value);
151 virtual void init()
override;
155 virtual void update()
override;
184 void onActiveChanged();
187 Body* getEffectiveSensorBody()
const;
189 bool mHasTargetInRange =
false;
191 float mStrength = 20.0f;
192 float mSoftness = 1.0f;
193 Body* mSensorBody =
nullptr;
197 float mCachedGravityScale = 1.0f;
198 bool mCachedMagnetism =
false;
199 b2Vec2 mCurrentMagneticForce = b2Vec2(0.0f, 0.0f);
202 static const float SOFTEN_STRENGTH;
206 #endif // MAGNETICATTRACTORLOGIC_H
float strength
Overall strength of the magnet.
Definition: MagneticAttractorLogic.h:61
An instance of a sound effect.
Definition: SoundEffectInstance.h:36
A QObject container for a Box2D b2Body.
Definition: Body.h:57
void activeSoundChanged()
Emitted when activeSound changed.
bool on
Whether or not this magnet is on, and should attract magnetic Bodys.
Definition: MagneticAttractorLogic.h:57
Q_INVOKABLE QPointF getCurrentMagneticForce() const
Returns the sum of magnetic forces currently being exerted by this magnet.
void setActiveSound(const QString &value)
Sets activeSound.
virtual void update() override
Computes and exerts forces on magnetic objects, if on is true.
void softnessChanged()
Emitted when softness changed.
const QString & getActiveSound() const
Returns activeSound.
Definition: MagneticAttractorLogic.h:136
QString activeSound
Path to sound to play looped while the magnet is on.
Definition: MagneticAttractorLogic.h:81
void onChanged()
Emitted when on changed.
void strengthChanged()
Emitted when strength changed.
void setHasTargetInRange(bool value)
Sets hasTargetInRange.
bool isOn() const
Returns on.
Definition: MagneticAttractorLogic.h:100
float getStrength() const
Returns strength.
Definition: MagneticAttractorLogic.h:109
Non-visual entities in the QML item tree that define behavior for their parent Actor.
Definition: Logic.h:31
void setSensorBody(Body *value)
Sets sensorBody.
float getSoftness() const
Returns softness.
Definition: MagneticAttractorLogic.h:118
void setSoftness(float value)
Sets softness.
void setOn(bool value)
Sets on.
float softness
Amount of softness (linearity) of the magnet's attraction.
Definition: MagneticAttractorLogic.h:69
bool hasTargetInRange() const
Returns hasTargetInRange.
Definition: MagneticAttractorLogic.h:91
Body sensorBody
Body to use as a sensor for this magnet.
Definition: MagneticAttractorLogic.h:76
void hasTargetInRangeChanged()
Emitted when hasTargetInRange changed.
void sensorBodyChanged()
Emitted when sensorBody changed.
Logic which pulls its parent actor in the direction of magnetic Bodys and also attracting them toward...
Definition: MagneticAttractorLogic.h:41
Body * getSensorBody() const
Returns sensorBody.
Definition: MagneticAttractorLogic.h:127
virtual void init() override
Implements Logic::init() to perform additional initialization.
void setStrength(float value)
Sets strength.