1) Added very first version of plunger with rubber band attached.

The rubber band doesn't do anything atm.
2) Bugfix: plungers could fly through the ground.



git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2522 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-11-28 03:32:47 +00:00
parent 5a9e06359d
commit c1fab8dc83
7 changed files with 213 additions and 14 deletions

View File

@ -57,18 +57,19 @@ supertuxkart_SOURCES = main.cpp \
material_manager.cpp material_manager.hpp \
grand_prix_manager.cpp grand_prix_manager.hpp \
items/attachment.cpp items/attachment.hpp \
items/attachment_manager.cpp items/attachment_manager.hpp \
items/powerup.cpp items/powerup.hpp \
items/powerup_manager.cpp items/powerup_manager.hpp \
items/item.cpp items/item.hpp \
items/item_manager.cpp items/item_manager.hpp \
items/projectile_manager.cpp items/projectile_manager.hpp \
items/attachment_manager.cpp items/attachment_manager.hpp \
items/powerup.cpp items/powerup.hpp \
items/powerup_manager.cpp items/powerup_manager.hpp \
items/item.cpp items/item.hpp \
items/item_manager.cpp items/item_manager.hpp \
items/projectile_manager.cpp items/projectile_manager.hpp \
items/bubblegumitem.cpp items/bubblegumitem.hpp \
items/plunger.cpp items/plunger.hpp \
items/cake.cpp items/cake.hpp \
items/bowling.cpp items/bowling.hpp \
karts/auto_kart.hpp karts/kart_control.hpp \
karts/kart.cpp karts/kart.hpp \
items/plunger.cpp items/plunger.hpp \
items/rubber_band.cpp items/rubber_band/hpp \
items/cake.cpp items/cake.hpp \
items/bowling.cpp items/bowling.hpp \
karts/auto_kart.hpp karts/kart_control.hpp \
karts/kart.cpp karts/kart.hpp \
karts/kart_model.cpp karts/kart_model.hpp \
karts/kart_properties.cpp karts/kart_properties.hpp \
karts/kart_properties_manager.cpp karts/kart_properties_manager.hpp \

View File

@ -178,7 +178,7 @@ RaceGUI::handle(GameAction ga, int value)
if (race_manager->getNumPlayers() ==1 )
{
Kart* kart = RaceManager::getPlayerKart(0);
kart->setPowerup(POWERUP_BUBBLEGUM, 10000);
kart->setPowerup(POWERUP_PLUNGER, 10000);
}
break;
case GA_DEBUG_ADD_HOMING:

View File

@ -1146,6 +1146,10 @@
RelativePath="..\..\items\projectile_manager.cpp"
>
</File>
<File
RelativePath="..\..\items\rubber_band.cpp"
>
</File>
</Filter>
<Filter
Name="physics"
@ -1760,6 +1764,10 @@
RelativePath="..\..\items\projectile_manager.hpp"
>
</File>
<File
RelativePath="..\..\items\rubber_band.hpp"
>
</File>
</Filter>
<Filter
Name="physics"

View File

@ -18,10 +18,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "items/plunger.hpp"
#include "constants.hpp"
#include "coord.hpp"
#include "karts/player_kart.hpp"
#include "camera.hpp"
#include "items/rubber_band.hpp"
#include "karts/player_kart.hpp"
// -----------------------------------------------------------------------------
Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
@ -34,8 +36,17 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER)
createPhysics(y_offset, btVector3(0.0f, m_speed*2, 0.0f),
new btCylinderShape(0.5f*m_extend), false, false, reverse_mode );
m_rubber_band = new RubberBand(this, *kart);
m_rubber_band->ref();
} // Plunger
// -----------------------------------------------------------------------------
Plunger::~Plunger()
{
m_rubber_band->removeFromScene();
ssgDeRefDelete(m_rubber_band);
} // ~Plunger
// -----------------------------------------------------------------------------
void Plunger::init(const lisp::Lisp* lisp, ssgEntity *plunger_model)
{
@ -46,5 +57,6 @@ void Plunger::init(const lisp::Lisp* lisp, ssgEntity *plunger_model)
void Plunger::update(float dt)
{
Flyable::update(dt);
m_rubber_band->update(dt);
} // update
// -----------------------------------------------------------------------------

View File

@ -22,10 +22,15 @@
#include "flyable.hpp"
class RubberBand;
class Plunger : public Flyable
{
private:
RubberBand *m_rubber_band;
public:
Plunger(Kart *kart);
Plunger(Kart *kart);
~Plunger();
static void init (const lisp::Lisp* lisp, ssgEntity* missile);
virtual void update (float dt);

129
src/items/rubber_band.cpp Executable file
View File

@ -0,0 +1,129 @@
// $Id: rubber_band.hpp 2458 2008-11-15 02:12:28Z auria $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2008 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "rubber_band.hpp"
#include "material_manager.hpp"
#include "race_manager.hpp"
#include "scene.hpp"
#include "items/plunger.hpp"
#include "modes/world.hpp"
#include "karts/kart.hpp"
#include "physics/physics.hpp"
/** RubberBand constructor. It creates a simple quad and attaches it to the
* root(!) of the graph. It's easier this way to get the right coordinates
* than attaching it to the plunger or kart, and trying to find the other
* coordinate.
* \param plunger Pointer to the plunger (non const, since the rubber band
* can trigger an explosion)
* \param kart Reference to the kart.
*/
RubberBand::RubberBand(Plunger *plunger, const Kart &kart)
: ssgVtxTable(GL_QUADS, new ssgVertexArray,
new ssgNormalArray,
new ssgTexCoordArray,
new ssgColourArray ),
m_plunger(plunger), m_kart(kart)
{
#ifdef DEBUG
setName("rubber_band");
#endif
// 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);
update(0);
sgVec3 norm;
sgSetVec3(norm, 1/sqrt(2.0f), 0, 1/sqrt(2.0f));
normals->add(norm);normals->add(norm);
normals->add(norm);normals->add(norm);
sgVec4 colour;
sgSetVec4(colour, 0.7f, 0.0f, 0.0f, 0.3f);
colours->add(colour);colours->add(colour);
colours->add(colour);colours->add(colour);
m_state = new ssgSimpleState();
m_state->disable(GL_CULL_FACE);
setState(m_state);
//setState(material_manager->getMaterial("chrome.rgb")->getState());
scene->add(this);
} // RubberBand
// ----------------------------------------------------------------------------
/** Removes the rubber band from the scene. Is called when the plunger
* explodes.
*/
void RubberBand::removeFromScene()
{
scene->remove(this);
} // removeFromScene
// ----------------------------------------------------------------------------
/** Updates the rubber band. It takes the new position of the kart and the
* plunger, and sets the quad representing the rubber band appropriately.
* It then casts a ray along the rubber band to detect if anything is hit. If
* so, an explosion is triggered.
* \param dt: Time step size.
*/
void RubberBand::update(float dt)
{
const Vec3 &p=m_plunger->getXYZ();
const Vec3 &k=m_kart.getXYZ();
Vec3 diff=p-k;
// See if anything hits the rubber band, but only if there is a certain
// distance between plunger and kart. Otherwise the raycast will either
// hit the kart or the plunger.
if(diff.length2()>2.0f)
{
diff.normalize();
const Vec3 from=k+diff; // this could be made dependent on kart length
const Vec3 to = p-diff;
btCollisionWorld::ClosestRayResultCallback ray_callback(from, to);
RaceManager::getWorld()->getPhysics()->getPhysicsWorld()->rayTest(from,
to, ray_callback);
if(ray_callback.HasHit())
{
m_plunger->explode(NULL);
return;
}
}
// Otherwise set the new coordinates for the plunger and the kart:
// ---------------------------------------------------------------
// 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
float *f = vertices->get(0);
f[0] = p.getX()-hh; f[1] = p.getY(); f[2] = p.getZ()-hh;
f = vertices->get(1);
f[0] = p.getX()+hh; f[1] = p.getY(); f[2] = p.getZ()+hh;
f = vertices->get(2);
f[0] = k.getX()+hh; f[1] = k.getY(); f[2] = k.getZ()+hh;
f = vertices->get(3);
f[0] = k.getX()-hh; f[1] = k.getY(); f[2] = k.getZ()-hh;
dirtyBSphere();
} // update
// ----------------------------------------------------------------------------

44
src/items/rubber_band.hpp Executable file
View File

@ -0,0 +1,44 @@
// $Id: rubber_band.hpp 2458 2008-11-15 02:12:28Z auria $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2008 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_RUBBER_BAND_HPP
#define HEADER_RUBBER_BAND_HPP
/** This class is used together with the pluger to display a rubber band from
* the shooting kart to the plunger.
*/
#define _WINSOCKAPI_
#include <plib/ssg.h>
class Kart;
class Plunger;
class RubberBand : public ssgVtxTable
{
private:
Plunger *m_plunger;
const Kart &m_kart;
ssgSimpleState *m_state;
public:
RubberBand(Plunger *plunger, const Kart &kart);
void update(float dt);
void removeFromScene();
}; // RubberBand
#endif