Added support for lose animations (and better support for other
animations). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5132 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -46,10 +46,10 @@
|
||||
#include "physics/btKart.hpp"
|
||||
#include "physics/btUprightConstraint.hpp"
|
||||
#include "physics/physics.hpp"
|
||||
#include "race/history.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/coord.hpp"
|
||||
#include "audio/sfx_manager.hpp"
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
// Disable warning for using 'this' in base member initializer list
|
||||
@@ -388,7 +388,7 @@ void Kart::reset()
|
||||
m_controller = m_saved_controller;
|
||||
m_saved_controller = NULL;
|
||||
}
|
||||
m_kart_properties->getKartModel()->setEndAnimation(false);
|
||||
m_kart_properties->getKartModel()->setAnimation(KartModel::AF_DEFAULT);
|
||||
m_view_blocked_by_plunger = 0.0;
|
||||
m_attachment.clear();
|
||||
m_powerup.reset();
|
||||
@@ -469,7 +469,11 @@ void Kart::finishedRace(float time)
|
||||
{
|
||||
// in modes that support it, start end animation
|
||||
setController(new EndController(this, m_controller->getPlayer()));
|
||||
m_kart_properties->getKartModel()->setEndAnimation(true);
|
||||
if(m_race_position<=0.5f*race_manager->getNumberOfKarts() ||
|
||||
m_race_position==1)
|
||||
m_kart_properties->getKartModel()->setAnimation(KartModel::AF_WIN_START);
|
||||
else
|
||||
m_kart_properties->getKartModel()->setAnimation(KartModel::AF_LOSE_START);
|
||||
|
||||
// Not all karts have a camera
|
||||
if (m_camera) m_camera->setMode(Camera::CM_REVERSE);
|
||||
@@ -485,8 +489,11 @@ void Kart::finishedRace(float time)
|
||||
{
|
||||
// start end animation
|
||||
setController(new EndController(this, m_controller->getPlayer()));
|
||||
m_kart_properties->getKartModel()->setEndAnimation(true);
|
||||
|
||||
if(m_race_position<=2)
|
||||
m_kart_properties->getKartModel()->setAnimation(KartModel::AF_WIN_START);
|
||||
else if(m_race_position>=0.7f*race_manager->getNumberOfKarts())
|
||||
m_kart_properties->getKartModel()->setAnimation(KartModel::AF_LOSE_START);
|
||||
|
||||
// Not all karts have a camera
|
||||
if (m_camera) m_camera->setMode(Camera::CM_REVERSE);
|
||||
|
||||
@@ -647,7 +654,8 @@ void Kart::handleExplosion(const Vec3& pos, bool direct_hit)
|
||||
//-----------------------------------------------------------------------------
|
||||
void Kart::update(float dt)
|
||||
{
|
||||
m_controller->update(dt);
|
||||
if(!history->replayHistory())
|
||||
m_controller->update(dt);
|
||||
if(m_camera)
|
||||
m_camera->update(dt);
|
||||
// if its view is blocked by plunger, decrease remaining time
|
||||
|
||||
@@ -52,6 +52,7 @@ KartModel::KartModel()
|
||||
for(unsigned int i=AF_BEGIN; i<=AF_END; i++)
|
||||
m_animation_frame[i]=-1;
|
||||
m_animation_speed = 15;
|
||||
m_current_animation = AF_DEFAULT;
|
||||
} // KartModel
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -64,12 +65,16 @@ void KartModel::loadInfo(const XMLNode &node)
|
||||
node.get("model-file", &m_model_filename);
|
||||
if(const XMLNode *animation_node=node.getNode("animations"))
|
||||
{
|
||||
animation_node->get("left", &m_animation_frame[AF_LEFT] );
|
||||
animation_node->get("straight", &m_animation_frame[AF_STRAIGHT] );
|
||||
animation_node->get("right", &m_animation_frame[AF_RIGHT] );
|
||||
animation_node->get("start-winning", &m_animation_frame[AF_WIN_START]);
|
||||
animation_node->get("end-winning", &m_animation_frame[AF_WIN_END] );
|
||||
animation_node->get("speed", &m_animation_speed );
|
||||
animation_node->get("left", &m_animation_frame[AF_LEFT] );
|
||||
animation_node->get("straight", &m_animation_frame[AF_STRAIGHT] );
|
||||
animation_node->get("right", &m_animation_frame[AF_RIGHT] );
|
||||
animation_node->get("start-winning", &m_animation_frame[AF_WIN_START] );
|
||||
animation_node->get("end-winning", &m_animation_frame[AF_WIN_END] );
|
||||
animation_node->get("start-losing", &m_animation_frame[AF_LOSE_START]);
|
||||
animation_node->get("end-losing", &m_animation_frame[AF_LOSE_END] );
|
||||
animation_node->get("start-explosion",&m_animation_frame[AF_LOSE_START]);
|
||||
animation_node->get("end-explosion", &m_animation_frame[AF_LOSE_END] );
|
||||
animation_node->get("speed", &m_animation_speed );
|
||||
}
|
||||
|
||||
if(const XMLNode *wheels_node=node.getNode("wheels"))
|
||||
@@ -113,6 +118,12 @@ void KartModel::loadModels(const KartProperties &kart_properties)
|
||||
std::string full_path = kart_properties.getKartDir()+"/"+m_model_filename;
|
||||
m_mesh = irr_driver->getAnimatedMesh(full_path);
|
||||
Vec3 min, max;
|
||||
if(!m_mesh)
|
||||
{
|
||||
printf("Problems loading mesh '%s' - aborting.\n",
|
||||
full_path.c_str());
|
||||
exit(-2);
|
||||
}
|
||||
MeshTools::minMax3D(m_mesh, &min, &max);
|
||||
Vec3 size = max-min;
|
||||
m_z_offset = min.getZ();
|
||||
@@ -222,21 +233,21 @@ void KartModel::setDefaultPhysicsPosition(const Vec3 ¢er_shift,
|
||||
/** Enables- or disables the end animation.
|
||||
* \param status True if end animation should be played, false otherwise.
|
||||
*/
|
||||
void KartModel::setEndAnimation(bool status)
|
||||
void KartModel::setAnimation(AnimationFrameType type)
|
||||
{
|
||||
m_end_animation = status;
|
||||
if(!m_end_animation)
|
||||
m_current_animation = type;
|
||||
if(!m_current_animation==AF_DEFAULT)
|
||||
{
|
||||
m_node->setLoopMode(false);
|
||||
m_node->setFrameLoop(m_animation_frame[AF_STRAIGHT],
|
||||
m_animation_frame[AF_STRAIGHT] );
|
||||
}
|
||||
|
||||
if(m_end_animation && m_animation_frame[AF_WIN_START]>-1 &&
|
||||
m_animation_frame[AF_WIN_END]>-1)
|
||||
if(m_current_animation!=AF_DEFAULT && m_animation_frame[type]>-1)
|
||||
{
|
||||
m_node->setFrameLoop(m_animation_frame[AF_WIN_START],
|
||||
m_animation_frame[AF_WIN_END] );
|
||||
AnimationFrameType end = (AnimationFrameType)(type+1);
|
||||
m_node->setFrameLoop(m_animation_frame[type],
|
||||
m_animation_frame[end] );
|
||||
m_node->setLoopMode(true);
|
||||
m_node->setAnimationSpeed(m_animation_speed);
|
||||
}
|
||||
@@ -288,7 +299,7 @@ void KartModel::update(float rotation, float visual_steer,
|
||||
|
||||
// Check if the end animation is being played, if so, don't
|
||||
// play steering animation.
|
||||
if(m_end_animation) return;
|
||||
if(m_current_animation!=AF_DEFAULT) return;
|
||||
|
||||
if(m_animation_frame[AF_LEFT]<0) return; // no animations defined
|
||||
|
||||
|
||||
@@ -38,17 +38,22 @@ class XMLNode;
|
||||
*/
|
||||
class KartModel
|
||||
{
|
||||
private:
|
||||
public:
|
||||
enum AnimationFrameType
|
||||
{AF_BEGIN, // First animation frame
|
||||
AF_LEFT = AF_BEGIN, // Steering to the left
|
||||
AF_STRAIGHT, // Going straight
|
||||
AF_RIGHT, // Steering to the right
|
||||
AF_WIN_START, // Begin of win animation
|
||||
AF_WIN_END, // End of win animation
|
||||
AF_END=AF_WIN_END, // Last animation frame
|
||||
AF_COUNT}; // Number of entries here
|
||||
|
||||
{AF_BEGIN, // First animation frame
|
||||
AF_DEFAULT = AF_BEGIN, // Default, i.e. steering animation
|
||||
AF_LEFT, // Steering to the left
|
||||
AF_STRAIGHT, // Going straight
|
||||
AF_RIGHT, // Steering to the right
|
||||
AF_LOSE_START, // Begin losing animation
|
||||
AF_LOSE_END, // End losing animation
|
||||
AF_BEGIN_EXPLOSION, // Begin explosion animation
|
||||
AF_END_EXPLOSION, // End explosion animation
|
||||
AF_WIN_START, // Begin of win animation
|
||||
AF_WIN_END, // End of win animation
|
||||
AF_END=AF_WIN_END, // Last animation frame
|
||||
AF_COUNT}; // Number of entries here
|
||||
private:
|
||||
/** Which frame number starts/end which animation. */
|
||||
int m_animation_frame[AF_COUNT];
|
||||
|
||||
@@ -69,7 +74,7 @@ private:
|
||||
std::string m_model_filename;
|
||||
|
||||
/** The four wheel models. */
|
||||
scene::IMesh *m_wheel_model[4];
|
||||
scene::IMesh *m_wheel_model[4];
|
||||
|
||||
/** The four scene nodes the wheels are attached to */
|
||||
scene::ISceneNode *m_wheel_node[4];
|
||||
@@ -99,8 +104,11 @@ private:
|
||||
of wheels in bullet is too large and looks strange). 1=no change, 2=half the amplitude */
|
||||
float m_dampen_suspension_amplitude[4];
|
||||
|
||||
/** True if the end animation is being shown. */
|
||||
bool m_end_animation;
|
||||
/** Which animation is currently being played. This is used to overwrite
|
||||
* the default steering animations while being in race. If this is set
|
||||
* to AF_DEFAULT the default steering animation is shown. */
|
||||
AnimationFrameType m_current_animation;
|
||||
|
||||
float m_kart_width; /**< Width of kart. */
|
||||
float m_kart_length; /**< Length of kart. */
|
||||
float m_kart_height; /**< Height of kart. */
|
||||
@@ -154,6 +162,6 @@ public:
|
||||
void setDefaultPhysicsPosition(const Vec3 ¢er_shift, float wheel_radius);
|
||||
|
||||
/** Enables- or disables the end animation. */
|
||||
void setEndAnimation(bool status);
|
||||
void setAnimation(AnimationFrameType type);
|
||||
}; // KartModel
|
||||
#endif
|
||||
|
||||
@@ -43,17 +43,25 @@ class KartProperties
|
||||
{
|
||||
private:
|
||||
/** Base directory for this kart. */
|
||||
std::string m_root;
|
||||
Material *m_icon_material; /**< The icon texture to use. */
|
||||
std::string m_root;
|
||||
|
||||
/** The icon texture to use. */
|
||||
Material *m_icon_material;
|
||||
|
||||
/** The kart model and wheels. It is mutable since the wheels of the
|
||||
* KartModel can rotate and turn, but otherwise the kart_properties
|
||||
* object is const. */
|
||||
mutable KartModel m_kart_model;
|
||||
std::vector<std::string> m_groups; /**< List of all groups the kart
|
||||
belongs to. */
|
||||
* KartModel can rotate and turn, and animations are played, but otherwise
|
||||
* the kart_properties object is const. */
|
||||
mutable KartModel m_kart_model;
|
||||
|
||||
/** List of all groups the kart belongs to. */
|
||||
std::vector<std::string> m_groups;
|
||||
static float UNDEFINED;
|
||||
float m_speed_angle_increase; /**< Increase of turn angle with speed. */
|
||||
int m_version; /**< Version of the .kart file. */
|
||||
|
||||
/** Increase of turn angle with speed. */
|
||||
float m_speed_angle_increase;
|
||||
|
||||
/** Version of the .kart file. */
|
||||
int m_version;
|
||||
|
||||
// SFX files
|
||||
// ---------------
|
||||
|
||||
Reference in New Issue
Block a user