HAving some fun : you will now physically lose a tire in 3-strikes mode. Watch out for tires all over the place as the battle gets fierce ;)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9703 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-09-01 20:09:26 +00:00
parent dd24f83d02
commit 3e7aeaf71f
9 changed files with 140 additions and 3 deletions

View File

@ -24,6 +24,7 @@
#include "io/file_manager.hpp"
#include "states_screens/race_gui_base.hpp"
#include "tracks/track.hpp"
#include "tracks/track_object_manager.hpp"
//-----------------------------------------------------------------------------
@ -31,6 +32,7 @@ ThreeStrikesBattle::ThreeStrikesBattle() : WorldWithRank()
{
WorldStatus::setClockMode(CLOCK_CHRONO);
m_use_highscores = false;
m_insert_tire = false;
m_tire = irr_driver->getMesh( file_manager->getModelFile("tire.b3d") );
} // ThreeStrikesBattle
@ -166,6 +168,12 @@ void ThreeStrikesBattle::kartHit(const int kart_id)
curr->setVisible(m_kart_info[kart_id].m_lives >= 3);
}
}
// schedule a tire to be thrown away (but can't do it in this callback
// because the caller is currently iterating the list of track objects)
m_insert_tire = true;
core::vector3df wheel_pos(m_karts[kart_id]->getKartWidth()*0.5f, 0.0f, 0.0f);
m_tire_position = kart_node->getPosition() + wheel_pos;
} // kartHit
//-----------------------------------------------------------------------------
@ -184,6 +192,25 @@ void ThreeStrikesBattle::update(float dt)
{
WorldWithRank::update(dt);
WorldWithRank::updateTrack(dt);
// insert blown away tire now if was requested
if (m_insert_tire)
{
TrackObjectManager* tom = m_track->getTrackObjectManager();
PhysicalObject* obj =
tom->insertObject(file_manager->getModelFile("tire.b3d"),
PhysicalObject::MP_CYLINDER_Y,
15 /* mass */,
0.5f /* radius */,
core::vector3df(800.0f,0,0) /* rotation */,
m_tire_position,
core::vector3df(0.5f, 0.5f, 0.5f) /* scale */);
// FIXME: orient the force relative to kart orientation
obj->getBody()->applyCentralForce(btVector3(60.0f, 0.0f, 0.0f));
m_insert_tire = false;
}
} // update
//-----------------------------------------------------------------------------

View File

@ -46,6 +46,12 @@ private:
irr::scene::IMesh* m_tire;
/** for tires that are blown away */
bool m_insert_tire;
/** for tires that are blown away */
core::vector3df m_tire_position;
public:
/** Used to show a nice graph when battle is over */

View File

@ -40,7 +40,6 @@ using namespace irr;
PhysicalObject::PhysicalObject(const XMLNode &xml_node)
: TrackObject(xml_node)
{
m_shape = NULL;
m_body = NULL;
m_motion_state = NULL;
@ -77,6 +76,26 @@ PhysicalObject::PhysicalObject(const XMLNode &xml_node)
} // PhysicalObject
// -----------------------------------------------------------------------------
PhysicalObject::PhysicalObject(const std::string& model,
bodyTypes shape, int mass, int radius,
const core::vector3df& hpr,
const core::vector3df& pos,
const core::vector3df& scale)
: TrackObject(pos, hpr, scale, model)
{
m_body_type = shape;
m_mass = mass;
m_radius = radius;
m_init_pos.setIdentity();
btQuaternion q;
q.setEuler(hpr.Y, hpr.X, hpr.Z);
m_init_pos.setRotation(q);
m_init_pos.setOrigin(btVector3(pos.X, pos.Y, pos.Z));
}
// -----------------------------------------------------------------------------
PhysicalObject::~PhysicalObject()
{

View File

@ -68,6 +68,13 @@ protected:
float m_radius;
public:
PhysicalObject (const XMLNode &node);
PhysicalObject(const std::string& model,
bodyTypes shape, int mass, int radius,
const core::vector3df& hpr,
const core::vector3df& pos,
const core::vector3df& scale);
virtual ~PhysicalObject ();
void update (float dt);
void init ();

View File

@ -371,6 +371,8 @@ public:
// ------------------------------------------------------------------------
bool isFogEnabled() const { return m_use_fog; }
TrackObjectManager* getTrackObjectManager() { return m_track_object_manager; }
}; // class Track
#endif

View File

@ -135,6 +135,59 @@ TrackObject::TrackObject(const XMLNode &xml_node)
} // TrackObject
// ----------------------------------------------------------------------------
TrackObject::TrackObject(const core::vector3df& pos, const core::vector3df& hpr,
const core::vector3df& scale, const std::string& model_name)
{
m_init_xyz = pos;
m_init_hpr = hpr;
m_init_scale = scale;
m_enabled = true;
m_is_looped = false;
m_sound = NULL;
// Some animated objects (billboards, sound emitters) don't use this scene node
if (model_name == "")
{
m_node = NULL;
m_mesh = NULL;
}
else
{
if(file_manager->fileExists(model_name))
{
m_mesh = irr_driver->getAnimatedMesh(model_name);
}
if(!m_mesh)
{
fprintf(stderr, "Warning: '%s' not found and is ignored.\n",
model_name.c_str());
return;
}
m_mesh->grab();
irr_driver->grabAllTextures(m_mesh);
scene::IAnimatedMeshSceneNode *node=irr_driver->addAnimatedMesh(m_mesh);
m_node = node;
#ifdef DEBUG
std::string debug_name = model_name+" (track-object)";
m_node->setName(debug_name.c_str());
#endif
m_frame_start = node->getStartFrame();
m_frame_end = node->getEndFrame();
if(!m_enabled)
m_node->setVisible(false);
m_node->setPosition(m_init_xyz);
m_node->setRotation(m_init_hpr);
m_node->setScale(m_init_scale);
}
reset();
} // TrackObject
// ----------------------------------------------------------------------------
TrackObject::~TrackObject()
{
if(m_node)

View File

@ -30,7 +30,7 @@ using namespace irr;
#include "utils/no_copy.hpp"
#include "utils/vec3.hpp"
#include <string>
class XMLNode;
class SFXBase;
@ -86,6 +86,8 @@ protected:
public:
TrackObject(const XMLNode &xml_node);
TrackObject(const core::vector3df& pos, const core::vector3df& hpr,
const core::vector3df& scale, const std::string& model);
~TrackObject();
virtual void update(float dt);
virtual void reset();

View File

@ -189,3 +189,19 @@ void TrackObjectManager::enableFog(bool enable)
}
}
} // enableFog
// ----------------------------------------------------------------------------
PhysicalObject* TrackObjectManager::insertObject(const std::string& model,
PhysicalObject::bodyTypes shape, int mass, int radius,
const core::vector3df& hpr,
const core::vector3df& pos,
const core::vector3df& scale)
{
PhysicalObject* object = new PhysicalObject(model, shape, mass, radius, hpr, pos, scale);
object->init();
m_all_objects.push_back(object);
return object;
}

View File

@ -20,10 +20,10 @@
#ifndef HEADER_TRACK_OBJECT_MANAGER_HPP
#define HEADER_TRACK_OBJECT_MANAGER_HPP
#include "physics/physical_object.hpp"
#include "tracks/track_object.hpp"
#include "utils/ptr_vector.hpp"
class PhysicalObject;
class Track;
class Vec3;
class XMLNode;
@ -54,6 +54,11 @@ public:
/** Enable or disable fog on objects */
void enableFog(bool enable);
PhysicalObject* insertObject(const std::string& model,
PhysicalObject::bodyTypes shape, int mass, int radius,
const core::vector3df& hpr,
const core::vector3df& pos,
const core::vector3df& scale);
}; // class TrackObjectManager
#endif