Started adding powerup functionality to irrlicht port.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3223 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-03-12 00:57:00 +00:00
parent 511be41e70
commit 01a9f73b54
21 changed files with 183 additions and 40 deletions

View File

@ -3,6 +3,7 @@
(tuxkart-collectable
(name "Bowling")
(model "bowling.ac")
(mesh "bowling.b3d")
(icon "bowling-icon.rgb")
(speed 4.0)
(min-height 0.2) ; height above terrain below which a ball is

View File

@ -3,6 +3,7 @@
(tuxkart-collectable
(name "cake")
(model "cake.ac")
(mesh "cake.b3d")
(icon "cake-icon.rgb")
(speed 50.0)
(min-height 0.2)

View File

@ -3,6 +3,7 @@
(tuxkart-collectable
(name "Plunger")
(model "plunger.ac")
(mesh "plunger.b3d")
(icon "plunger-icon.rgb")
(speed 35.0)
(min-height 0.2) ; height above terrain below which a plunger is

View File

@ -3,6 +3,7 @@
(tuxkart-collectable
(name "zipper")
(model "zipper.ac")
(mesh "zipper.b3d")
(icon "zipper_collect.rgb")
)

View File

@ -64,17 +64,19 @@ RaceGUI::RaceGUI()
icon_width = 27;
icon_player_width = 35;
}
#ifdef NOT_READY_YET
m_icons = new gui::IGUIImage*[race_manager->getNumKarts()];
for(unsigned int i=0; i<race_manager->getNumKarts(); i++)
{
core::position2d<s32> p(0, i*20);
Kart *kart = race_manager->getKart(i);
Material *m = kart->getKartProperties()->getIconMaterial();
m = material_manager->getMaterial("track.png");
// FIXME: The icons needs to be resized.
m_icons[i] = irr_driver->getGUI()->addImage(m->getTexture(), p);
}
#endif
core::rect<s32> p(user_config->m_width-10, 0,
user_config->m_width+10, 10);
m_attachment_icon = irr_driver->getGUI()->addImage(p);
#else
m_speed_back_icon = material_manager->getMaterial("speedback.rgb");
m_speed_back_icon->getState()->disable(GL_CULL_FACE);
@ -391,7 +393,9 @@ void RaceGUI::drawPowerupIcons ( Kart* player_kart, int offset_x,
int y1 = (int)(user_config->m_height*5/6 * ratio_y) + offset_y;
int nSize=(int)(64.0f*std::min(ratio_x, ratio_y));
#ifndef HAVE_IRRLICHT
#ifdef HAVE_IRRLICHT
m_attachment_icon->setImage(powerup->getIcon()->getTexture());
#else
powerup->getIcon()->apply();
int n = player_kart->getNumPowerup() ;

View File

@ -93,7 +93,8 @@ private:
private:
#ifdef HAVE_IRRLICHT
gui::IGUIStaticText *m_time;
gui::IGUIImage **m_icons;
gui::IGUIImage **m_icons;
gui::IGUIImage *m_attachment_icon;
#endif
ulClock m_fps_timer;
int m_fps_counter;

View File

@ -44,11 +44,19 @@ struct initAttachmentType {attachmentType attachment; const char *file;};
initAttachmentType iat[]=
{
#ifdef HAVE_IRRLICHT
{ATTACH_PARACHUTE, "parachute.b3d"},
{ATTACH_BOMB, "bomb.b3d"},
{ATTACH_ANVIL, "anvil.b3d"},
{ATTACH_TINYTUX, "tinytux_magnet.b3d"},
{ATTACH_MAX, ""},
#else
{ATTACH_PARACHUTE, "parachute.ac"},
{ATTACH_BOMB, "bomb.ac"},
{ATTACH_ANVIL, "anvil.ac"},
{ATTACH_TINYTUX, "tinytux_magnet.ac"},
{ATTACH_MAX, ""},
#endif
};
//-----------------------------------------------------------------------------

View File

@ -16,8 +16,8 @@
// 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_ATTACHMENT_MANAGER_H
#define HEADER_ATTACHMENT_MANAGER_H
#ifndef HEADER_ATTACHMENT_MANAGER_HPP
#define HEADER_ATTACHMENT_MANAGER_HPP
#include <plib/ssg.h>
#include "items/attachment.hpp"

View File

@ -70,7 +70,11 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */)
} // Bowling
// -----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
void Bowling::init(const lisp::Lisp* lisp, scene::IMesh *bowling)
#else
void Bowling::init(const lisp::Lisp* lisp, ssgEntity *bowling)
#endif
{
Flyable::init(lisp, bowling, POWERUP_BOWLING);
m_st_max_distance = 20.0f;

View File

@ -17,8 +17,13 @@
// 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_BOWLING_H
#define HEADER_BOWLING_H
#ifndef HEADER_BOWLING_HPP
#define HEADER_BOWLING_HPP
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#endif
#include "flyable.hpp"
@ -31,7 +36,11 @@ private:
public:
Bowling(Kart* kart);
#ifdef HAVE_IRRLICHT
static void init(const lisp::Lisp* lisp, scene::IMesh *bowling);
#else
static void init(const lisp::Lisp* lisp, ssgEntity* bowling);
#endif
virtual void update(float dt);
int getExplosionSound() const { return SFXManager::SOUND_BOWLING_STRIKE; }

View File

@ -107,7 +107,11 @@ Cake::Cake (Kart *kart) : Flyable(kart, POWERUP_CAKE)
} // Cake
// -----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
void Cake::init(const lisp::Lisp* lisp, scene::IMesh *cake_model)
#else
void Cake::init(const lisp::Lisp* lisp, ssgEntity *cake_model)
#endif
{
Flyable::init(lisp, cake_model, POWERUP_CAKE);
m_st_max_distance = 80.0f;

View File

@ -17,8 +17,13 @@
// 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_CAKE_H
#define HEADER_CAKE_H
#ifndef HEADER_CAKE_HPP
#define HEADER_CAKE_HPP
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#endif
#include "flyable.hpp"
@ -35,7 +40,11 @@ private:
// projectile (NULL if none)
public:
Cake (Kart *kart);
#ifdef HAVE_IRRLICHT
static void init (const lisp::Lisp* lisp, scene::IMesh *cake_model);
#else
static void init (const lisp::Lisp* lisp, ssgEntity* cake_model);
#endif
virtual void update (float dt);
virtual void hitTrack () { hit(NULL); }
// Kinematic objects are not allowed to have a velocity (assertion in

View File

@ -23,6 +23,8 @@
#include "callback_manager.hpp"
#include "race_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/mesh_tools.hpp"
#include "graphics/scene.hpp"
#include "items/projectile_manager.hpp"
#include "karts/kart.hpp"
@ -35,7 +37,11 @@
// static variables:
float Flyable::m_st_speed[POWERUP_MAX];
#ifdef HAVE_IRRLICHT
scene::IMesh* Flyable::m_st_model[POWERUP_MAX];
#else
ssgEntity* Flyable::m_st_model[POWERUP_MAX];
#endif
float Flyable::m_st_min_height[POWERUP_MAX];
float Flyable::m_st_max_height[POWERUP_MAX];
float Flyable::m_st_force_updown[POWERUP_MAX];
@ -65,6 +71,7 @@ Flyable::Flyable(Kart *kart, PowerupType type, float mass) : Moveable()
// Add the graphical model
#ifdef HAVE_IRRLICHT
setRoot(irr_driver->addMesh(m_st_model[type]));
#else
ssgTransform *m = getModelTransform();
m->addKid(m_st_model[type]);
@ -117,8 +124,13 @@ void Flyable::createPhysics(float y_offset, const btVector3 &velocity,
} // createPhysics
// -----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
void Flyable::init(const lisp::Lisp* lisp, scene::IMesh *model,
PowerupType type)
#else
void Flyable::init(const lisp::Lisp* lisp, ssgEntity *model,
PowerupType type)
#endif
{
m_st_speed[type] = 25.0f;
m_st_max_height[type] = 1.0f;
@ -132,6 +144,7 @@ void Flyable::init(const lisp::Lisp* lisp, ssgEntity *model,
// Store the size of the model
Vec3 min, max;
#ifdef HAVE_IRRLICHT
MeshTools::minMax3D(model, &min, &max);
#else
SSGHelp::MinMax(model, &min, &max);
#endif

View File

@ -20,6 +20,10 @@
#ifndef HEADER_FLYABLE_HPP
#define HEADER_FLYABLE_HPP
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#endif
#include "audio/sfx_manager.hpp"
#include "items/powerup_manager.hpp"
#include "karts/moveable.hpp"
@ -28,6 +32,9 @@
class FlyableInfo;
class Kart;
class MovingPhysics;
#ifndef HAVE_IRRLICHT
class ssgEntity;
#endif
class Flyable : public Moveable, public TerrainInfo
{
@ -58,7 +65,11 @@ protected:
// so we need arrays of these variables to have different values
// for bowling balls, missiles, ...
static float m_st_speed[POWERUP_MAX]; // Speed of the projectile
#ifdef HAVE_IRRLICHT
static scene::IMesh *m_st_model[POWERUP_MAX]; // 3d model
#else
static ssgEntity* m_st_model[POWERUP_MAX]; // 3d model
#endif
static float m_st_min_height[POWERUP_MAX]; // min height above track
static float m_st_max_height[POWERUP_MAX]; // max height above track
static float m_st_force_updown[POWERUP_MAX]; // force pushing up/down
@ -98,8 +109,13 @@ public:
* terrain. Missiles can 'follow the terrain' with this adjustment,
* but gravity will basically be disabled. */
void setAdjustZVelocity(bool f) { m_adjust_z_velocity = f; }
#ifdef HAVE_IRRLICHT
static void init (const lisp::Lisp* lisp, scene::IMesh *model,
PowerupType type);
#else
static void init (const lisp::Lisp* lisp, ssgEntity *model,
PowerupType type);
#endif
virtual void update (float);
void updateFromServer(const FlyableInfo &f, float dt);

View File

@ -106,7 +106,11 @@ Plunger::~Plunger()
} // ~Plunger
// -----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
void Plunger::init(const lisp::Lisp* lisp, scene::IMesh *plunger_model)
#else
void Plunger::init(const lisp::Lisp* lisp, ssgEntity *plunger_model)
#endif
{
Flyable::init(lisp, plunger_model, POWERUP_PLUNGER);
} // init

View File

@ -17,9 +17,13 @@
// 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_MISSILE_H
#define HEADER_MISSILE_H
#ifndef HEADER_MISSILE_HPP
#define HEADER_MISSILE_HPP
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#endif
#include "flyable.hpp"
class RubberBand;
@ -38,7 +42,11 @@ private:
public:
Plunger(Kart *kart);
~Plunger();
#ifdef HAVE_IRRLICHT
static void init(const lisp::Lisp* lisp, scene::IMesh* missile);
#else
static void init (const lisp::Lisp* lisp, ssgEntity* missile);
#endif
/** 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.
*/

View File

@ -26,6 +26,7 @@
#include "file_manager.hpp"
#include "material_manager.hpp"
#include "material.hpp"
#include "graphics/irr_driver.hpp"
#include "items/bowling.hpp"
#include "items/cake.hpp"
#include "items/plunger.hpp"
@ -41,6 +42,16 @@ initPowerupType;
initPowerupType ict[]=
{
#ifdef HAVE_IRRLICHT
{POWERUP_ZIPPER, "zipper.collectable" },
{POWERUP_BOWLING, "bowling.projectile" },
{POWERUP_BUBBLEGUM, "bubblegum.xml" },
{POWERUP_CAKE, "cake.projectile" },
{POWERUP_ANVIL, "anvil.collectable" },
{POWERUP_PARACHUTE, "parachute.collectable" },
{POWERUP_PLUNGER, "plunger.projectile" },
{POWERUP_MAX, "" },
#else
{POWERUP_ZIPPER, "zipper.collectable" },
{POWERUP_BOWLING, "bowling.projectile" },
{POWERUP_BUBBLEGUM, "bubblegum.projectile" },
@ -49,6 +60,7 @@ initPowerupType ict[]=
{POWERUP_PARACHUTE, "parachute.collectable" },
{POWERUP_PLUNGER, "plunger.projectile" },
{POWERUP_MAX, "" },
#endif
};
PowerupManager* powerup_manager=0;
@ -58,7 +70,11 @@ PowerupManager::PowerupManager()
{
for(int i=0; i<POWERUP_MAX; i++)
{
#ifdef HAVE_IRRLICHT
m_all_meshes[i] = NULL;
#else
m_all_models[i] = (ssgEntity*)NULL;
#endif
m_all_icons[i] = (Material*)NULL;
}
} // PowerupManager
@ -114,15 +130,30 @@ void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType )
{
std::string sName, sModel, sIconFile;
lisp->get("name", sName );
lisp->get("model", sModel );
lisp->get("icon", sIconFile );
#ifdef HAVE_IRRLICHT
lisp->get("mesh", sModel );
#else
lisp->get("model", sModel );
#endif
lisp->get("icon", sIconFile );
// load material
m_all_icons[collectType] = material_manager->getMaterial(sIconFile,
/* full_path */ false,
/*make_permanent */ true);
/*make_permanent */ true);
#ifdef HAVE_IRRLICHT
if(sModel!="")
{
// FIXME LEAK: not freed (unimportant, since the models have to exist
// for the whole game anyway).
std::string full_path = file_manager->getModelFile(sModel);
m_all_meshes[collectType] = irr_driver->getMesh(full_path);
}
else
{
m_all_meshes[collectType] = 0;
m_all_extends[collectType] = btVector3(0.0f,0.0f,0.0f);
}
#else
m_all_icons[collectType]->getState()->ref();
if(sModel!="")
@ -142,6 +173,17 @@ void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType )
#endif
// Load special attributes for certain powerups
#ifdef HAVE_IRRLICHT
switch (collectType) {
case POWERUP_BOWLING:
Bowling::init(lisp, m_all_meshes[collectType]); break;
case POWERUP_PLUNGER:
Plunger::init(lisp, m_all_meshes[collectType]); break;
case POWERUP_CAKE:
Cake::init(lisp, m_all_meshes[collectType]); break;
default:;
} // switch
#else
switch (collectType) {
case POWERUP_BOWLING:
Bowling::init (lisp, m_all_models[collectType]); break;
@ -151,6 +193,6 @@ void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType )
Cake::init (lisp, m_all_models[collectType]); break;
default:;
} // switch
#endif
} // LoadNode

View File

@ -17,15 +17,20 @@
// 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_POWERUPMANAGER_H
#define HEADER_POWERUPMANAGER_H
#ifndef HEADER_POWERUPMANAGER_HPP
#define HEADER_POWERUPMANAGER_HPP
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
#endif
#include "lisp/parser.hpp"
#include "lisp/lisp.hpp"
#include "btBulletDynamicsCommon.h"
class Material;
#ifndef HAVE_IRRLICHT
class ssgEntity;
#endif
// The anvil and parachute must be at the end of the enum, and the
// zipper just before them (see Powerup::hitBonusBox).
@ -38,24 +43,34 @@ enum PowerupType {POWERUP_NOTHING,
class PowerupManager
{
protected:
Material* m_all_icons [POWERUP_MAX];
float m_all_max_distance[POWERUP_MAX]; // if a target is closer than this
float m_all_force_to_target[POWERUP_MAX]; // apply this force to move towards
Material* m_all_icons [POWERUP_MAX];
float m_all_max_distance[POWERUP_MAX]; // if a target is closer than this
float m_all_force_to_target[POWERUP_MAX]; // apply this force to move towards
// the target
float m_all_max_turn_angle[POWERUP_MAX]; // maximum turn angle for homing
ssgEntity* m_all_models[POWERUP_MAX];
btVector3 m_all_extends[POWERUP_MAX];
void LoadNode (const lisp::Lisp* lisp, int collectType);
float m_all_max_turn_angle[POWERUP_MAX]; // maximum turn angle for homing
#ifdef HAVE_IRRLICHT
scene::IMesh *m_all_meshes[POWERUP_MAX];
#else
ssgEntity* m_all_models[POWERUP_MAX];
#endif
btVector3 m_all_extends[POWERUP_MAX];
void LoadNode (const lisp::Lisp* lisp, int collectType);
public:
PowerupManager ();
void loadPowerups();
void removeTextures ();
void Load (int collectType, const char* filename);
Material* getIcon (int type) const {return m_all_icons [type]; }
ssgEntity* getModel (int type) const {return m_all_models[type]; }
float getForceToTarget(int type) const {return m_all_force_to_target[type]; }
float getMaxDistance (int type) const {return m_all_max_distance[type];}
float getMaxTurnAngle (int type) const {return m_all_max_turn_angle[type];}
void loadPowerups();
void removeTextures ();
void Load (int collectType, const char* filename);
Material* getIcon (int type) const {return m_all_icons [type]; }
#ifdef HAVE_IRRLICHT
/** Returns the mesh for a certain powerup.
* \param type Mesh type for which the model is returned. */
scene::IMesh *getMesh (int type) const {return m_all_meshes[type]; }
#else
ssgEntity* getModel (int type) const {return m_all_models[type]; }
#endif
float getForceToTarget(int type) const {return m_all_force_to_target[type]; }
float getMaxDistance (int type) const {return m_all_max_distance[type];}
float getMaxTurnAngle (int type) const {return m_all_max_turn_angle[type];}
const btVector3& getExtend (int type) const {return m_all_extends[type]; }
};

View File

@ -31,9 +31,9 @@ Moveable::Moveable()
{
m_body = 0;
m_motion_state = 0;
m_first_time = true ;
m_first_time = true;
#ifdef HAVE_IRRLICHT
m_mesh = 0;
m_mesh = 0;
#else
m_model_transform = new ssgTransform();
m_model_transform->ref();

View File

@ -66,10 +66,11 @@ public:
Moveable();
virtual ~Moveable();
#ifdef HAVE_IRRLICHT
scene::ISceneNode
*getRoot() {return m_root; }
scene::ISceneNode
*getRoot() {return m_root; }
void setRoot(scene::ISceneNode *n){m_root = n; }
#else
ssgTransform *getModelTransform() {return m_model_transform; }
ssgTransform *getModelTransform() {return m_model_transform; }
#endif
virtual const btVector3
&getVelocity() const {return m_body->getLinearVelocity();}

View File

@ -59,6 +59,7 @@ MovingPhysics::MovingPhysics(const XMLNode *xml_node)
{
fprintf(stderr, "Warning: '%s' in '%s' not found and is ignored.\n",
xml_node->getName().c_str(), model_name.c_str());
return;
} // if(!obj)
}
m_mesh = obj->getMesh(0);