From 78865a5608872193e752f9e321c73adf266a67f0 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 28 Oct 2012 23:19:20 +0000 Subject: [PATCH] Move the plunger a bit more randomly. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11804 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/graphics/irr_driver.cpp | 2 +- src/states_screens/minimal_race_gui.cpp | 6 +- src/states_screens/minimal_race_gui.hpp | 2 +- src/states_screens/race_gui.cpp | 6 +- src/states_screens/race_gui.hpp | 2 +- src/states_screens/race_gui_base.cpp | 76 ++++++++++++++++++----- src/states_screens/race_gui_base.hpp | 24 ++++++- src/states_screens/race_gui_overworld.cpp | 4 +- src/states_screens/race_gui_overworld.hpp | 2 +- 9 files changed, 95 insertions(+), 29 deletions(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 70c95921c..fe5bd9308 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1584,7 +1584,7 @@ void IrrDriver::update(float dt) PROFILER_PUSH_CPU_MARKER(marker_name, 0x00, 0x00, (i+1)*60); } - rg->renderPlayerView(kart); + rg->renderPlayerView(kart, dt); PROFILER_POP_CPU_MARKER(); } diff --git a/src/states_screens/minimal_race_gui.cpp b/src/states_screens/minimal_race_gui.cpp index 7e9389fc4..8178a8da5 100644 --- a/src/states_screens/minimal_race_gui.cpp +++ b/src/states_screens/minimal_race_gui.cpp @@ -199,7 +199,7 @@ void MinimalRaceGUI::renderGlobal(float dt) * collectibles, ... * \param kart Pointer to the kart for which to render the view. */ -void MinimalRaceGUI::renderPlayerView(const AbstractKart *kart) +void MinimalRaceGUI::renderPlayerView(const AbstractKart *kart, float dt) { if (!m_enabled) return; @@ -208,7 +208,7 @@ void MinimalRaceGUI::renderPlayerView(const AbstractKart *kart) scaling *= viewport.getWidth()/800.0f; // scale race GUI along screen size - drawPlungerInFace(kart); + drawPlungerInFace(kart, dt); drawAllMessages (kart, viewport, scaling); if(!World::getWorld()->isRacePhase()) return; @@ -218,7 +218,7 @@ void MinimalRaceGUI::renderPlayerView(const AbstractKart *kart) drawEnergyMeter (kart, viewport, scaling); drawRankLap (info, kart, viewport); - RaceGUIBase::renderPlayerView(kart); + RaceGUIBase::renderPlayerView(kart, dt); } // renderPlayerView //----------------------------------------------------------------------------- diff --git a/src/states_screens/minimal_race_gui.hpp b/src/states_screens/minimal_race_gui.hpp index ea7798568..8fe38a1eb 100644 --- a/src/states_screens/minimal_race_gui.hpp +++ b/src/states_screens/minimal_race_gui.hpp @@ -119,7 +119,7 @@ public: MinimalRaceGUI(); ~MinimalRaceGUI(); virtual void renderGlobal(float dt); - virtual void renderPlayerView(const AbstractKart *kart); + virtual void renderPlayerView(const AbstractKart *kart, float dt); /** Returns the size of the texture on which to render the minimap to. */ virtual const core::dimension2du getMiniMapSize() const diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 0efb2c442..3531ed5ce 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -183,7 +183,7 @@ void RaceGUI::renderGlobal(float dt) * collectibles, ... * \param kart Pointer to the kart for which to render the view. */ -void RaceGUI::renderPlayerView(const AbstractKart *kart) +void RaceGUI::renderPlayerView(const AbstractKart *kart, float dt) { if (!m_enabled) return; @@ -191,7 +191,7 @@ void RaceGUI::renderPlayerView(const AbstractKart *kart) core::vector2df scaling = kart->getCamera()->getScaling(); - drawPlungerInFace(kart); + drawPlungerInFace(kart, dt); scaling *= viewport.getWidth()/800.0f; // scale race GUI along screen size drawAllMessages (kart, viewport, scaling); @@ -204,7 +204,7 @@ void RaceGUI::renderPlayerView(const AbstractKart *kart) drawSpeedAndEnergy (kart, viewport, scaling); drawRankLap (info, kart, viewport); - RaceGUIBase::renderPlayerView(kart); + RaceGUIBase::renderPlayerView(kart, dt); } // renderPlayerView //----------------------------------------------------------------------------- diff --git a/src/states_screens/race_gui.hpp b/src/states_screens/race_gui.hpp index 0f27b271a..152347b5d 100644 --- a/src/states_screens/race_gui.hpp +++ b/src/states_screens/race_gui.hpp @@ -110,7 +110,7 @@ public: RaceGUI(); ~RaceGUI(); virtual void renderGlobal(float dt); - virtual void renderPlayerView(const AbstractKart *kart); + virtual void renderPlayerView(const AbstractKart *kart, float dt); /** Returns the size of the texture on which to render the minimap to. */ virtual const core::dimension2du getMiniMapSize() const diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index e65901154..ed458951a 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -133,6 +133,10 @@ void RaceGUIBase::restartRace() { m_referee_height = 10.0f; m_referee->attachToSceneNode(); + m_plunger_move_time = 0; + m_plunger_offset = core::vector2di(0,0); + m_plunger_speed = core::vector2df(0,0); + m_plunger_state = PLUNGER_STATE_INIT; } // restartRace //----------------------------------------------------------------------------- @@ -480,7 +484,7 @@ void RaceGUIBase::preRenderCallback(const AbstractKart &kart) } // preRenderCallback // ---------------------------------------------------------------------------- -void RaceGUIBase::renderPlayerView(const AbstractKart *kart) +void RaceGUIBase::renderPlayerView(const AbstractKart *kart, float dt) { const core::recti &viewport = kart->getCamera()->getViewport(); @@ -1015,35 +1019,77 @@ void RaceGUIBase::drawGlobalPlayerIcons(const KartIconDisplayInfo* info, } // drawGlobalPlayerIcons // ---------------------------------------------------------------------------- + /** Draws the plunger-in-face if necessary. Does nothing if there is no * plunger in face atm. */ -void RaceGUIBase::drawPlungerInFace(const AbstractKart *kart) +void RaceGUIBase::drawPlungerInFace(const AbstractKart *kart, float dt) { - if (kart->getBlockedByPlungerTime()<=0) return; + if (kart->getBlockedByPlungerTime()<=0) + { + m_plunger_state = PLUNGER_STATE_INIT; + return; + } const core::recti &viewport = kart->getCamera()->getViewport(); const int screen_width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X; - const int plunger_size = (int)(0.6f * screen_width); - int plunger_x = viewport.UpperLeftCorner.X + screen_width/2 - - plunger_size/2; - int plunger_offset = 0; - const float anim_time=3.0f; - if(kart->getBlockedByPlungerTime()getBlockedByPlungerTime())/anim_time; - plunger_offset = (int)(f*height*0.5f); + RandomGenerator random; + m_plunger_move_time = 0.1f+random.get(50)/200.0f; + m_plunger_offset = core::vector2di(0,0); + m_plunger_state = PLUNGER_STATE_NOMOVE; + m_plunger_speed = core::vector2df(0, 0); + m_plunger_x_target = random.get(screen_width)- screen_width/2; } + m_plunger_move_time -= dt; + if(m_plunger_move_time < dt && m_plunger_state!=PLUNGER_STATE_FAST) + { + const float fast_time = 0.3f; + if(kart->getBlockedByPlungerTime()getTexture(); + plunger_x += (int)m_plunger_offset.X; core::rect dest(plunger_x, offset_y, plunger_x+plunger_size, offset_y+plunger_size); diff --git a/src/states_screens/race_gui_base.hpp b/src/states_screens/race_gui_base.hpp index 93ce9b337..fc1d36cb9 100644 --- a/src/states_screens/race_gui_base.hpp +++ b/src/states_screens/race_gui_base.hpp @@ -150,6 +150,26 @@ protected: /** Material for the 'plunger in the face' texture. */ Material *m_plunger_face; + /** State of the plunger: the plunger switches between not moving and slow + * moving till the end of the plunger time is nearly reached, in which + * case it changes to fast moving. */ + enum PlungerState {PLUNGER_STATE_INIT, PLUNGER_STATE_SLOW, + PLUNGER_STATE_NOMOVE, PLUNGER_STATE_FAST} + m_plunger_state; + + /** How long the plunger should stay in the current state. */ + float m_plunger_move_time; + + /** The x position at which the plunger should end, randomly determined. */ + int m_plunger_x_target; + + /** Offset of the plunger. */ + core::vector2di m_plunger_offset; + + /* Speed of the plunger. This gets changed depending on state (not moving, + * slow moving, fast moving). */ + core::vector2df m_plunger_speed; + /** The size of a single marker in pixels, must be a power of 2. */ int m_marker_rendered_size; @@ -176,7 +196,7 @@ protected: const core::vector2df &scaling); void drawGlobalMusicDescription(); void drawGlobalReadySetGo (); - void drawPlungerInFace(const AbstractKart *kart); + void drawPlungerInFace(const AbstractKart *kart, float dt); /** Instructs the base gui to ignore unimportant messages (like * item messages). */ @@ -198,7 +218,7 @@ public: virtual void renderGlobal(float dt); virtual void init(); virtual void restartRace(); - virtual void renderPlayerView(const AbstractKart *kart); + virtual void renderPlayerView(const AbstractKart *kart, float dt); virtual void addMessage(const irr::core::stringw &m, const AbstractKart *kart, float time, const video::SColor &color= diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 1e6b2aca6..20af0b3a9 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -175,7 +175,7 @@ void RaceGUIOverworld::renderGlobal(float dt) * collectibles, ... * \param kart Pointer to the kart for which to render the view. */ -void RaceGUIOverworld::renderPlayerView(const AbstractKart *kart) +void RaceGUIOverworld::renderPlayerView(const AbstractKart *kart, float dt) { if (!m_enabled) return; @@ -194,7 +194,7 @@ void RaceGUIOverworld::renderPlayerView(const AbstractKart *kart) drawPowerupIcons (kart, viewport, scaling); - RaceGUIBase::renderPlayerView(kart); + RaceGUIBase::renderPlayerView(kart, dt); } // renderPlayerView //----------------------------------------------------------------------------- diff --git a/src/states_screens/race_gui_overworld.hpp b/src/states_screens/race_gui_overworld.hpp index 323e75dd0..c38eb1300 100644 --- a/src/states_screens/race_gui_overworld.hpp +++ b/src/states_screens/race_gui_overworld.hpp @@ -113,7 +113,7 @@ public: RaceGUIOverworld(); ~RaceGUIOverworld(); virtual void renderGlobal(float dt); - virtual void renderPlayerView(const AbstractKart *kart); + virtual void renderPlayerView(const AbstractKart *kart, float dt); /** Returns the size of the texture on which to render the minimap to. */ virtual const core::dimension2du getMiniMapSize() const