Simplify bubblegum code, make it play a sound when exploding and leave a bubblegum pudddle on the ground
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14118 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
1e6425a1cc
commit
f426a2f31c
@ -25,6 +25,7 @@
|
||||
#include "graphics/explosion.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "items/attachment_manager.hpp"
|
||||
#include "items/item_manager.hpp"
|
||||
#include "items/projectile_manager.hpp"
|
||||
#include "items/swatter.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
@ -35,20 +36,23 @@
|
||||
#include "modes/world.hpp"
|
||||
#include "network/race_state.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include "physics/triangle_mesh.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/log.hpp" //TODO: remove after debugging is done
|
||||
// Log::verbose("attachment", "Decreasing shield \n");
|
||||
#include "utils/log.hpp"
|
||||
|
||||
/** Initialises the attachment each kart has.
|
||||
*/
|
||||
Attachment::Attachment(AbstractKart* kart)
|
||||
{
|
||||
m_type = ATTACH_NOTHING;
|
||||
m_time_left = 0.0;
|
||||
m_plugin = NULL;
|
||||
m_kart = kart;
|
||||
m_previous_owner = NULL;
|
||||
m_bomb_sound = NULL;
|
||||
m_node_scale = 1.0f;
|
||||
m_type = ATTACH_NOTHING;
|
||||
m_time_left = 0.0;
|
||||
m_plugin = NULL;
|
||||
m_kart = kart;
|
||||
m_previous_owner = NULL;
|
||||
m_bomb_sound = NULL;
|
||||
m_bubble_explode_sound = NULL;
|
||||
m_node_scale = 1.0f;
|
||||
|
||||
// If we attach a NULL mesh, we get a NULL scene node back. So we
|
||||
// have to attach some kind of mesh, but make it invisible.
|
||||
@ -77,6 +81,12 @@ Attachment::~Attachment()
|
||||
sfx_manager->deleteSFX(m_bomb_sound);
|
||||
m_bomb_sound = NULL;
|
||||
}
|
||||
|
||||
if (m_bubble_explode_sound)
|
||||
{
|
||||
sfx_manager->deleteSFX(m_bubble_explode_sound);
|
||||
m_bubble_explode_sound = NULL;
|
||||
}
|
||||
} // ~Attachment
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -214,7 +224,7 @@ void Attachment::hitBanana(Item *item, int new_attachment)
|
||||
//Bubble gum shield effect:
|
||||
if(m_type == ATTACH_BUBBLEGUM_SHIELD)
|
||||
{
|
||||
m_time_left -= stk_config->m_bubblegum_shield_time;
|
||||
m_time_left = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -434,15 +444,33 @@ void Attachment::update(float dt)
|
||||
// Nothing to do for tinytux, this is all handled in EmergencyAnimation
|
||||
break;
|
||||
case ATTACH_BUBBLEGUM_SHIELD:
|
||||
if(!m_kart->isShielded())
|
||||
if (m_time_left < 0)
|
||||
{
|
||||
m_time_left = 0.0f;
|
||||
if (m_kart->m_bubble_drop)
|
||||
if (m_bubble_explode_sound) sfx_manager->deleteSFX(m_bubble_explode_sound);
|
||||
m_bubble_explode_sound = sfx_manager->createSoundSource("bubblegum_explode");
|
||||
m_bubble_explode_sound->position(m_kart->getXYZ());
|
||||
m_bubble_explode_sound->play();
|
||||
|
||||
// drop a small bubble gum
|
||||
Vec3 hit_point;
|
||||
Vec3 normal;
|
||||
const Material* material_hit;
|
||||
Vec3 pos = m_kart->getXYZ();
|
||||
Vec3 to=pos+Vec3(0, -10000, 0);
|
||||
World* world = World::getWorld();
|
||||
world->getTrack()->getTriangleMesh().castRay(pos, to, &hit_point,
|
||||
&material_hit, &normal);
|
||||
// This can happen if the kart is 'over nothing' when dropping
|
||||
// the bubble gum
|
||||
if(material_hit)
|
||||
{
|
||||
Log::verbose("Attachment", "Drop a small bubble gum. \n");;
|
||||
//TODO: drop a bubble gum item on the track
|
||||
}
|
||||
normal.normalize();
|
||||
|
||||
pos.setY(hit_point.getY()-0.05f);
|
||||
|
||||
ItemManager::get()->newItem(Item::ITEM_BUBBLEGUM, pos, normal, m_kart);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} // switch
|
||||
|
@ -98,6 +98,9 @@ private:
|
||||
/** Ticking sound for the bomb */
|
||||
SFXBase *m_bomb_sound;
|
||||
|
||||
/** Soung for exploding bubble gum shield */
|
||||
SFXBase *m_bubble_explode_sound;
|
||||
|
||||
public:
|
||||
Attachment(AbstractKart* kart);
|
||||
~Attachment();
|
||||
|
@ -217,8 +217,7 @@ bool Bowling::hit(AbstractKart* kart, PhysicalObject* obj)
|
||||
{
|
||||
if(kart && kart->isShielded())
|
||||
{
|
||||
kart->decreaseShieldTime(0.0f); //Decreasing the shield time by the default value.
|
||||
Log::verbose("Bowling", "Decreasing shield!");
|
||||
kart->decreaseShieldTime();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -173,8 +173,7 @@ bool Cake::hit(AbstractKart* kart, PhysicalObject* obj)
|
||||
{
|
||||
if(kart && kart->isShielded())
|
||||
{
|
||||
kart->decreaseShieldTime(0.0f); //Decreasing the shield time by the default value.
|
||||
Log::verbose("Cake", "Decreasing shield! \n");
|
||||
kart->decreaseShieldTime();
|
||||
return false; //Not sure if a shield hit is a real hit.
|
||||
}
|
||||
explode(kart, obj);
|
||||
|
@ -179,14 +179,7 @@ bool Plunger::updateAndDelete(float dt)
|
||||
bool Plunger::hit(AbstractKart *kart, PhysicalObject *obj)
|
||||
{
|
||||
if(isOwnerImmunity(kart)) return false;
|
||||
|
||||
/*if(kart && kart->isShielded())
|
||||
{
|
||||
//kart->decreaseShieldTime(0.0f); //Decreasing the shield time by the default value.
|
||||
Log::verbose("Plunger", "Almost Decreasing shield! \n");
|
||||
|
||||
return false; //Not sure if a shield hit is a real hit.
|
||||
}*/
|
||||
|
||||
RaceGUIBase* gui = World::getWorld()->getRaceGUI();
|
||||
irr::core::stringw hit_message;
|
||||
|
||||
|
@ -368,8 +368,7 @@ void Powerup::use()
|
||||
if(kart->isEliminated() || kart== m_owner) continue;
|
||||
if(kart->isShielded())
|
||||
{
|
||||
kart->decreaseShieldTime(stk_config->m_bubblegum_shield_time);
|
||||
Log::verbose("Powerup", "Decreasing shield \n");
|
||||
kart->decreaseShieldTime();
|
||||
continue;
|
||||
}
|
||||
if(m_owner->getPosition() > kart->getPosition())
|
||||
|
@ -721,14 +721,9 @@ bool RubberBall::hit(AbstractKart* kart, PhysicalObject* object)
|
||||
bool was_real_hit = Flyable::hit(kart, object);
|
||||
if(was_real_hit)
|
||||
{
|
||||
/*if(kart && kart->isShielded() && kart->getShieldTime() > stk_config->m_bubblegum_shield_time )
|
||||
{ //remove twice the default shield time
|
||||
kart->decreaseShieldTime(stk_config->m_bubblegum_shield_time * 2);
|
||||
Log::verbose("rubber_ball", "Decreasing shield 1! \n");
|
||||
}
|
||||
else */if(kart && kart->isShielded())
|
||||
if(kart && kart->isShielded())
|
||||
{
|
||||
kart->decreaseShieldTime(stk_config->m_bubblegum_shield_time);
|
||||
kart->decreaseShieldTime();
|
||||
//kart->getAttachment()->update(0.0f);
|
||||
//kart->setSquash(m_st_squash_duration, m_st_squash_slowdown);
|
||||
Log::verbose("rubber_ball", "Decreasing shield 2! \n");
|
||||
|
@ -247,9 +247,8 @@ void RubberBand::hit(AbstractKart *kart_hit, const Vec3 *track_xyz)
|
||||
{
|
||||
if(kart_hit->isShielded())
|
||||
{
|
||||
kart_hit->decreaseShieldTime(0.0f); //Decreasing the shield time by the default value.
|
||||
kart_hit->decreaseShieldTime();
|
||||
m_plunger->setKeepAlive(0.0f);
|
||||
Log::verbose("rubber_band", "Decreasing shield! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -386,8 +386,7 @@ public:
|
||||
virtual float getShieldTime() const = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Decreases the kart's shield time. */
|
||||
//Hard coded shield decrease time
|
||||
virtual void decreaseShieldTime(float t) = 0;
|
||||
virtual void decreaseShieldTime() = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Shows the star effect for a certain time. */
|
||||
@ -415,9 +414,7 @@ public:
|
||||
/** Set a text that is displayed on top of a kart.
|
||||
*/
|
||||
virtual void setOnScreenText(const wchar_t *text) = 0;
|
||||
/** Whether an unused bubble gum shield becomes a bubble gum on the ground.
|
||||
* */
|
||||
bool m_bubble_drop;
|
||||
|
||||
}; // AbstractKart
|
||||
|
||||
|
||||
|
@ -38,12 +38,7 @@ ExplosionAnimation *ExplosionAnimation::create(AbstractKart *kart,
|
||||
bool direct_hit)
|
||||
{
|
||||
if(kart->isInvulnerable()) return NULL;
|
||||
/*else if(kart->isShielded() && !direct_hit) //How can I test this code ??
|
||||
{
|
||||
kart->decreaseShieldTime(0.0f); //Decreasing the shield time by the default value.
|
||||
Log::verbose("ExlosionAnimation", "Decreasing shield \n");
|
||||
return NULL;
|
||||
}*/
|
||||
|
||||
float r = kart->getKartProperties()->getExplosionRadius();
|
||||
|
||||
// Ignore explosion that are too far away.
|
||||
@ -61,8 +56,7 @@ ExplosionAnimation *ExplosionAnimation::create(AbstractKart *kart)
|
||||
if(kart->isInvulnerable()) return NULL;
|
||||
else if(kart->isShielded())
|
||||
{
|
||||
kart->decreaseShieldTime(0.0f) ; //decreasing the shieldtime by the default amount
|
||||
Log::verbose("ExplosionAnimation", "Decreasing shield 2\n");
|
||||
kart->decreaseShieldTime();
|
||||
return NULL;
|
||||
}
|
||||
return new ExplosionAnimation(kart, kart->getXYZ(), /*direct hit*/true);
|
||||
|
@ -526,8 +526,7 @@ void Kart::blockViewWithPlunger()
|
||||
m_kart_properties->getPlungerInFaceTime();
|
||||
if(isShielded())
|
||||
{
|
||||
decreaseShieldTime(0.0f); //decrease the default amount of time
|
||||
Log::verbose("Kart", "Decreasing shield, because of removing the plunger. \n");
|
||||
decreaseShieldTime();
|
||||
}
|
||||
} // blockViewWithPlunger
|
||||
|
||||
@ -1003,24 +1002,12 @@ float Kart::getShieldTime() const
|
||||
* Decreases the kart's shield time.
|
||||
* \param t The time substracted from the shield timer. If t == 0.0f, the default amout of time is substracted.
|
||||
*/
|
||||
void Kart::decreaseShieldTime(float t)
|
||||
void Kart::decreaseShieldTime()
|
||||
{
|
||||
if(isShielded())
|
||||
if (isShielded())
|
||||
{
|
||||
getAttachment()->setTimeLeft( getAttachment()->getTimeLeft() - t );
|
||||
if(t == 0.0f)
|
||||
{
|
||||
getAttachment()->setTimeLeft( getAttachment()->getTimeLeft()
|
||||
- stk_config->m_bubblegum_shield_time);
|
||||
}
|
||||
|
||||
getAttachment()->setTimeLeft(0.0f);
|
||||
}
|
||||
//Let the kart drop a bubble gum, if the shield was not damaged.
|
||||
//This is the default, whenever a powerup is used by a kart.
|
||||
//It is turned off, if the shield was reduced below zero by a hit. (Or by intently damaging the shield.)
|
||||
if(!isShielded())
|
||||
m_bubble_drop = false;
|
||||
|
||||
} // decreaseShieldTime
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1170,7 +1157,6 @@ void Kart::update(float dt)
|
||||
// since use() can test if something needs to be switched on/off.
|
||||
m_powerup->use() ;
|
||||
World::getWorld()->onFirePressed(getController());
|
||||
m_bubble_drop = true;
|
||||
m_fire_clicked = 1;
|
||||
}
|
||||
|
||||
@ -1355,8 +1341,7 @@ void Kart::setSquash(float time, float slowdown)
|
||||
|
||||
if (isShielded())
|
||||
{
|
||||
decreaseShieldTime(stk_config->m_bubblegum_shield_time/2.0f);
|
||||
Log::verbose("Kart", "Decreasing shield \n");
|
||||
decreaseShieldTime();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -409,8 +409,7 @@ public:
|
||||
virtual float getShieldTime() const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Decreases the kart's shield time. */
|
||||
//If t = 0.0f: decrease shield time by the default amount.
|
||||
virtual void decreaseShieldTime(float t);
|
||||
virtual void decreaseShieldTime();
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Sets the energy the kart has collected. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user