Cosmetic changes only (style, comments, ...).

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9869 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-09-20 01:44:27 +00:00
parent b7b1c02bb0
commit e371a273d6
3 changed files with 49 additions and 34 deletions

View File

@ -63,8 +63,8 @@ Cake::Cake (Kart *kart) : Flyable(kart, PowerupManager::POWERUP_CAKE)
const bool backwards = kart->getControls().m_look_back; const bool backwards = kart->getControls().m_look_back;
const Kart *closest_kart=NULL; const Kart *closest_kart=NULL;
Vec3 direction; Vec3 direction;
float kartDistSquared; float kart_dist_squared;
getClosestKart(&closest_kart, &kartDistSquared, &direction, getClosestKart(&closest_kart, &kart_dist_squared, &direction,
kart /* search in front of this kart */, backwards); kart /* search in front of this kart */, backwards);
// aim at this kart if 1) it's not too far, 2) if the aimed kart's speed // aim at this kart if 1) it's not too far, 2) if the aimed kart's speed
@ -73,7 +73,7 @@ Cake::Cake (Kart *kart) : Flyable(kart, PowerupManager::POWERUP_CAKE)
// this code finds the correct angle and upwards velocity to hit an opponents' // this code finds the correct angle and upwards velocity to hit an opponents'
// vehicle if they were to continue travelling in the same direction and same speed // vehicle if they were to continue travelling in the same direction and same speed
// (barring any obstacles in the way of course) // (barring any obstacles in the way of course)
if(closest_kart != NULL && kartDistSquared < m_st_max_distance_squared && if(closest_kart != NULL && kart_dist_squared < m_st_max_distance_squared &&
m_speed>closest_kart->getSpeed()) m_speed>closest_kart->getSpeed())
{ {
m_target = (Kart*)closest_kart; m_target = (Kart*)closest_kart;

View File

@ -43,6 +43,14 @@
#define SWAT_ANGLE_OFFSET (90.0f + 15.0f) #define SWAT_ANGLE_OFFSET (90.0f + 15.0f)
#define SWATTER_ANIMATION_SPEED 100.0f #define SWATTER_ANIMATION_SPEED 100.0f
/** Constructor: creates a swatter at a given attachment for a kart. If there
* was a bomb attached, it triggers the replace bomb animations.
* \param attachment The attachment instance where the swatter is attached to.
* \param kart The kart to which the swatter is attached.
* \param was_bomb True if the kart had a bomv as attachment.
* \param bomb_scene_node The scene node of the bomb (i.e. the previous
* attachment scene node).
*/
Swatter::Swatter(Attachment *attachment, Kart *kart, bool was_bomb, Swatter::Swatter(Attachment *attachment, Kart *kart, bool was_bomb,
scene::ISceneNode* bomb_scene_node) scene::ISceneNode* bomb_scene_node)
: AttachmentPlugin(attachment, kart) : AttachmentPlugin(attachment, kart)
@ -72,7 +80,9 @@ Swatter::Swatter(Attachment *attachment, Kart *kart, bool was_bomb,
m_swat_sound = sfx_manager->createSoundSource("swatter"); m_swat_sound = sfx_manager->createSoundSource("swatter");
} // Swatter } // Swatter
//----------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Destructor, stops any playing sfx.
*/
Swatter::~Swatter() Swatter::~Swatter()
{ {
if (m_swat_sound) if (m_swat_sound)
@ -81,7 +91,7 @@ Swatter::~Swatter()
} }
} // ~Swatter } // ~Swatter
//----------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Updates an armed swatter: it checks for any karts that are close enough /** Updates an armed swatter: it checks for any karts that are close enough
* and not invulnerable, it swats the kart. * and not invulnerable, it swats the kart.
* \param dt Time step size. * \param dt Time step size.
@ -158,7 +168,8 @@ bool Swatter::updateAndTestFinished(float dt)
// Did we just finish the first part of the movement? // Did we just finish the first part of the movement?
if(current_frame >= middle_frame) if(current_frame >= middle_frame)
{ {
// Squash the karts and items around and change the current phase // Squash the karts and items around and
// change the current phase
squashThingsAround(); squashThingsAround();
m_animation_phase = SWATTER_FROM_TARGET; m_animation_phase = SWATTER_FROM_TARGET;
} }
@ -175,13 +186,18 @@ bool Swatter::updateAndTestFinished(float dt)
return false; return false;
} // updateAndTestFinished } // updateAndTestFinished
/** When the animation ends, the swatter is ready again */ // ----------------------------------------------------------------------------
/** When the animation ends, the swatter is ready again.
*/
void Swatter::onAnimationEnd() void Swatter::onAnimationEnd()
{ {
m_animation_phase = SWATTER_AIMING; m_animation_phase = SWATTER_AIMING;
} // onAnimationEnd } // onAnimationEnd
/** Determine the nearest kart or item and update the current target accordingly */ // ----------------------------------------------------------------------------
/** Determine the nearest kart or item and update the current target
* accordingly.
*/
void Swatter::chooseTarget() void Swatter::chooseTarget()
{ {
// TODO: for the moment, only handle karts... // TODO: for the moment, only handle karts...
@ -205,7 +221,9 @@ void Swatter::chooseTarget()
m_target = closest_kart; // may be NULL m_target = closest_kart; // may be NULL
} }
/** If there is a current target, point in its direction, otherwise adopt the default position */ // ----------------------------------------------------------------------------
/** If there is a current target, point in its direction, otherwise adopt the
* default position. */
void Swatter::pointToTarget() void Swatter::pointToTarget()
{ {
if(!m_target) if(!m_target)
@ -214,25 +232,31 @@ void Swatter::pointToTarget()
} }
else else
{ {
Vec3 swatter_to_target = m_target->getXYZ() - m_attachment->getNode()->getAbsolutePosition(); Vec3 swatter_to_target = m_target->getXYZ()
-m_attachment->getNode()->getAbsolutePosition();
float dy = -swatter_to_target.getZ(); float dy = -swatter_to_target.getZ();
float dx = swatter_to_target.getX(); float dx = swatter_to_target.getX();
float angle = SWAT_ANGLE_OFFSET + (atan2(dy, dx) - m_kart->getHeading()) * 180.0f/M_PI; float angle = SWAT_ANGLE_OFFSET + (atan2(dy, dx)-m_kart->getHeading())
* 180.0f/M_PI;
m_attachment->getNode()->setRotation(core::vector3df(0.0, angle, 0.0)); m_attachment->getNode()->setRotation(core::vector3df(0.0, angle, 0.0));
} }
} }
/** Squash karts or items that are around the end position (determined using a joint) of the swatter */ // ----------------------------------------------------------------------------
/** Squash karts or items that are around the end position (determined using
* a joint) of the swatter.
*/
void Swatter::squashThingsAround() void Swatter::squashThingsAround()
{ {
const KartProperties* kp = m_kart->getKartProperties(); const KartProperties* kp = m_kart->getKartProperties();
float min_dist2 = kp->getSwatterDistance2(); // Square of the minimum distance // Square of the minimum distance
float min_dist2 = kp->getSwatterDistance2();
const World* world = World::getWorld(); const World* world = World::getWorld();
scene::IAnimatedMeshSceneNode *node = m_attachment->getNode(); scene::IAnimatedMeshSceneNode *node = m_attachment->getNode();
// Get the node corresponding to the joint at the center of the swatter (by swatter, I mean // Get the node corresponding to the joint at the center of the swatter
// the thing hold in the hand, not the whole thing) // (by swatter, I mean the thing hold in the hand, not the whole thing)
scene::ISceneNode* swatter_node = node->getJointNode("Swatter"); scene::ISceneNode* swatter_node = node->getJointNode("Swatter");
assert(swatter_node); assert(swatter_node);
Vec3 swatter_pos = swatter_node->getAbsolutePosition(); Vec3 swatter_pos = swatter_node->getAbsolutePosition();
@ -260,7 +284,8 @@ void Swatter::squashThingsAround()
// make bomb explode // make bomb explode
kart->getAttachment()->update(10000); kart->getAttachment()->update(10000);
HitEffect *he = new Explosion(m_kart->getXYZ(), "explosion"); HitEffect *he = new Explosion(m_kart->getXYZ(),
"explosion");
if(m_kart->getController()->isPlayerController()) if(m_kart->getController()->isPlayerController())
he->setPlayerKartHit(); he->setPlayerKartHit();
projectile_manager->addHitEffect(he); projectile_manager->addHitEffect(he);

View File

@ -150,16 +150,6 @@ void EmergencyAnimation::handleExplosion(const Vec3 &pos, bool direct_hit)
if(m_kart->isInvulnerable()) if(m_kart->isInvulnerable())
return; return;
// !Funto! TODO: squash items with the swatter...should we do it here or in the Swatter class?
/* Attachment *a=m_kart->getAttachment();
if(a->getType()==Attachment::ATTACH_SWATTER &&
a->isSwatterReady())
{
a->swatItem();
return;
}
*/
m_xyz = m_kart->getXYZ(); m_xyz = m_kart->getXYZ();
// Ignore explosion that are too far away. // Ignore explosion that are too far away.
float r = m_kart->getKartProperties()->getExplosionRadius(); float r = m_kart->getKartProperties()->getExplosionRadius();