added time management to flyables. this means : 1) bowling balls now have a time limit, after a while they self-destruct 2) you can't be hit by your own flyable while throwing it, thus throwables don't need to be placed so far in front of karts
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2510 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
0cc1dd7b98
commit
b1a4eeb190
@ -57,6 +57,10 @@ Flyable::Flyable(Kart *kart, PowerupType type, float mass) : Moveable()
|
||||
m_mass = mass;
|
||||
m_adjust_z_velocity = true;
|
||||
|
||||
m_time_since_thrown = 0;
|
||||
m_owner_has_temporary_immunity = true;
|
||||
m_max_lifespan = -1;
|
||||
|
||||
// Add the graphical model
|
||||
ssgTransform *m = getModelTransform();
|
||||
m->addKid(m_st_model[type]);
|
||||
@ -184,6 +188,9 @@ void Flyable::getClosestKart(const Kart **minKart, float *minDistSquared,
|
||||
//-----------------------------------------------------------------------------
|
||||
void Flyable::update (float dt)
|
||||
{
|
||||
m_time_since_thrown += dt;
|
||||
if(m_max_lifespan > -1 && m_time_since_thrown > m_max_lifespan) explode(NULL);
|
||||
|
||||
if(m_exploded) return;
|
||||
|
||||
Vec3 pos=getBody()->getWorldTransform().getOrigin();
|
||||
@ -229,6 +236,9 @@ void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
{
|
||||
if(m_exploded) return;
|
||||
|
||||
// the owner of this flyable should not be hit by his own flyable
|
||||
if(m_owner_has_temporary_immunity && kart_hit == m_owner && m_time_since_thrown < 2.0f) return;
|
||||
|
||||
m_has_hit_something=true;
|
||||
// Notify the projectile manager that this rocket has hit something.
|
||||
// The manager will create the appropriate explosion object.
|
||||
|
@ -40,7 +40,7 @@ private:
|
||||
* adjusted in case that the objects is too high or too low above the
|
||||
* terrain. Otherwise gravity will not work correctly on this object. */
|
||||
bool m_adjust_z_velocity;
|
||||
|
||||
|
||||
protected:
|
||||
Kart* m_owner; // the kart which released this flyable
|
||||
btCollisionShape *m_shape;
|
||||
@ -62,6 +62,17 @@ protected:
|
||||
static float m_st_force_updown[POWERUP_MAX]; // force pushing up/down
|
||||
static btVector3 m_st_extend[POWERUP_MAX]; // size of the model
|
||||
|
||||
/** time since thrown. used so a kart can't hit himself when trying something,
|
||||
and also to put some time limit to some collectibles */
|
||||
float m_time_since_thrown;
|
||||
|
||||
/** set to something > -1 if this flyable should auto-destrcut after a while */
|
||||
float m_max_lifespan;
|
||||
|
||||
/** if set to true, the kart that throwns this flyable can't collide with it
|
||||
for a short time */
|
||||
bool m_owner_has_temporary_immunity;
|
||||
|
||||
/** Returns information on what is the closest kart and at what
|
||||
distance it is. All 3 parameters first are of type 'out'.
|
||||
'inFrontOf' can be set if you wish to know the closest
|
||||
|
@ -28,7 +28,7 @@ float Bowling::m_st_force_to_target;
|
||||
// -----------------------------------------------------------------------------
|
||||
Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */)
|
||||
{
|
||||
float y_offset = 0.5f*kart->getKartLength()+2.0f*m_extend.getY();
|
||||
float y_offset = 0.5f*kart->getKartLength() + m_extend.getY()/2.0f;
|
||||
|
||||
// if the kart is looking backwards, release from the back
|
||||
PlayerKart* pk = dynamic_cast<PlayerKart*>(kart);
|
||||
@ -60,6 +60,10 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */)
|
||||
int flag = getBody()->getCollisionFlags();
|
||||
flag = flag & (~ btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
||||
getBody()->setCollisionFlags(flag);
|
||||
|
||||
// should not live forever, auto-destruct after 20 seconds
|
||||
m_max_lifespan = 20;
|
||||
|
||||
} // Bowling
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -35,7 +35,7 @@ Cake::Cake (Kart *kart) : Flyable(kart, POWERUP_CAKE)
|
||||
// collide with the track. By setting the mass to 1, collisions happen.
|
||||
// (if bullet is compiled with _DEBUG, a warning will be printed the first
|
||||
// time a homing-track collision happens).
|
||||
float y_offset=kart->getKartLength()+2.0f*m_extend.getY();
|
||||
float y_offset=kart->getKartLength()/2.0f + m_extend.getY()/2.0f;
|
||||
|
||||
float up_velocity = m_speed/7.0f;
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
|
||||
{
|
||||
float y_offset = 0.5f*kart->getKartLength()+2.0f*m_extend.getY();
|
||||
float y_offset = 0.5f*kart->getKartLength()+0.5f*m_extend.getY();
|
||||
|
||||
// if the kart is looking backwards, release from the back
|
||||
PlayerKart* pk = dynamic_cast<PlayerKart*>(kart);
|
||||
|
Loading…
Reference in New Issue
Block a user