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
This commit is contained in:
parent
180da88c32
commit
78865a5608
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
@ -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()<anim_time)
|
||||
|
||||
if(m_plunger_state == PLUNGER_STATE_INIT)
|
||||
{
|
||||
int height = viewport.LowerRightCorner.Y
|
||||
- viewport.UpperLeftCorner.Y;
|
||||
// Map remaining plunger time between [anim_time,0] time to [0,1]
|
||||
float f = (anim_time - kart->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()<fast_time)
|
||||
{
|
||||
m_plunger_state = PLUNGER_STATE_FAST;
|
||||
m_plunger_speed = core::vector2df(m_plunger_x_target/fast_time,
|
||||
viewport.getHeight()*0.5f
|
||||
/fast_time);
|
||||
m_plunger_move_time = fast_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
RandomGenerator random;
|
||||
m_plunger_move_time = 0.1f+random.get(50)/200.0f;
|
||||
// Plunger is either moving or not moving
|
||||
if(m_plunger_state==PLUNGER_STATE_NOMOVE)
|
||||
{
|
||||
m_plunger_state = PLUNGER_STATE_SLOW;
|
||||
m_plunger_speed =
|
||||
core::vector2df(0, 0.05f*viewport.getHeight()
|
||||
/m_plunger_move_time );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_plunger_state = PLUNGER_STATE_NOMOVE;
|
||||
m_plunger_speed = core::vector2df(0,0);
|
||||
}
|
||||
} // has not reach fast moving state
|
||||
}
|
||||
|
||||
m_plunger_offset.X += (int)(m_plunger_speed.X * dt);
|
||||
m_plunger_offset.Y += (int)(m_plunger_speed.Y * dt);
|
||||
|
||||
const int plunger_size = (int)(0.6f * screen_width);
|
||||
int offset_y = viewport.UpperLeftCorner.Y + viewport.getHeight()/2
|
||||
- plunger_size/2 - plunger_offset;
|
||||
- plunger_size/2 - m_plunger_offset.Y;
|
||||
|
||||
int plunger_x = viewport.UpperLeftCorner.X + screen_width/2
|
||||
- plunger_size/2;
|
||||
|
||||
video::ITexture *t=m_plunger_face->getTexture();
|
||||
plunger_x += (int)m_plunger_offset.X;
|
||||
core::rect<s32> dest(plunger_x, offset_y,
|
||||
plunger_x+plunger_size, offset_y+plunger_size);
|
||||
|
||||
|
@ -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=
|
||||
|
@ -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
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user