Refactoring: instead of flyable triggering explosions, this must now

be done from the hit function of the objects that need an explosion.
This makes flyable and the behaviour of flyables easier to understand
when reading the code, getting rid of the needsExplosion function.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9623 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2011-08-25 22:16:52 +00:00
parent f3355f2484
commit a51597cdaf
8 changed files with 26 additions and 15 deletions

View File

@@ -198,3 +198,13 @@ bool Bowling::updateAndDelete(float dt)
return false;
} // updateAndDelete
// -----------------------------------------------------------------------------
/** Callback from the physics in case that a kart or physical object is hit.
* The bowling ball triggers an explosion when hit.
* \param kart The kart hit (NULL if no kart was hit).
* \param object The object that was hit (NULL if none).
*/
void Bowling::hit(Kart* kart, PhysicalObject* obj)
{
Flyable::hit(kart, obj);
explode(kart, obj);
} // hit

View File

@@ -46,6 +46,7 @@ public:
static void init(const XMLNode &node, scene::IMesh *bowling);
virtual bool updateAndDelete(float dt);
virtual const core::stringw getHitString(const Kart *kart) const;
virtual void hit(Kart* kart, PhysicalObject* obj=NULL);
/** Returns the sfx to use when the bowling ball explodes. */
const char* getExplosionSound() const { return "strike"; }

View File

@@ -154,3 +154,15 @@ const core::stringw Cake::getHitString(const Kart *kart) const
default: assert(false); return L""; // avoid compiler warning
}
} // getHitString
// ----------------------------------------------------------------------------
/** Callback from the physics in case that a kart or physical object is hit.
* The cake triggers an explosion when hit.
* \param kart The kart hit (NULL if no kart was hit).
* \param object The object that was hit (NULL if none).
*/
void Cake::hit(Kart* kart, PhysicalObject* obj)
{
Flyable::hit(kart, obj);
explode(kart, obj);
} // hit

View File

@@ -50,6 +50,7 @@ public:
Cake (Kart *kart);
static void init (const XMLNode &node, scene::IMesh *cake_model);
virtual const core::stringw getHitString(const Kart *kart) const;
virtual void hit(Kart* kart, PhysicalObject* obj=NULL);
// ------------------------------------------------------------------------
virtual void hitTrack () { hit(NULL); }
// ------------------------------------------------------------------------

View File

@@ -390,7 +390,7 @@ bool Flyable::updateAndDelete(float dt)
Moveable::update(dt);
return false;
} // updateAmdDelete
} // updateAndDelete
// ----------------------------------------------------------------------------
/** Updates the position of a projectile based on information received frmo the
@@ -419,7 +419,7 @@ bool Flyable::isOwnerImmunity(const Kart* kart_hit) const
} // isOwnerImmunity
// ----------------------------------------------------------------------------
/** Callback from the phycis in case that a kart or physical object is hit.
/** Callback from the physics in case that a kart or physical object is hit.
* kart The kart hit (NULL if no kart was hit).
* object The object that was hit (NULL if none).
*/
@@ -442,13 +442,8 @@ void Flyable::hit(Kart *kart_hit, PhysicalObject* object)
}
m_has_hit_something=true;
// Notify the projectile manager that this rocket has hit something.
// The manager will create the appropriate explosion object.
m_exploded=true;
if(needsExplosion())
explode(kart_hit, object);
return;

View File

@@ -193,9 +193,6 @@ public:
// ------------------------------------------------------------------------
/** Returns the sfx that should be played in case of an explosion. */
virtual const char* getExplosionSound() const { return "explosion"; }
// ------------------------------------------------------------------------
/** Default is that each flyable needs an explosion effect. */
virtual bool needsExplosion() const { return true; }
}; // Flyable
#endif

View File

@@ -64,8 +64,6 @@ public:
/** No hit effect when it ends. */
virtual HitEffect *getHitEffect() const {return NULL; }
// ------------------------------------------------------------------------
/** Plunger does not need an explosion effect. */
virtual bool needsExplosion() const { return false; }
}; // Plunger
#endif

View File

@@ -134,9 +134,6 @@ public:
/** This object does not create an explosion, all affects on
* karts are handled by this hit() function. */
virtual HitEffect *getHitEffect() const {return NULL; }
// ------------------------------------------------------------------------
/** Plunger does not need an explosion effect. */
virtual bool needsExplosion() const { return false; }
}; // RubberBall