1) First working version of plunger with rubber bands.
2) Some projectile functions have been renamed (explode to hit etc), since not all projectiles might explode. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2574 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
1dc083872e
commit
e1aba93a50
@ -35,7 +35,7 @@
|
||||
(shortcut-length 120 ) ;; leaving the road and coming back on it more than
|
||||
;; 120 'meters" later is considered to be a shortcut
|
||||
(explosion-impulse 10000.0 ) ;; explosion impulse on not directly hit karts
|
||||
(explosion-impulse-objects 500.0 ) ;; explosion impulse for physics objects (smaller
|
||||
(explosion-impulse-objects 500.0) ;; explosion impulse for physics objects (smaller
|
||||
;; else a cone e.g. will be pushed way too far)
|
||||
|
||||
;; The following files are the defaults for karts
|
||||
@ -119,6 +119,9 @@
|
||||
(upright-tolerance 0.2)
|
||||
(upright-max-force 30)
|
||||
(track-connection-accel 2)
|
||||
(rubber-band-max-length 50) ;; Maximum length of rubber band
|
||||
(rubber-band-force 1500) ;; Force a plunger/rubber band applies to the kart(s).
|
||||
(rubber-band-duration 1) ;; Duration a rubber band acts.
|
||||
(camera-max-accel 10)
|
||||
(camera-max-brake 10)
|
||||
(camera-distance 3.5)
|
||||
|
@ -188,7 +188,7 @@ void Flyable::getClosestKart(const Kart **minKart, float *minDistSquared,
|
||||
void Flyable::update (float dt)
|
||||
{
|
||||
m_time_since_thrown += dt;
|
||||
if(m_max_lifespan > -1 && m_time_since_thrown > m_max_lifespan) explode(NULL);
|
||||
if(m_max_lifespan > -1 && m_time_since_thrown > m_max_lifespan) hit(NULL);
|
||||
|
||||
if(m_exploded) return;
|
||||
|
||||
@ -196,7 +196,7 @@ void Flyable::update (float dt)
|
||||
TerrainInfo::update(pos);
|
||||
if(getHoT()==Track::NOHIT)
|
||||
{
|
||||
explode(NULL); // flyable out of track boundary
|
||||
hit(NULL); // flyable out of track boundary
|
||||
return;
|
||||
}
|
||||
if(m_adjust_z_velocity)
|
||||
@ -231,17 +231,27 @@ void Flyable::updateFromServer(const FlyableInfo &f, float dt)
|
||||
} // updateFromServer
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
/** Returns true if the item hit the kart who shot it (to avoid that an item
|
||||
* that's too close to the shoter hits the shoter).
|
||||
* \param kart Kart who was hit.
|
||||
*/
|
||||
bool Flyable::isOwnerImmunity(const Kart* kart_hit) const
|
||||
{
|
||||
if(m_exploded) return;
|
||||
return m_owner_has_temporary_immunity &&
|
||||
kart_hit == m_owner &&
|
||||
m_time_since_thrown < 2.0f;
|
||||
} // isOwnerImmunity
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Flyable::hit(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
{
|
||||
// the owner of this flyable should not be hit by his own flyable
|
||||
if(m_owner_has_temporary_immunity && kart_hit == m_owner && m_time_since_thrown < 2.0f) return;
|
||||
if(m_exploded || isOwnerImmunity(kart_hit)) return;
|
||||
|
||||
m_has_hit_something=true;
|
||||
// Notify the projectile manager that this rocket has hit something.
|
||||
// The manager will create the appropriate explosion object.
|
||||
projectile_manager->explode();
|
||||
projectile_manager->notifyRemove();
|
||||
|
||||
// Now remove this projectile from the graph:
|
||||
ssgTransform *m = getModelTransform();
|
||||
@ -254,6 +264,10 @@ void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
RaceManager::getWorld()->getPhysics()->removeBody(getBody());
|
||||
m_exploded=true;
|
||||
|
||||
if(!needsExplosion()) return;
|
||||
|
||||
// Apply explosion effect
|
||||
// ----------------------
|
||||
for ( unsigned int i = 0 ; i < race_manager->getNumKarts() ; i++ )
|
||||
{
|
||||
Kart *kart = RaceManager::getKart(i);
|
||||
@ -271,6 +285,6 @@ void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
}
|
||||
}
|
||||
callback_manager->handleExplosion(pos_explosion, moving_physics);
|
||||
} // explode
|
||||
} // hit
|
||||
|
||||
/* EOF */
|
||||
|
@ -22,10 +22,12 @@
|
||||
|
||||
#include "moving_physics.hpp"
|
||||
#include "terrain_info.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "items/powerup_manager.hpp"
|
||||
#include "karts/moveable.hpp"
|
||||
|
||||
class FlyableInfo;
|
||||
class Kart;
|
||||
|
||||
class Flyable : public Moveable, public TerrainInfo
|
||||
{
|
||||
@ -101,11 +103,17 @@ public:
|
||||
void updateFromServer(const FlyableInfo &f, float dt);
|
||||
|
||||
virtual void hitTrack () {};
|
||||
void explode (Kart* kart, MovingPhysics* moving_physics=NULL);
|
||||
virtual void hit (Kart* kart, MovingPhysics* moving_physics=NULL);
|
||||
bool hasHit () { return m_has_hit_something; }
|
||||
void reset () { Moveable::reset(); }
|
||||
|
||||
virtual int getExplosionSound() const { return SFXManager::SOUND_EXPLOSION; }
|
||||
/** Indicates that something was hit and that this object must
|
||||
* be removed. */
|
||||
void setHasHit () { m_has_hit_something = true; }
|
||||
void reset () { Moveable::reset(); }
|
||||
bool isOwnerImmunity(const Kart *kart_hit) const;
|
||||
virtual int getExplosionSound() const { return SFXManager::SOUND_EXPLOSION; }
|
||||
/** Indicates if an explosion needs to be added if this flyable
|
||||
* is removed. */
|
||||
virtual bool needsExplosion() const {return true;}
|
||||
}; // Flyable
|
||||
|
||||
#endif
|
||||
|
@ -172,7 +172,7 @@ RaceGUI::handle(GameAction ga, int value)
|
||||
}
|
||||
break;
|
||||
case GA_DEBUG_ADD_MISSILE:
|
||||
if (race_manager->getNumPlayers() ==1 )
|
||||
//FIXME if (race_manager->getNumPlayers() ==1 )
|
||||
{
|
||||
Kart* kart = RaceManager::getPlayerKart(0);
|
||||
kart->setPowerup(POWERUP_PLUNGER, 10000);
|
||||
|
@ -17,6 +17,7 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "karts/kart.hpp"
|
||||
#include "items/cake.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
Cake (Kart *kart);
|
||||
static void init (const lisp::Lisp* lisp, ssgEntity* cake_model);
|
||||
virtual void update (float dt);
|
||||
virtual void hitTrack () { explode(NULL); }
|
||||
virtual void hitTrack () { hit(NULL); }
|
||||
// Kinematic objects are not allowed to have a velocity (assertion in
|
||||
// bullet), so we have to do our own velocity handling here
|
||||
virtual const btVector3 &getVelocity() const {return m_initial_velocity;}
|
||||
|
@ -21,8 +21,12 @@
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "camera.hpp"
|
||||
#include "race_manager.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "items/rubber_band.hpp"
|
||||
#include "items/projectile_manager.hpp"
|
||||
#include "karts/player_kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
|
||||
@ -37,6 +41,7 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
|
||||
new btCylinderShape(0.5f*m_extend), 0.0f /* gravity */, false /* rotates */, reverse_mode );
|
||||
m_rubber_band = new RubberBand(this, *kart);
|
||||
m_rubber_band->ref();
|
||||
m_keep_alive = -1;
|
||||
} // Plunger
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -55,7 +60,72 @@ void Plunger::init(const lisp::Lisp* lisp, ssgEntity *plunger_model)
|
||||
// -----------------------------------------------------------------------------
|
||||
void Plunger::update(float dt)
|
||||
{
|
||||
// In keep-alive mode, just update the rubber band
|
||||
if(m_keep_alive >= 0)
|
||||
{
|
||||
m_keep_alive -= dt;
|
||||
if(m_keep_alive<=0)
|
||||
{
|
||||
setHasHit();
|
||||
projectile_manager->notifyRemove();
|
||||
ssgTransform *m = getModelTransform();
|
||||
m->removeAllKids();
|
||||
scene->remove(m);
|
||||
}
|
||||
m_rubber_band->update(dt);
|
||||
return;
|
||||
}
|
||||
|
||||
// Else: update the flyable and rubber band
|
||||
Flyable::update(dt);
|
||||
m_rubber_band->update(dt);
|
||||
} // update
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Virtual function called when the plunger hits something.
|
||||
* The plunger is special in that it is not deleted when hitting an object.
|
||||
* Instead it stays around (though not as a graphical or physical object)
|
||||
* till the rubber band expires.
|
||||
* \param kart Pointer to the kart hit (NULL if not a kart).
|
||||
* \param mp Pointer to MovingPhysics object if hit (NULL otherwise).
|
||||
*/
|
||||
void Plunger::hit(Kart *kart, MovingPhysics *mp)
|
||||
{
|
||||
if(isOwnerImmunity(kart)) return;
|
||||
|
||||
m_keep_alive = m_owner->getKartProperties()->getRubberBandDuration();
|
||||
|
||||
// Make this object invisible by placing it faaar down. Not that if this
|
||||
// objects is simply removed from the scene graph, it might be auto-deleted
|
||||
// because the ref count reaches zero.
|
||||
Vec3 hell(0, 0, -10000);
|
||||
getModelTransform()->setTransform(hell.toFloat());
|
||||
RaceManager::getWorld()->getPhysics()->removeBody(getBody());
|
||||
|
||||
if(kart)
|
||||
{
|
||||
m_rubber_band->hit(kart);
|
||||
return;
|
||||
}
|
||||
else if(mp)
|
||||
{
|
||||
Vec3 pos(mp->getBody()->getWorldTransform().getOrigin());
|
||||
m_rubber_band->hit(NULL, &pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_rubber_band->hit(NULL, &(getXYZ()));
|
||||
}
|
||||
|
||||
} // hit
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Called when the plunger hits the track. In this case, notify the rubber
|
||||
* band, and remove the plunger (but keep it alive).
|
||||
*/
|
||||
void Plunger::hitTrack()
|
||||
{
|
||||
hit(NULL, NULL);
|
||||
} // hitTrack
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -23,18 +23,31 @@
|
||||
#include "flyable.hpp"
|
||||
|
||||
class RubberBand;
|
||||
class Kart;
|
||||
class MovingPhysics;
|
||||
|
||||
class Plunger : public Flyable
|
||||
{
|
||||
private:
|
||||
RubberBand *m_rubber_band;
|
||||
/** The rubber band attached to a plunger. */
|
||||
RubberBand *m_rubber_band;
|
||||
/** Timer to keep the plunger alive while the rubber band is working. */
|
||||
float m_keep_alive;
|
||||
|
||||
public:
|
||||
Plunger(Kart *kart);
|
||||
~Plunger();
|
||||
static void init (const lisp::Lisp* lisp, ssgEntity* missile);
|
||||
/** Sets the keep-alive value. Setting it to 0 will remove the plunger
|
||||
* at the next update - which is used if the rubber band snaps.
|
||||
*/
|
||||
void setKeepAlive(float t) {m_keep_alive = t;}
|
||||
virtual void update (float dt);
|
||||
virtual void hitTrack () { explode(NULL); }
|
||||
virtual void hitTrack ();
|
||||
virtual void hit (Kart *kart, MovingPhysics *mp=NULL);
|
||||
|
||||
/** A plunger does not explode if it is removed. */
|
||||
virtual bool needsExplosion() const {return false;}
|
||||
}; // Plunger
|
||||
|
||||
#endif
|
||||
|
@ -99,7 +99,10 @@ void ProjectileManager::update(float dt)
|
||||
while(p!=m_active_projectiles.end())
|
||||
{
|
||||
if(! (*p)->hasHit()) { p++; continue; }
|
||||
newExplosion((*p)->getXYZ(), (*p)->getExplosionSound() );
|
||||
if((*p)->needsExplosion())
|
||||
{
|
||||
newExplosion((*p)->getXYZ(), (*p)->getExplosionSound() );
|
||||
}
|
||||
Flyable *f=*p;
|
||||
Projectiles::iterator pNext=m_active_projectiles.erase(p); // returns the next element
|
||||
delete f;
|
||||
@ -174,7 +177,7 @@ void ProjectileManager::updateClient(float dt)
|
||||
if(f.m_exploded)
|
||||
{
|
||||
m_something_was_hit = true;
|
||||
(*i)->explode(NULL);
|
||||
(*i)->hit(NULL);
|
||||
}
|
||||
} // for i in m_active_projectiles
|
||||
|
||||
|
@ -52,7 +52,8 @@ private:
|
||||
public:
|
||||
ProjectileManager() {m_something_was_hit=false;}
|
||||
~ProjectileManager() {}
|
||||
void explode () {m_something_was_hit=true; }
|
||||
/** Notifies the projectile manager that something needs to be removed. */
|
||||
void notifyRemove () {m_something_was_hit=true; }
|
||||
void FinishedExplosion() {m_explosion_ended =true; }
|
||||
ssgSelector* getExplosionModel()
|
||||
{
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "race_manager.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "items/plunger.hpp"
|
||||
#include "items/projectile_manager.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "physics/physics.hpp"
|
||||
@ -40,7 +41,7 @@ RubberBand::RubberBand(Plunger *plunger, const Kart &kart)
|
||||
new ssgNormalArray,
|
||||
new ssgTexCoordArray,
|
||||
new ssgColourArray ),
|
||||
m_plunger(plunger), m_kart(kart)
|
||||
m_plunger(plunger), m_owner(kart)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
setName("rubber_band");
|
||||
@ -49,6 +50,7 @@ RubberBand::RubberBand(Plunger *plunger, const Kart &kart)
|
||||
// The call to update defines the actual coordinates, only the entries are added for now.
|
||||
vertices->add(0, 0, 0); vertices->add(0, 0, 0);
|
||||
vertices->add(0, 0, 0); vertices->add(0, 0, 0);
|
||||
m_attached_state = RB_TO_PLUNGER;
|
||||
update(0);
|
||||
|
||||
sgVec3 norm;
|
||||
@ -86,33 +88,21 @@ void RubberBand::removeFromScene()
|
||||
*/
|
||||
void RubberBand::update(float dt)
|
||||
{
|
||||
// Don't do anything for plungers who already hit something.
|
||||
if(m_plunger->hasHit()) return;
|
||||
Vec3 p;
|
||||
const Vec3 &k = m_owner.getXYZ();
|
||||
|
||||
const Vec3 &p = m_plunger->getXYZ();
|
||||
const Vec3 &k = m_kart.getXYZ();
|
||||
|
||||
btCollisionWorld::ClosestRayResultCallback ray_callback(k, p);
|
||||
// Disable raycast collision detection for this plunger and this kart!
|
||||
short int old_plunger_group = m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup;
|
||||
short int old_kart_group = m_kart.getBody()->getBroadphaseHandle()->m_collisionFilterGroup;
|
||||
m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
|
||||
m_kart.getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
|
||||
|
||||
// Do the raycast
|
||||
RaceManager::getWorld()->getPhysics()->getPhysicsWorld()->rayTest(k, p,
|
||||
ray_callback);
|
||||
// Reset collision groups
|
||||
m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_plunger_group;
|
||||
m_kart.getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_kart_group;
|
||||
if(ray_callback.HasHit())
|
||||
// Get the position to which the band is attached
|
||||
// ----------------------------------------------
|
||||
switch(m_attached_state)
|
||||
{
|
||||
m_plunger->explode(NULL);
|
||||
return;
|
||||
}
|
||||
case RB_TO_KART: p = m_hit_kart->getXYZ(); break;
|
||||
case RB_TO_TRACK: p = m_hit_position; break;
|
||||
case RB_TO_PLUNGER: p = m_plunger->getXYZ();
|
||||
checkForHit(k, p); break;
|
||||
} // switch(m_attached_state);
|
||||
|
||||
// Otherwise set the new coordinates for the plunger and the kart:
|
||||
// ---------------------------------------------------------------
|
||||
// Draw the rubber band
|
||||
// --------------------
|
||||
// Todo: make height dependent on length (i.e. rubber band gets
|
||||
// thinner). And call explosion if the band is too long.
|
||||
const float hh=.1f; // half height of the band
|
||||
@ -126,6 +116,89 @@ void RubberBand::update(float dt)
|
||||
f = vertices->get(3);
|
||||
f[0] = k.getX()-hh; f[1] = k.getY(); f[2] = k.getZ()-hh;
|
||||
dirtyBSphere();
|
||||
|
||||
// Check for rubber band snapping
|
||||
// ------------------------------
|
||||
float l = (p-k).length2();
|
||||
float max_len = m_owner.getKartProperties()->getRubberBandMaxLength();
|
||||
if(l>max_len*max_len)
|
||||
{
|
||||
// Rubber band snaps
|
||||
m_plunger->hit(NULL);
|
||||
// This causes the plunger to be removed at the next update
|
||||
m_plunger->setKeepAlive(0.0f);
|
||||
}
|
||||
|
||||
// Apply forces (if applicable)
|
||||
// ----------------------------
|
||||
if(m_attached_state!=RB_TO_PLUNGER)
|
||||
{
|
||||
float force = m_owner.getKartProperties()->getRubberBandForce();
|
||||
Vec3 diff = p-k;
|
||||
diff.normalize(); // diff can't be zero here
|
||||
m_owner.getBody()->applyCentralForce(diff*force);
|
||||
if(m_attached_state==RB_TO_KART)
|
||||
m_hit_kart->getBody()->applyCentralForce(diff*(-force));
|
||||
}
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Uses a raycast to see if anything has hit the rubber band.
|
||||
* \param k Position of the kart = one end of the rubber band
|
||||
* \param p Position of the plunger = other end of the rubber band.
|
||||
*/
|
||||
void RubberBand::checkForHit(const Vec3 &k, const Vec3 &p)
|
||||
{
|
||||
btCollisionWorld::ClosestRayResultCallback ray_callback(k, p);
|
||||
// Disable raycast collision detection for this plunger and this kart!
|
||||
short int old_plunger_group = m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup;
|
||||
short int old_kart_group = m_owner.getBody() ->getBroadphaseHandle()->m_collisionFilterGroup;
|
||||
m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
|
||||
m_owner.getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0;
|
||||
|
||||
// Do the raycast
|
||||
RaceManager::getWorld()->getPhysics()->getPhysicsWorld()->rayTest(k, p,
|
||||
ray_callback);
|
||||
// Reset collision groups
|
||||
m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_plunger_group;
|
||||
m_owner.getBody() ->getBroadphaseHandle()->m_collisionFilterGroup = old_kart_group;
|
||||
if(ray_callback.HasHit())
|
||||
{
|
||||
Vec3 pos(ray_callback.m_hitPointWorld);
|
||||
UserPointer *up = (UserPointer*)ray_callback.m_collisionObject->getUserPointer();
|
||||
if(up && up->is(UserPointer::UP_KART))
|
||||
hit(up->getPointerKart(), &pos);
|
||||
else
|
||||
hit(NULL, &pos);
|
||||
} // if raycast hast hit
|
||||
|
||||
} // checkForHit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** The plunger hit a kart or the track.
|
||||
* \param kart_hit The kart hit, or NULL if the track was hit.
|
||||
* \param track _xyz The coordinated where the track was hit (NULL if a kart
|
||||
* was hit.
|
||||
*/
|
||||
void RubberBand::hit(Kart *kart_hit, const Vec3 *track_xyz)
|
||||
{
|
||||
// More than one report of a hit. This can happen if the raycast detects
|
||||
// a hit as well as the bullet physics.
|
||||
if(m_attached_state!=RB_TO_PLUNGER) return;
|
||||
|
||||
// A kart was hit
|
||||
// ==============
|
||||
if(kart_hit)
|
||||
{
|
||||
m_hit_kart = kart_hit;
|
||||
m_attached_state = RB_TO_KART;
|
||||
return;
|
||||
}
|
||||
|
||||
// The track was hit
|
||||
// =================
|
||||
m_hit_position = *track_xyz;
|
||||
m_attached_state = RB_TO_TRACK;
|
||||
} // hit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -26,19 +26,36 @@
|
||||
#define _WINSOCKAPI_
|
||||
#include <plib/ssg.h>
|
||||
|
||||
#include "utils/vec3.hpp"
|
||||
class Kart;
|
||||
class Plunger;
|
||||
|
||||
class RubberBand : public ssgVtxTable
|
||||
{
|
||||
private:
|
||||
enum {RB_TO_PLUNGER, /**< Rubber band is attached to plunger. */
|
||||
RB_TO_KART, /**< Rubber band is attached to a kart hit. */
|
||||
RB_TO_TRACK} /**< Rubber band is attached to track. */
|
||||
m_attached_state;
|
||||
/** True if plunger was fired backwards. */
|
||||
bool m_is_backward;
|
||||
/** If rubber band is attached to track, the coordinates. */
|
||||
Vec3 m_hit_position;
|
||||
/** The plunger the rubber band is attached to. */
|
||||
Plunger *m_plunger;
|
||||
const Kart &m_kart;
|
||||
/** The kart who shot this plunger. */
|
||||
const Kart &m_owner;
|
||||
/** The kart a plunger might have hit. */
|
||||
Kart *m_hit_kart;
|
||||
/** State for rubber band. */
|
||||
ssgSimpleState *m_state;
|
||||
|
||||
void checkForHit(const Vec3 &k, const Vec3 &p);
|
||||
|
||||
public:
|
||||
RubberBand(Plunger *plunger, const Kart &kart);
|
||||
void update(float dt);
|
||||
void removeFromScene();
|
||||
void hit(Kart *kart_hit, const Vec3 *track_xyz=NULL);
|
||||
}; // RubberBand
|
||||
#endif
|
||||
|
@ -65,8 +65,10 @@ KartProperties::KartProperties() : m_icon_material(0)
|
||||
m_chassis_angular_damping = m_maximum_speed = m_suspension_rest =
|
||||
m_max_speed_reverse_ratio = m_jump_velocity = m_upright_tolerance =
|
||||
m_upright_max_force = m_suspension_travel_cm =
|
||||
m_track_connection_accel = m_min_speed_turn =
|
||||
m_angle_at_min = m_max_speed_turn = m_angle_at_max =
|
||||
m_track_connection_accel = m_min_speed_turn = m_angle_at_min =
|
||||
m_max_speed_turn = m_angle_at_max =
|
||||
m_rubber_band_max_length = m_rubber_band_force =
|
||||
m_rubber_band_duration =
|
||||
m_camera_max_accel = m_camera_max_brake =
|
||||
m_camera_distance = UNDEFINED;
|
||||
m_gravity_center_shift = Vec3(UNDEFINED);
|
||||
@ -247,6 +249,10 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
|
||||
lisp->get("upright-tolerance", m_upright_tolerance );
|
||||
lisp->get("upright-max-force", m_upright_max_force );
|
||||
lisp->get("track-connection-accel", m_track_connection_accel );
|
||||
lisp->get("rubber-band-max-length", m_rubber_band_max_length );
|
||||
lisp->get("rubber-band-force", m_rubber_band_force );
|
||||
lisp->get("rubber-band-duration", m_rubber_band_duration );
|
||||
|
||||
lisp->getVector("groups", m_groups );
|
||||
|
||||
// getVector appends to existing vectors, so a new one must be used to load
|
||||
@ -326,6 +332,9 @@ void KartProperties::checkAllSet(const std::string &filename)
|
||||
CHECK_NEG(m_upright_tolerance, "upright-tolerance" );
|
||||
CHECK_NEG(m_upright_max_force, "upright-max-force" );
|
||||
CHECK_NEG(m_track_connection_accel, "track-connection-accel" );
|
||||
CHECK_NEG(m_rubber_band_max_length, "rubber-band-max-length" );
|
||||
CHECK_NEG(m_rubber_band_force, "rubber-band-force" );
|
||||
CHECK_NEG(m_rubber_band_duration, "rubber-band-duration" );
|
||||
CHECK_NEG(m_camera_max_accel, "camera-max-accel" );
|
||||
CHECK_NEG(m_camera_max_brake, "camera-max-brake" );
|
||||
CHECK_NEG(m_camera_distance, "camera-distance" );
|
||||
|
@ -52,17 +52,17 @@ private:
|
||||
protected:
|
||||
// Display and gui
|
||||
// ---------------
|
||||
std::string m_name; /**< The human readable Name of the kart
|
||||
* driver. */
|
||||
std::string m_ident; /**< The computer readable-name of the kart
|
||||
* driver. */
|
||||
std::string m_icon_file; /**< Filename of icon that represents the kart
|
||||
* in the statusbar and the character select
|
||||
* screen. */
|
||||
std::string m_shadow_file; /**< Filename of the image file that contains
|
||||
* the shadow for this kart. */
|
||||
Vec3 m_color; /**< Color the represents the kart in the status
|
||||
* bar and on the track-view. */
|
||||
std::string m_name; /**< The human readable Name of the kart
|
||||
* driver. */
|
||||
std::string m_ident; /**< The computer readable-name of the
|
||||
* kart driver. */
|
||||
std::string m_icon_file; /**< Filename of icon that represents the
|
||||
* kart in the statusbar and the
|
||||
* character select screen. */
|
||||
std::string m_shadow_file; /**< Filename of the image file that
|
||||
* contains the shadow for this kart.*/
|
||||
Vec3 m_color; /**< Color the represents the kart in the
|
||||
* status bar and on the track-view. */
|
||||
|
||||
// Physic properties
|
||||
// -----------------
|
||||
@ -99,7 +99,11 @@ protected:
|
||||
*m_wheel_transform[4]; /**< The transform for the wheels, used
|
||||
* to rotate the wheels and display
|
||||
* the suspension in the race. */
|
||||
SFXManager::SFXType m_engine_sfx_type;
|
||||
float m_rubber_band_max_length;/**< Max. length of plunger rubber band.*/
|
||||
float m_rubber_band_force; /**< Force of an attached rubber band.*/
|
||||
float m_rubber_band_duration;/**< Duration a rubber band works. */
|
||||
|
||||
SFXManager::SFXType m_engine_sfx_type; /**< Engine sound effect. */
|
||||
|
||||
// bullet physics data
|
||||
// -------------------
|
||||
@ -182,13 +186,19 @@ public:
|
||||
float getChassisLinearDamping () const {return m_chassis_linear_damping; }
|
||||
float getChassisAngularDamping () const {return m_chassis_angular_damping; }
|
||||
float getMaximumSpeed () const {return m_maximum_speed; }
|
||||
const Vec3& getGravityCenterShift() const {return m_gravity_center_shift; }
|
||||
const Vec3&getGravityCenterShift() const {return m_gravity_center_shift; }
|
||||
float getSuspensionRest () const {return m_suspension_rest; }
|
||||
float getSuspensionTravelCM () const {return m_suspension_travel_cm; }
|
||||
float getJumpVelocity () const {return m_jump_velocity; }
|
||||
float getUprightTolerance () const {return m_upright_tolerance; }
|
||||
float getUprightMaxForce () const {return m_upright_max_force; }
|
||||
float getTrackConnectionAccel () const {return m_track_connection_accel; }
|
||||
/** Returns the maximum length of a rubber band before it breaks. */
|
||||
float getRubberBandMaxLength () const {return m_rubber_band_max_length; }
|
||||
/** Returns force a rubber band has when attached to a kart. */
|
||||
float getRubberBandForce () const {return m_rubber_band_force; }
|
||||
/** Returns the duration a rubber band is active for. */
|
||||
float getRubberBandDuration () const {return m_rubber_band_duration; }
|
||||
const std::vector<float>&
|
||||
getGearSwitchRatio () const {return m_gear_switch_ratio; }
|
||||
const std::vector<float>&
|
||||
|
@ -222,7 +222,7 @@ void MovingPhysics::reset()
|
||||
} // reset
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void MovingPhysics::handleExplosion(const btVector3& pos, bool direct_hit) {
|
||||
void MovingPhysics::handleExplosion(const Vec3& pos, bool direct_hit) {
|
||||
if(direct_hit) {
|
||||
btVector3 impulse(0.0f, 0.0f, stk_config->m_explosion_impulse_objects);
|
||||
m_body->applyCentralImpulse(impulse);
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "callback.hpp"
|
||||
#include "user_pointer.hpp"
|
||||
|
||||
class Vec3;
|
||||
|
||||
class MovingPhysics : public ssgTransform, public Callback
|
||||
{
|
||||
public:
|
||||
@ -46,8 +48,9 @@ public:
|
||||
void update (float dt);
|
||||
void init ();
|
||||
virtual void reset ();
|
||||
const char *getTypeName() {return "moving physics";}
|
||||
virtual void handleExplosion(const btVector3& pos, bool directHit);
|
||||
btRigidBody *getBody () { return m_body; }
|
||||
const char *getTypeName() { return "moving physics"; }
|
||||
virtual void handleExplosion(const Vec3& pos, bool directHit);
|
||||
}; // MovingPhysics
|
||||
|
||||
#endif
|
||||
|
@ -131,17 +131,17 @@ void Physics::update(float dt)
|
||||
}
|
||||
else if(p->b->is(UserPointer::UP_MOVING_PHYSICS))
|
||||
{
|
||||
p->a->getPointerFlyable()->explode(NULL, p->b->getPointerMovingPhysics());
|
||||
p->a->getPointerFlyable()->hit(NULL, p->b->getPointerMovingPhysics());
|
||||
|
||||
}
|
||||
else if(p->b->is(UserPointer::UP_KART)) // projectile hit kart
|
||||
{
|
||||
p->a->getPointerFlyable()->explode(p->b->getPointerKart());
|
||||
p->a->getPointerFlyable()->hit(p->b->getPointerKart());
|
||||
}
|
||||
else // projectile hits projectile
|
||||
{
|
||||
p->a->getPointerFlyable()->explode(NULL);
|
||||
p->b->getPointerFlyable()->explode(NULL);
|
||||
p->a->getPointerFlyable()->hit(NULL);
|
||||
p->b->getPointerFlyable()->hit(NULL);
|
||||
}
|
||||
}
|
||||
} // for all p in m_all_collisions
|
||||
|
Loading…
Reference in New Issue
Block a user