Files
itgmania212121/src/LifeMeterBattery.cpp
T

230 lines
5.8 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
#include "LifeMeterBattery.h"
#include "GameState.h"
#include "ThemeManager.h"
2003-08-03 00:13:55 +00:00
#include "Steps.h"
#include "PlayerState.h"
#include "Course.h"
2002-07-23 01:41:40 +00:00
const float BATTERY_X[NUM_PLAYERS] = { -92, +92 };
const float NUM_X[NUM_PLAYERS] = { BATTERY_X[0], BATTERY_X[1] };
const float NUM_Y = +2;
const float BATTERY_BLINK_TIME = 1.2f;
LifeMeterBattery::LifeMeterBattery()
{
m_iLivesLeft = GAMESTATE->m_SongOptions.GetStage().m_iBatteryLives;
2002-07-28 20:28:37 +00:00
m_iTrailingLivesLeft = m_iLivesLeft;
2002-07-23 01:41:40 +00:00
m_fBatteryBlinkTime = 0;
2005-02-06 03:32:53 +00:00
m_soundGainLife.Load( THEME->GetPathS("LifeMeterBattery","gain") );
m_soundLoseLife.Load( THEME->GetPathS("LifeMeterBattery","lose"),true );
2002-08-01 13:42:56 +00:00
}
void LifeMeterBattery::Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats )
2002-08-01 13:42:56 +00:00
{
LifeMeter::Load( pPlayerState, pPlayerStageStats );
2002-08-01 13:42:56 +00:00
bool bPlayerEnabled = GAMESTATE->IsPlayerEnabled( pPlayerState );
2002-08-01 13:42:56 +00:00
2005-02-06 03:32:53 +00:00
m_sprFrame.Load( THEME->GetPathG("LifeMeterBattery","frame") );
this->AddChild( &m_sprFrame );
2002-07-23 01:41:40 +00:00
2005-02-06 03:32:53 +00:00
m_sprBattery.Load( THEME->GetPathG("LifeMeterBattery","lives 1x4") );
2002-07-23 01:41:40 +00:00
m_sprBattery.StopAnimating();
2002-08-01 13:42:56 +00:00
if( bPlayerEnabled )
this->AddChild( &m_sprBattery );
2002-07-23 01:41:40 +00:00
2004-07-25 07:22:31 +00:00
m_textNumLives.LoadFromFont( THEME->GetPathF("LifeMeterBattery", "lives") );
m_textNumLives.SetDiffuse( RageColor(1,1,1,1) );
m_textNumLives.SetShadowLength( 0 );
2002-08-01 13:42:56 +00:00
if( bPlayerEnabled )
this->AddChild( &m_textNumLives );
2002-07-23 01:41:40 +00:00
PlayerNumber pn = pPlayerState->m_PlayerNumber;
2002-07-28 20:28:37 +00:00
m_sprFrame.SetZoomX( pn==PLAYER_1 ? 1.0f : -1.0f );
m_sprBattery.SetZoomX( pn==PLAYER_1 ? 1.0f : -1.0f );
m_sprBattery.SetX( BATTERY_X[pn] );
m_textNumLives.SetX( NUM_X[pn] );
2002-07-23 01:41:40 +00:00
m_textNumLives.SetY( NUM_Y );
2003-10-04 08:22:09 +00:00
if( bPlayerEnabled )
{
m_Percent.Load( pPlayerState, pPlayerStageStats, "LifeMeterBattery Percent", true );
m_Percent.SetZoomX( pn==PLAYER_1 ? 1.0f : -1.0f );
2003-10-04 08:22:09 +00:00
this->AddChild( &m_Percent );
}
2002-07-23 01:41:40 +00:00
Refresh();
2002-07-23 01:41:40 +00:00
}
2006-09-16 19:56:00 +00:00
void LifeMeterBattery::OnSongEnded()
2002-07-23 01:41:40 +00:00
{
if( m_pPlayerStageStats->m_bFailed || m_iLivesLeft == 0 )
2002-07-23 01:41:40 +00:00
return;
if( m_iLivesLeft < GAMESTATE->m_SongOptions.GetSong().m_iBatteryLives )
{
m_iTrailingLivesLeft = m_iLivesLeft;
PlayerNumber pn = m_pPlayerState->m_PlayerNumber;
const Course *pCourse = GAMESTATE->m_pCurCourse;
if( pCourse && pCourse->m_vEntries[GAMESTATE->GetCourseSongIndex()].iGainLives > -1 )
2006-09-16 19:56:00 +00:00
m_iLivesLeft += pCourse->m_vEntries[GAMESTATE->GetCourseSongIndex()].iGainLives;
else
m_iLivesLeft += ( GAMESTATE->m_pCurSteps[pn]->GetMeter()>=8 ? 2 : 1 );
m_iLivesLeft = min( m_iLivesLeft, GAMESTATE->m_SongOptions.GetSong().m_iBatteryLives );
2006-09-16 19:56:00 +00:00
if( m_iTrailingLivesLeft < m_iLivesLeft )
m_soundGainLife.Play();
}
2002-07-23 01:41:40 +00:00
Refresh();
}
2002-07-28 20:28:37 +00:00
2002-07-23 01:41:40 +00:00
void LifeMeterBattery::ChangeLife( TapNoteScore score )
{
2006-11-09 08:39:45 +00:00
if( m_iLivesLeft == 0 )
2002-07-23 01:41:40 +00:00
return;
switch( score )
{
case TNS_W1:
case TNS_W2:
case TNS_W3:
2002-07-23 01:41:40 +00:00
break;
case TNS_W4:
case TNS_W5:
case TNS_Miss:
case TNS_HitMine:
2002-07-28 20:28:37 +00:00
m_iTrailingLivesLeft = m_iLivesLeft;
2002-07-23 01:41:40 +00:00
m_iLivesLeft--;
m_soundLoseLife.Play();
m_textNumLives.SetZoom( 1.5f );
m_textNumLives.BeginTweening( 0.15f );
2003-04-12 06:16:12 +00:00
m_textNumLives.SetZoom( 1.0f );
2002-07-23 01:41:40 +00:00
Refresh();
m_fBatteryBlinkTime = BATTERY_BLINK_TIME;
break;
default:
ASSERT(0);
2002-07-23 01:41:40 +00:00
}
}
void LifeMeterBattery::ChangeLife( HoldNoteScore score, TapNoteScore tscore )
{
switch( score )
{
case HNS_Held:
break;
case HNS_LetGo:
ChangeLife( TNS_Miss ); // LetGo is the same as a miss
break;
default:
ASSERT(0);
}
}
void LifeMeterBattery::HandleTapScoreNone()
{
}
2003-11-11 07:36:28 +00:00
void LifeMeterBattery::ChangeLife( float fDeltaLifePercent )
{
}
2003-11-03 18:24:13 +00:00
bool LifeMeterBattery::IsInDanger() const
2002-07-23 01:41:40 +00:00
{
return false;
}
2003-11-03 18:24:13 +00:00
bool LifeMeterBattery::IsHot() const
2002-07-23 01:41:40 +00:00
{
return false;
}
2003-11-03 18:24:13 +00:00
bool LifeMeterBattery::IsFailing() const
2002-07-23 01:41:40 +00:00
{
2006-11-09 08:39:45 +00:00
return m_iLivesLeft == 0;
2002-07-23 01:41:40 +00:00
}
2003-10-23 06:15:58 +00:00
float LifeMeterBattery::GetLife() const
{
if( !GAMESTATE->m_SongOptions.GetSong().m_iBatteryLives )
2003-10-23 06:15:58 +00:00
return 1;
return float(m_iLivesLeft) / GAMESTATE->m_SongOptions.GetSong().m_iBatteryLives;
2003-10-23 06:15:58 +00:00
}
2002-07-23 01:41:40 +00:00
void LifeMeterBattery::Refresh()
{
2002-07-28 20:28:37 +00:00
if( m_iLivesLeft <= 4 )
2002-07-23 01:41:40 +00:00
{
m_textNumLives.SetText( "" );
2002-07-28 20:28:37 +00:00
m_sprBattery.SetState( max(m_iLivesLeft-1,0) );
2002-07-23 01:41:40 +00:00
}
else
{
m_textNumLives.SetText( ssprintf("x%d", m_iLivesLeft-1) );
2002-07-23 01:41:40 +00:00
m_sprBattery.SetState( 3 );
}
}
void LifeMeterBattery::Update( float fDeltaTime )
{
2002-07-28 20:28:37 +00:00
LifeMeter::Update( fDeltaTime );
if( m_fBatteryBlinkTime > 0 )
2002-07-23 01:41:40 +00:00
{
m_fBatteryBlinkTime -= fDeltaTime;
2002-07-28 20:28:37 +00:00
int iFrame1 = m_iLivesLeft-1;
int iFrame2 = m_iTrailingLivesLeft-1;
int iFrameNo = (int(m_fBatteryBlinkTime*15)%2) ? iFrame1 : iFrame2;
2002-07-23 01:41:40 +00:00
CLAMP( iFrameNo, 0, 3 );
m_sprBattery.SetState( iFrameNo );
2002-07-28 20:28:37 +00:00
}
else
{
m_fBatteryBlinkTime = 0;
int iFrameNo = m_iLivesLeft-1;
CLAMP( iFrameNo, 0, 3 );
m_sprBattery.SetState( iFrameNo );
2002-07-23 01:41:40 +00:00
}
2003-02-16 04:56:36 +00:00
}
2004-06-08 00:08:04 +00:00
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/