Added referee in rescuing a kart. Note that at this

stage thunderbird still has the traffic light attached, and
the position of the bird in relation to the kart is not yet
ideal.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9903 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-09-27 11:46:27 +00:00
parent 8dd1dd5767
commit 29453de9fa
6 changed files with 70 additions and 27 deletions

View File

@ -425,9 +425,9 @@ void Camera::update(float dt)
getCameraSettings(&above_kart, &cam_angle, &side_way, &distance,
&smoothing);
// If an explosion or rescue is happening, stop moving the camera,
// If an explosion is happening, stop moving the camera,
// but keep it target on the kart.
if(m_kart->playingEmergencyAnimation())
if(m_kart->playingExplosionAnimation())
{
// The camera target needs to be 'smooth moved', otherwise
// there will be a noticable jump in the first frame

View File

@ -153,11 +153,9 @@ void Referee::cleanup()
// ----------------------------------------------------------------------------
/** Creates an instance of the referee, using the static values to initialise
* it.
* \param is_start_referee True when this is the start referee, i.e. it must
* have the traffic light attached.
* it. This is the constructor used when a start referee is needed.
*/
Referee::Referee(bool is_start_referee)
Referee::Referee()
{
assert(m_st_referee_mesh);
// First add a NULL mesh, then set the material to be read only
@ -166,16 +164,38 @@ Referee::Referee(bool is_start_referee)
// mesh. ATM it doesn't make any difference, but if we ever should
// decide to use more than one referee model at startup we only
// have to change the textures once, and all models will be in synch.
if(is_start_referee)
{
m_scene_node = irr_driver->addAnimatedMesh(NULL);
m_scene_node->setReadOnlyMaterials(true);
m_scene_node->setMesh(m_st_referee_mesh);
m_scene_node->grab();
m_scene_node->setRotation(m_st_start_rotation.toIrrVector());
m_scene_node->setScale(m_st_scale.toIrrVector());
m_scene_node->setFrameLoop(m_st_first_start_frame, m_st_last_start_frame);
}
m_scene_node->setFrameLoop(m_st_first_start_frame,
m_st_last_start_frame);
} // Referee
// ----------------------------------------------------------------------------
/** Creates an instance of the referee, using the static values to initialise
* it. This is the constructor used when a rescue referee is needed.
* \param kart The kart which the referee should rescue.
*/
Referee::Referee(const Kart &kart)
{
assert(m_st_referee_mesh);
// First add a NULL mesh, then set the material to be read only
// (this appears to be the only way to get read only materials).
// This way we only need to adjust the materials in the original
// mesh. ATM it doesn't make any difference, but if we ever should
// decide to use more than one referee model at startup we only
// have to change the textures once, and all models will be in synch.
m_scene_node = irr_driver->addAnimatedMesh(NULL);
m_scene_node->setReadOnlyMaterials(true);
m_scene_node->setMesh(m_st_referee_mesh);
m_scene_node->grab();
m_scene_node->setScale(m_st_scale.toIrrVector());
m_scene_node->setPosition(core::vector3df(0,kart.getKartHeight(), 0));
m_scene_node->setFrameLoop(m_st_first_rescue_frame,
m_st_last_rescue_frame);
} // Referee
// ----------------------------------------------------------------------------

View File

@ -78,7 +78,8 @@ private:
scene::IAnimatedMeshSceneNode *m_scene_node;
public:
Referee(bool is_start_referee);
Referee();
Referee(const Kart &kart);
~Referee();
void selectReadySetGo(int rsg);
void attachToSceneNode();
@ -86,6 +87,9 @@ public:
static void cleanup();
void removeFromSceneGraph();
// ------------------------------------------------------------------------
/** Returns the scene node of this referee. */
scene::IAnimatedMeshSceneNode* getSceneNode() { return m_scene_node; }
// ------------------------------------------------------------------------
/** Moves the referee to the specified position. */
void setPosition(const Vec3 &xyz)
{m_scene_node->setPosition(xyz.toIrrVector()); }

View File

@ -20,6 +20,7 @@
#include "karts/emergency_animation.hpp"
#include "graphics/camera.hpp"
#include "graphics/referee.hpp"
#include "graphics/stars.hpp"
#include "karts/kart.hpp"
#include "modes/world.hpp"
@ -35,6 +36,7 @@
EmergencyAnimation::EmergencyAnimation(Kart *kart)
{
m_stars_effect = NULL;
m_referee = NULL;
m_kart = kart;
// Setting kart mode here is important! If the mode should be rescue when
// reset() is called, it is assumed that this was triggered by a restart,
@ -79,6 +81,11 @@ void EmergencyAnimation::reset()
m_timer = 0;
m_kart_mode = EA_NONE;
m_eliminated = false;
if(m_referee)
{
delete m_referee;
m_referee = NULL;
}
} // reset
//-----------------------------------------------------------------------------
@ -116,12 +123,15 @@ void EmergencyAnimation::forceRescue(bool is_auto_rescue)
{
if(playingEmergencyAnimation()) return;
assert(!m_referee);
m_referee = new Referee(*m_kart);
m_kart->getNode()->addChild(m_referee->getSceneNode());
m_kart_mode = EA_RESCUE;
m_timer = m_kart->getKartProperties()->getRescueTime();
m_up_velocity = m_kart->getKartProperties()->getRescueHeight() / m_timer;
m_xyz = m_kart->getXYZ();
m_kart->getAttachment()->set(Attachment::ATTACH_TINYTUX, m_timer);
m_kart->getAttachment()->clear();
m_curr_rotation.setPitch(m_kart->getPitch());
m_curr_rotation.setRoll(m_kart->getRoll() );
@ -221,6 +231,9 @@ void EmergencyAnimation::update(float dt)
if(m_kart_mode==EA_RESCUE)
{
World::getWorld()->moveKartAfterRescue(m_kart);
m_kart->getNode()->removeChild(m_referee->getSceneNode());
delete m_referee;
m_referee = NULL;
}
World::getWorld()->getPhysics()->addKart(m_kart);
m_kart->getBody()->setLinearVelocity(btVector3(0,0,0));

View File

@ -24,6 +24,7 @@
#include "utils/vec3.hpp"
class Kart;
class Referee;
class Stars;
/**
@ -71,6 +72,9 @@ protected:
/** For stars rotating around head effect */
Stars *m_stars_effect;
/** The referee during a rescue operation. */
Referee *m_referee;
/** Different kart modes: normal racing, being rescued, showing end
* animation, explosions, kart eliminated. */
enum {EA_NONE, EA_RESCUE, EA_EXPLOSION}
@ -82,23 +86,25 @@ public:
virtual void handleExplosion(const Vec3& pos, bool direct_hit);
virtual void forceRescue(bool is_auto_rescue=false);
void update(float dt);
void eliminate (bool remove);
// ------------------------------------------------------------------------
/** Returns true if an emergency animation is being played. */
bool playingEmergencyAnimation() const {return m_kart_mode!=EA_NONE; }
// ------------------------------------------------------------------------
/** Returns if a rescue animation is being shown. */
bool playingRescueAnimation() const {return m_kart_mode==EA_RESCUE; }
// ------------------------------------------------------------------------
/** Returns if an explosion animation is being shown. */
bool playingExplosionAnimation() const {return m_kart_mode==EA_EXPLOSION; }
bool playingExplosionAnimation() const {return m_kart_mode==EA_EXPLOSION;}
// ------------------------------------------------------------------------
/** Returns the timer for the currently played animation. */
const float getAnimationTimer() const {return m_timer;}
// ------------------------------------------------------------------------
/** Returns true if the kart is eliminated. */
bool isEliminated () const {return m_eliminated;}
// ------------------------------------------------------------------------
/** Returns a pointer to the stars effect. */
const Stars *getStarEffect () const {return m_stars_effect; }
void eliminate (bool remove);
}; // EmergencyAnimation
#endif

View File

@ -107,7 +107,7 @@ void RaceGUIBase::init()
m_referee_rotation.push_back(hpr);
}
m_referee = new Referee(/*is_start_referee*/true);
m_referee = new Referee();
// Do everything else required at a race restart as well, esp.
// resetting the height of the referee.