diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index db37ba521..a289a1631 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -35,7 +35,7 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER) // if the kart is looking backwards, release from the back PlayerKart* pk = dynamic_cast(kart); - const bool reverse_mode = (pk != NULL && pk->getCamera()->getMode() == Camera::CM_REVERSE); + m_reverse_mode = (pk != NULL && pk->getCamera()->getMode() == Camera::CM_REVERSE); // find closest kart in front of the current one const Kart *closest_kart=0; btVector3 direction; float kartDistSquared; @@ -52,7 +52,7 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER) float pitch = kart->getTerrainPitch(heading); // aim at this kart if it's not too far - if(closest_kart != NULL && kartDistSquared < 30*30 && !reverse_mode) // aiming doesn't work backwards + if(closest_kart != NULL && kartDistSquared < 30*30 && !m_reverse_mode) // aiming doesn't work backwards { const float time = sqrt(kartDistSquared) / (m_speed - closest_kart->getSpeed()); @@ -76,9 +76,9 @@ 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), 0.0f /* gravity */, false /* rotates */, reverse_mode, &trans ); + new btCylinderShape(0.5f*m_extend), 0.0f /* gravity */, false /* rotates */, m_reverse_mode, &trans ); - if(reverse_mode) + if(m_reverse_mode) m_rubber_band = NULL; else { @@ -116,13 +116,13 @@ void Plunger::update(float dt) m->removeAllKids(); scene->remove(m); } - m_rubber_band->update(dt); + if(!m_reverse_mode) m_rubber_band->update(dt); return; } // Else: update the flyable and rubber band Flyable::update(dt); - m_rubber_band->update(dt); + if(!m_reverse_mode) m_rubber_band->update(dt); // FIXME - don't hardcode, put in config file const float max_height = 1.0; @@ -155,30 +155,50 @@ 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) + if(m_reverse_mode) { - m_rubber_band->hit(kart); - return; - } - else if(mp) - { - Vec3 pos(mp->getBody()->getWorldTransform().getOrigin()); - m_rubber_band->hit(NULL, &pos); + if(kart) + { + kart->blockViewWithPlunger(); + } + else + { + m_keep_alive = 0; + // 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()); + //hitTrack(); + } } else { - m_rubber_band->hit(NULL, &(getXYZ())); - } + 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 // ----------------------------------------------------------------------------- diff --git a/src/items/plunger.hpp b/src/items/plunger.hpp index 107b29e62..6fe885469 100644 --- a/src/items/plunger.hpp +++ b/src/items/plunger.hpp @@ -34,6 +34,7 @@ private: /** Timer to keep the plunger alive while the rubber band is working. */ float m_keep_alive; + bool m_reverse_mode; public: Plunger(Kart *kart); ~Plunger(); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index f00910bde..08a86a376 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -80,7 +80,7 @@ Kart::Kart (const std::string& kart_name, int position, m_nitro = NULL; m_skidmarks = NULL; - m_view_blocked_by_plunger = false; + m_view_blocked_by_plunger = 0; // Set position and heading: m_reset_transform = init_transform; @@ -468,6 +468,9 @@ void Kart::handleExplosion(const Vec3& pos, bool direct_hit) //----------------------------------------------------------------------------- void Kart::update(float dt) { + // if its view is blocked by plunger, decrease remaining time + if(m_view_blocked_by_plunger > 0) m_view_blocked_by_plunger -= dt; + // Store the actual kart controls at the start of update in the server // state. This makes it easier to reset some fields when they are not used // anymore (e.g. controls.fire). diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 16cc38288..ca1266fe6 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -91,7 +91,9 @@ private: float m_finish_time; bool m_finished_race; - bool m_view_blocked_by_plunger; + /* When a kart has its view blocked by the plunger, this variable will be > 0 + the number it contains is the time left before removing plunger */ + float m_view_blocked_by_plunger; float m_speed; float m_rpm; @@ -145,8 +147,8 @@ public: void updatePhysics (float dt); bool hasViewBlockedByPlunger() const - { return m_view_blocked_by_plunger; } - void blockViewWithPlunger() { m_view_blocked_by_plunger = true; } + { return m_view_blocked_by_plunger > 0; } + void blockViewWithPlunger() { m_view_blocked_by_plunger = 20; } /** returns a bullet transform object located at the kart's position diff --git a/src/modes/standard_race.cpp b/src/modes/standard_race.cpp index 115f732ca..e65d4c6d2 100644 --- a/src/modes/standard_race.cpp +++ b/src/modes/standard_race.cpp @@ -98,6 +98,9 @@ void StandardRace::getDefaultCollectibles(int& collectible_type, int& amount) amount = race_manager->getNumLaps(); } else World::getDefaultCollectibles(collectible_type, amount); + + collectible_type = POWERUP_PLUNGER; + amount = 5; } //----------------------------------------------------------------------------- bool StandardRace::enableBonusBoxes()