Files
itgmania212121/stepmania/src/ScoreDisplayNormal.cpp
T

92 lines
2.1 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-07-23 01:41:40 +00:00
/*
-----------------------------------------------------------------------------
Class: ScoreDisplayNormal.h
Desc: A graphic displayed in the ScoreDisplayNormal during Dancing.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "ScoreDisplayNormal.h"
#include "RageUtil.h"
#include "RageLog.h"
#include "PrefsManager.h"
#include "GameState.h"
#include "ThemeManager.h"
2002-07-23 01:41:40 +00:00
const float SCORE_TWEEN_TIME = 0.2f;
2003-02-25 00:33:42 +00:00
const int NUM_SCORE_DIGITS = 9;
2002-07-23 01:41:40 +00:00
ScoreDisplayNormal::ScoreDisplayNormal()
{
LOG->Trace( "ScoreDisplayNormal::ScoreDisplayNormal()" );
2002-07-23 01:41:40 +00:00
2003-05-05 06:48:20 +00:00
m_sprFrame.Load( THEME->GetPathToG("ScoreDisplayNormal frame") );
this->AddChild( &m_sprFrame );
2002-07-23 01:41:40 +00:00
// init the text
m_text.LoadFromNumbers( THEME->GetPathToN("ScoreDisplayNormal") );
m_text.SetShadowLength( 0 );
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
m_iScore = 0;
m_iTrailingScore = 0;
m_iScoreVelocity = 0;
2002-07-23 01:41:40 +00:00
CString s;
for( int i=0; i<NUM_SCORE_DIGITS; i++ )
s += ' ';
2003-02-25 00:33:42 +00:00
m_text.SetText( s );
this->AddChild( &m_text );
2002-07-23 01:41:40 +00:00
}
2003-02-25 00:33:42 +00:00
void ScoreDisplayNormal::Init( PlayerNumber pn )
2002-07-23 01:41:40 +00:00
{
2003-02-25 00:33:42 +00:00
ScoreDisplay::Init( pn );
m_text.SetDiffuse( PlayerToColor(pn) );
2002-07-23 01:41:40 +00:00
}
2003-06-18 20:08:39 +00:00
void ScoreDisplayNormal::SetScore( int iNewScore )
{
m_iScore = iNewScore;
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
int iDelta = m_iScore - m_iTrailingScore;
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
m_iScoreVelocity = int(float(iDelta) / SCORE_TWEEN_TIME); // in score units per second
2002-07-23 01:41:40 +00:00
}
2003-02-25 00:33:42 +00:00
void ScoreDisplayNormal::SetText( CString s )
{
m_text.SetText( s );
}
2002-07-23 01:41:40 +00:00
void ScoreDisplayNormal::Update( float fDeltaTime )
{
2003-02-25 00:33:42 +00:00
ScoreDisplay::Update( fDeltaTime );
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
if( m_iTrailingScore != m_iScore )
2002-07-23 01:41:40 +00:00
{
// adjust for when player fails
int increment = int(m_iScoreVelocity * fDeltaTime);
if (m_iScoreVelocity != 0 && increment == 0) increment = 1;
2003-06-18 20:08:39 +00:00
int iDeltaBefore = m_iScore - m_iTrailingScore;
m_iTrailingScore += increment;
2003-06-18 20:08:39 +00:00
int iDeltaAfter = m_iScore - m_iTrailingScore;
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
if( (iDeltaBefore < 0 && iDeltaAfter > 0) ||
(iDeltaBefore > 0 && iDeltaAfter < 0) ) // the sign changed
2002-07-28 20:28:37 +00:00
{
2003-06-18 20:08:39 +00:00
m_iTrailingScore = m_iScore;
m_iScoreVelocity = 0;
2002-07-28 20:28:37 +00:00
}
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
m_text.SetText( ssprintf("%*.0i", NUM_SCORE_DIGITS, m_iTrailingScore) );
2002-07-23 01:41:40 +00:00
}
}