From b48f31d4a0b1b92c2434599078c64d493fbbc514 Mon Sep 17 00:00:00 2001 From: Alayan Date: Fri, 21 Sep 2018 04:36:23 +0200 Subject: [PATCH] add basic functions to manage super status --- src/karts/abstract_kart.hpp | 13 ++++++ src/karts/kart.cpp | 80 +++++++++++++++++++++++++++++++++++++ src/karts/kart.hpp | 9 +++++ 3 files changed, 102 insertions(+) diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index dc0725aa7..75a884e33 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -277,6 +277,19 @@ public: /** Makes the kart unsquashed again. */ virtual void unsetSquash() = 0; // ------------------------------------------------------------------------ + /** This activates super mode for kart ; upscaling it and giving it + * other perks. + * \param time How long the kart will be in super mode. A value of 0 will reset + * the kart to be normal. */ + virtual void setSuper(float time) = 0; + // ------------------------------------------------------------------------ + /** This disables super mode + * \param instant Is this a normal end or a reset */ + virtual void unsetSuper(bool instant) = 0; + // ------------------------------------------------------------------------ + /** Updates the kart's current scaling */ + virtual void updateScale() = 0; + // ------------------------------------------------------------------------ /** Returns the speed of the kart in meters/second. This is not declared * pure abstract, since this function is not needed for certain classes, * like Ghost. */ diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 140807d5c..e2fcd3cb4 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -348,6 +348,7 @@ void Kart::reset() m_collision_particles->setCreationRateAbsolute(0.0f); #endif + unsetSuper(true /*instant*/); unsetSquash(); m_last_used_powerup = PowerupManager::POWERUP_NOTHING; @@ -360,7 +361,9 @@ void Kart::reset() m_invulnerable_ticks = 0; m_min_nitro_ticks = 0; m_energy_to_min_ratio = 0; + m_scale_change_ticks = 0; m_squash_time = std::numeric_limits::max(); + m_super_time = std::numeric_limits::max(); m_collected_energy = 0; m_bounce_back_ticks = 0; m_brake_ticks = 0; @@ -1792,6 +1795,8 @@ void Kart::setSquash(float time, float slowdown) return; } + unsetSuper(true /*instant*/); + m_max_speed->setSlowdown(MaxSpeed::MS_DECREASE_SQUASH, slowdown, stk_config->time2Ticks(0.1f), stk_config->time2Ticks(time)); @@ -1846,6 +1851,71 @@ void Kart::unsetSquash() #endif } +//----------------------------------------------------------------------------- +/** This activates super mode for kart ; upscaling it and giving it + * other perks. + * \param time How long the kart will be in super mode. A value of 0 will reset + * the kart to be normal. + */ +void Kart::setSuper(float time) +{ + if (time <= 0) unsetSuper(false /*instant*/); + + unsetSquash(); + + //TODO : set max speed and engine bonus + + if (m_super_time == std::numeric_limits::max()) + { + m_scale_change_ticks = 40; + m_super_time = time; + } +} // setSuper + +//----------------------------------------------------------------------------- +/** Update the scale according to m_scale_change_ticks + */ +void Kart::updateScale() +{ + //TODO update physics model too + if (m_scale_change_ticks == 0) return; + + float scale_factor; + if (m_scale_change_ticks > 0) + { + m_scale_change_ticks--; + scale_factor = 1.4 - (m_scale_change_ticks*0.01); + } + else + { + m_scale_change_ticks++; + scale_factor = 1.0 - (m_scale_change_ticks*0.01); + } + + m_node->setScale(core::vector3df(scale_factor,scale_factor,scale_factor)); +} // setSuper + +//----------------------------------------------------------------------------- +/** This disables super mode + * \param instant Is this a normal end or a reset */ +void Kart::unsetSuper(bool instant) +{ + //TODO update physics model too + m_super_time = std::numeric_limits::max(); + if (instant) + { + m_node->setScale(core::vector3df(1.0f,1.0f,1.0f)); + m_scale_change_ticks = 0; + //TODO : force end the max speed bonus + } + else + { + //Will scale back to normal over time + m_scale_change_ticks = -40; + } +} // unsetSuper + + //----------------------------------------------------------------------------- /** Returns if the kart is currently being squashed */ @@ -2506,6 +2576,16 @@ bool Kart::playCustomSFX(unsigned int type) */ void Kart::updatePhysics(int ticks) { + if (m_super_time != std::numeric_limits::max()) + { + m_squash_time -= stk_config->ticks2Time(ticks); + // If super time ends, reset the model + if (m_super_time <= 0.0f) + { + unsetSuper(false /*instant*/); + } + } // if super + if (m_controls.getAccel() > 0.0f && World::getWorld()->getTicksSinceStart() == 1) { diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 8b74ec36f..26008d908 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -253,6 +253,11 @@ protected: int m_ticks_last_crash; RaceManager::KartType m_type; + // Used to know where we are when upscaling/downscaling the kart + // Set to positive to upscale, to negative to downscale + int8_t m_scale_change_ticks; + float m_super_time; + /** To prevent using nitro in too short bursts */ int8_t m_min_nitro_ticks; @@ -315,6 +320,10 @@ public: virtual void setSquash (float time, float slowdown) OVERRIDE; virtual void unsetSquash () OVERRIDE; + virtual void setSuper (float time) OVERRIDE; + virtual void unsetSuper (bool instant) OVERRIDE; + virtual void updateScale () OVERRIDE; + virtual void crashed (AbstractKart *k, bool update_attachments) OVERRIDE; virtual void crashed (const Material *m, const Vec3 &normal) OVERRIDE; virtual float getHoT () const OVERRIDE;