improvements to battle mode. 1. drop karts at an acceptable angle on rescue 2. hits make karts lose lives 3. improved resetting, ending and restarting 4. added fast music support 5. fixed memory leak

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2340 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2008-10-15 19:00:50 +00:00
parent ed2f52bee6
commit 88fcbc0c95
4 changed files with 54 additions and 9 deletions

View File

@ -241,6 +241,10 @@ void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
{
// Set a flag it if was a direct hit.
kart->handleExplosion(getXYZ(), kart==kart_hit);
if(kart==kart_hit && RaceManager::getTrack()->isArena())
{
RaceManager::getWorld()->kartHit(kart->getWorldKartId());
}
}
}
callback_manager->handleExplosion(pos_explosion, moving_physics);

View File

@ -17,6 +17,7 @@
#include "modes/three_strikes_battle.hpp"
#include "gui/race_gui.hpp"
#include "audio/sound_manager.hpp"
#include <string>
@ -44,11 +45,11 @@ ThreeStrikesBattle::ThreeStrikesBattle() : World()
// no positions in this mode
m_kart[n]->setPosition(-1);
}// next kart
// TODO - implement
}
ThreeStrikesBattle::~ThreeStrikesBattle()
{
delete[] m_kart_display_info;
}
@ -64,9 +65,25 @@ void ThreeStrikesBattle::onGo()
}
void ThreeStrikesBattle::terminateRace()
{
// TODO - implement
World::terminateRace();
}
void ThreeStrikesBattle::kartHit(const int kart_id)
{
assert(kart_id >= 0);
assert(kart_id < m_kart.size());
// make kart lose a life
m_kart_info[kart_id].m_lives --;
// check if kart is 'dead'
if(m_kart_info[kart_id].m_lives < 1)
removeKart(kart_id);
// almost over, use fast music
if(getCurrentNumKarts()==2)
sound_manager->switchToFastMusic();
}
std::string ThreeStrikesBattle::getInternalCode() const
{
return "BATTLE_3_STRIKES";
@ -74,9 +91,29 @@ std::string ThreeStrikesBattle::getInternalCode() const
void ThreeStrikesBattle::update(float delta)
{
World::update(delta);
// check if over
if(getCurrentNumKarts()==1 || getCurrentNumPlayers()==0)
{
// Add the results for the remaining kart
for(int i=1; i<(int)race_manager->getNumKarts(); i++)
if(!m_kart[i]->isEliminated())
race_manager->RaceFinished(m_kart[i], -1);
TimedRace::enterRaceOverState();
return;
}
}
void ThreeStrikesBattle::restartRace()
{
World::restartRace();
const unsigned int kart_amount = m_kart.size();
for(unsigned int n=0; n<kart_amount; n++)
{
m_kart_info[n].m_lives = 3;
}// next kart
}
//void ThreeStrikesBattle::getDefaultCollectibles(int& collectible_type, int& amount)
@ -151,10 +188,9 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
kart->setXYZ( Vec3(RaceManager::getTrack()->m_start_positions[closest_id_found]) );
// FIXME - implement heading
// btQuaternion heading(btVector3(0.0f, 0.0f, 1.0f),
// DEGREE_TO_RAD(RaceManager::getTrack()->m_angle[info.m_track_sector]) );
// kart->setRotation(heading);
// FIXME - implement correct heading
btQuaternion heading(btVector3(0.0f, 0.0f, 1.0f), 0 /* angle */ );
kart->setRotation(heading);
// A certain epsilon is added here to the Z coordinate (0.1), in case
// that the points are somewhat under the track. Otherwise, the
@ -162,8 +198,7 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
// a rescue, ...
btTransform pos;
pos.setOrigin(kart->getXYZ()+btVector3(0, 0, 0.5f*kart->getKartHeight()+0.1f));
//pos.setRotation(btQuaternion(btVector3(0.0f, 0.0f, 1.0f),
// DEGREE_TO_RAD(RaceManager::getTrack()->m_angle[info.m_track_sector])));
pos.setRotation( btQuaternion(btVector3(0.0f, 0.0f, 1.0f), 0 /* angle */) );
body->setCenterOfMassTransform(pos);

View File

@ -57,6 +57,8 @@ public:
virtual void moveKartAfterRescue(Kart* kart, btRigidBody* body);
virtual std::string getInternalCode() const;
virtual void kartHit(const int kart_id);
};

View File

@ -188,6 +188,10 @@ public:
/** Called when it is needed to know whether this kind of race involves counting laps.
*/
virtual bool raceHasLaps() = 0;
/** Called when a kart was hit by a projectile
*/
virtual void kartHit(const int kart_id) {};
};
#endif