Add 'push back on collision' effect

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10623 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2012-01-09 02:30:49 +00:00
parent d510a660f8
commit 513b021a6c
3 changed files with 61 additions and 11 deletions

View File

@@ -187,7 +187,30 @@ Material::Material(const XMLNode *node, int index)
node->get("sphere", &m_sphere_map );
node->get("high-adhesion", &m_high_tire_adhesion);
node->get("reset", &m_drive_reset );
node->get("crash-reset", &m_crash_reset );
// backwards compatibility
bool crash_reset = false;
node->get("crash-reset", &crash_reset );
if (crash_reset)
{
m_collision_reaction = RESCUE;
}
std::string creaction;
node->get("collision-reaction", &creaction);
if (creaction == "reset")
{
m_collision_reaction = RESCUE;
}
else if (creaction == "push")
{
m_collision_reaction = PUSH_BACK;
}
else if (creaction.size() > 0)
{
fprintf(stderr, "[Material] WARNING: Unknown collision reaction '%s'\n", creaction.c_str());
}
node->get("below-surface", &m_below_surface );
node->get("falling-effect", &m_falling_effect );
// A terrain with falling effect has to force a reset
@@ -207,9 +230,15 @@ Material::Material(const XMLNode *node, int index)
node->get("mask", &m_mask);
if (m_crash_reset)
if (m_collision_reaction != NORMAL)
{
node->get("crash-reset-particles", &m_crash_reset_particles);
node->get("collision-particles", &m_collision_particles);
if (m_collision_particles.size() == 0)
{
// backwards compatibility
node->get("crash-reset-particles", &m_collision_particles);
}
}
bool use_normal_map = false;
@@ -369,7 +398,7 @@ void Material::init(unsigned int index)
m_surface = false;
m_ignore = false;
m_drive_reset = false;
m_crash_reset = false;
m_collision_reaction = NORMAL;
m_add = false;
m_disable_z_write = false;
m_fog = true;

View File

@@ -61,6 +61,13 @@ public:
EMIT_KINDS_COUNT
};
enum CollisionReaction
{
NORMAL,
RESCUE,
PUSH_BACK
};
private:
video::ITexture *m_texture;
unsigned int m_index;
@@ -89,10 +96,10 @@ private:
/** If a kart is rescued when driving on this surface. */
bool m_drive_reset;
/** If a kart is rescued when crashing into this surface. */
bool m_crash_reset;
CollisionReaction m_collision_reaction;
/** Particles to show on crash-reset */
std::string m_crash_reset_particles;
/** Particles to show on touch */
std::string m_collision_particles;
/** If the property should be ignored in the physics. Example would be
* plants that a kart can just drive through. */
@@ -219,9 +226,9 @@ public:
bool isDriveReset () const { return m_drive_reset; }
/** Returns if this material should trigger a rescue if a kart
* crashes against it. */
bool isCrashReset () const { return m_crash_reset; }
CollisionReaction getCollisionReaction() const { return m_collision_reaction; }
std::string getCrashResetParticles() const { return m_crash_reset_particles; }
std::string getCrashResetParticles() const { return m_collision_particles; }
bool highTireAdhesion () const { return m_high_tire_adhesion; }
const std::string&

View File

@@ -1445,7 +1445,7 @@ void Kart::crashed(Kart *k, const Material *m)
* long disabling of the engine. Therefore, this reaction is disabled
* for 0.5 seconds after a crash.
*/
if(m && m->isCrashReset() && !playingEmergencyAnimation())
if(m && m->getCollisionReaction() != Material::NORMAL && !playingEmergencyAnimation())
{
std::string particles = m->getCrashResetParticles();
if (particles.size() > 0)
@@ -1470,7 +1470,21 @@ void Kart::crashed(Kart *k, const Material *m)
}
}
forceRescue();
if (m->getCollisionReaction() == Material::RESCUE)
{
forceRescue();
}
else if (m->getCollisionReaction() == Material::PUSH_BACK)
{
if (m_bounce_back_time <= 0.0f)
{
btVector3 push = m_vehicle->getRigidBody()->getLinearVelocity().normalized();
push[1] = -0.1f;
m_vehicle->getRigidBody()->applyCentralImpulse( -4000.0f*push );
//m_vehicle->getRigidBody()->setLinearVelocity( -m_vehicle->getRigidBody()->getLinearVelocity() );
m_bounce_back_time = 2.0f;
}
}
}
if(World::getWorld()->getTime()-m_time_last_crash < 0.5f) return;