Files
itgmania212121/stepmania/src/ArrowEffects.cpp
T

193 lines
5.7 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-02-24 10:31:20 +00:00
/*
-----------------------------------------------------------------------------
File: ArrowEffects.cpp
Desc: Functions that return properties of arrows based on StyleDef and PlayerOptions
2002-02-24 10:31:20 +00:00
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2002-02-24 10:31:20 +00:00
Chris Danford
-----------------------------------------------------------------------------
*/
2002-02-24 10:31:20 +00:00
#include "ArrowEffects.h"
2002-05-19 01:59:48 +00:00
#include "Notes.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2002-04-16 17:31:00 +00:00
#include "GameManager.h"
2002-07-23 01:41:40 +00:00
#include "GameState.h"
2002-07-27 19:29:51 +00:00
#include "RageException.h"
#include "RageTimer.h"
#include "NoteDisplay.h"
#include <math.h>
2002-02-24 10:31:20 +00:00
2003-01-25 11:05:12 +00:00
RageTimer g_timerExpand;
float g_fExpandSeconds = 0;
float ArrowGetYOffset( PlayerNumber pn, float fNoteBeat )
2002-02-24 10:31:20 +00:00
{
2002-07-29 03:06:55 +00:00
float fSongBeat = GAMESTATE->m_fSongBeat;
float fBeatsUntilStep = fNoteBeat - fSongBeat;
2002-02-24 10:31:20 +00:00
float fYOffset = fBeatsUntilStep * ARROW_GAP;
/* With both boost and wave enabled, the effect is that the
2002-09-30 02:19:02 +00:00
* notes "buffer" at the bottom of the screen and shoot out
* at high speed.
*
* With wave first, the boost appears halfway down the screen.
* With boost first, it appears about 1/4 down the screen.
*
* I'm not sure which is better. - glenn
*/
2003-01-25 11:05:12 +00:00
/* Boost and wave can no longer be used at the same time. -Chris */
switch( GAMESTATE->m_PlayerOptions[pn].m_AccelType )
{
case PlayerOptions::ACCEL_BOOST:
fYOffset *= 1.5f / ((fYOffset+SCREEN_HEIGHT/1.2f)/SCREEN_HEIGHT);
break;
case PlayerOptions::ACCEL_LAND:
if( fYOffset > 0 ) // speed the arrows back to normal after they cross 0
fYOffset *= SCALE( fYOffset, 0.f, SCREEN_HEIGHT, 0.25f, 1.5f );
2003-01-25 11:05:12 +00:00
break;
case PlayerOptions::ACCEL_WAVE:
fYOffset += 20.0f*sinf( fYOffset/38.0f );
break;
case PlayerOptions::ACCEL_EXPAND:
if( !GAMESTATE->m_bFreeze )
g_fExpandSeconds += g_timerExpand.GetDeltaTime();
else
g_timerExpand.GetDeltaTime(); // throw away
fYOffset *= SCALE( cosf(g_fExpandSeconds*3), -1, 1, 0.5f, 1.5f );
break;
case PlayerOptions::ACCEL_BOOMERANG:
fYOffset *= SCALE( fYOffset, 0.f, SCREEN_HEIGHT, 1.5f, 0.5f );
break;
}
2002-02-24 10:31:20 +00:00
return fYOffset;
}
float ArrowGetXPos( PlayerNumber pn, int iColNum, float fYPos )
2002-02-24 10:31:20 +00:00
{
float fPixelOffsetFromCenter = GAMESTATE->GetCurrentStyleDef()->m_ColumnInfo[pn][iColNum].fXOffset;
2002-02-24 10:31:20 +00:00
2002-09-30 02:19:02 +00:00
if( GAMESTATE->m_PlayerOptions[pn].m_bEffects[PlayerOptions::EFFECT_DRUNK] )
2002-12-19 23:07:20 +00:00
fPixelOffsetFromCenter += cosf( RageTimer::GetTimeSinceStart() + iColNum*0.2f + fYPos*6/SCREEN_HEIGHT) * ARROW_SIZE*0.5f;
2002-09-30 02:19:02 +00:00
if( GAMESTATE->m_PlayerOptions[pn].m_bEffects[PlayerOptions::EFFECT_FLIP] )
fPixelOffsetFromCenter = -fPixelOffsetFromCenter;
2002-09-30 02:19:02 +00:00
if( GAMESTATE->m_PlayerOptions[pn].m_bEffects[PlayerOptions::EFFECT_TORNADO] )
{
const StyleDef* pStyleDef = GAMESTATE->GetCurrentStyleDef();
float fMaxX = -100000, fMinX = +100000;
for( int i=0; i<pStyleDef->m_iColsPerPlayer; i++ )
{
fMaxX = max( fMaxX, pStyleDef->m_ColumnInfo[pn][i].fXOffset );
fMinX = min( fMinX, pStyleDef->m_ColumnInfo[pn][i].fXOffset );
}
float fPositionBetween = SCALE( fPixelOffsetFromCenter, fMinX, fMaxX, -1, 1 );
float fRads = acosf( fPositionBetween );
fRads += fYPos * 6 / SCREEN_HEIGHT;
fPixelOffsetFromCenter = SCALE( cosf(fRads), -1, 1, fMinX, fMaxX );
}
2002-02-24 10:31:20 +00:00
return fPixelOffsetFromCenter;
}
2003-01-25 11:05:12 +00:00
float ArrowGetRotation( PlayerNumber pn, float fNoteBeat )
2002-02-24 10:31:20 +00:00
{
2002-04-01 02:04:43 +00:00
float fRotation = 0; //StyleDef.m_ColumnToRotation[iColNum];
2002-02-25 23:29:39 +00:00
2002-09-30 02:19:02 +00:00
if( GAMESTATE->m_PlayerOptions[pn].m_bEffects[PlayerOptions::EFFECT_DIZZY] )
2003-01-25 11:05:12 +00:00
{
float fSongBeat = GAMESTATE->m_fSongBeat;
float fBeatsUntilStep = fNoteBeat - fSongBeat;
fRotation += fBeatsUntilStep;
}
2002-02-24 10:31:20 +00:00
return fRotation;
}
2003-01-25 11:05:12 +00:00
float ArrowGetYPosWithoutReverse( PlayerNumber pn, float fYOffset )
{
return fYOffset * GAMESTATE->m_PlayerOptions[pn].m_fScrollSpeed;
}
float ArrowGetYPos( PlayerNumber pn, float fYOffset )
2002-02-24 10:31:20 +00:00
{
2003-01-25 11:05:12 +00:00
return ArrowGetYPosWithoutReverse(pn,fYOffset) * (GAMESTATE->m_PlayerOptions[pn].m_bReverseScroll ? -1 : 1 );
2002-02-24 10:31:20 +00:00
}
const float fCenterLine = 160; // from fYPos == 0
const float fFadeDist = 100;
// used by ArrowGetAlpha and ArrowGetGlow below
float ArrowGetPercentVisible( PlayerNumber pn, float fYPos )
2002-02-24 10:31:20 +00:00
{
2002-08-01 03:15:27 +00:00
const bool bReverse = GAMESTATE->m_PlayerOptions[pn].m_bReverseScroll;
const float fCorrectedYPos = bReverse ? -fYPos : fYPos;
const float fDistFromCenterLine = fCorrectedYPos - fCenterLine;
float fAlpha;
2002-08-01 03:15:27 +00:00
2002-07-29 03:06:55 +00:00
switch( GAMESTATE->m_PlayerOptions[pn].m_AppearanceType )
2002-02-24 10:31:20 +00:00
{
case PlayerOptions::APPEARANCE_VISIBLE:
fAlpha = 1;
break;
case PlayerOptions::APPEARANCE_HIDDEN:
fAlpha = SCALE( fDistFromCenterLine, 0, fFadeDist, 0, 1 );
2002-02-24 10:31:20 +00:00
break;
case PlayerOptions::APPEARANCE_SUDDEN:
fAlpha = SCALE( fDistFromCenterLine, 0, -fFadeDist, 0, 1 );
2002-02-24 10:31:20 +00:00
break;
case PlayerOptions::APPEARANCE_STEALTH:
fAlpha = 0;
break;
case PlayerOptions::APPEARANCE_BLINK: // this is an Ez2dancer Appearance Mode
2002-12-19 23:07:20 +00:00
fAlpha = sinf( RageTimer::GetTimeSinceStart()*12 );
fAlpha = froundf( fAlpha, 0.3333f );
2002-02-24 10:31:20 +00:00
break;
default:
ASSERT(0);
2002-08-01 03:15:27 +00:00
fAlpha = 1;
}
if( fCorrectedYPos < 0 ) // past Gray Arrows
2002-02-24 10:31:20 +00:00
fAlpha = 1;
return clamp( fAlpha, 0, 1 );
}
2002-02-24 10:31:20 +00:00
2002-09-05 03:45:07 +00:00
float ArrowGetAlpha( PlayerNumber pn, float fYPos, float fPercentFadeToFail )
{
2002-09-05 03:45:07 +00:00
float fPercentVisible = ArrowGetPercentVisible(pn,fYPos);
if( fPercentFadeToFail != -1 )
fPercentVisible = 1 - fPercentFadeToFail;
return (fPercentVisible>0.5f) ? 1.0f : 0.0f;
}
2002-02-24 10:31:20 +00:00
2002-09-05 03:45:07 +00:00
float ArrowGetGlow( PlayerNumber pn, float fYPos, float fPercentFadeToFail )
{
2002-09-05 03:45:07 +00:00
float fPercentVisible = ArrowGetPercentVisible(pn,fYPos);
if( fPercentFadeToFail != -1 )
fPercentVisible = 1 - fPercentFadeToFail;
const float fDistFromHalf = fabsf( fPercentVisible - 0.5f );
return SCALE( fDistFromHalf, 0, 0.5f, 1.3f, 0 );
}
2003-02-12 22:05:14 +00:00
2003-02-12 22:52:28 +00:00
float ArrowGetBrightness( PlayerNumber pn, float fYOffset )
2003-02-12 22:05:14 +00:00
{
2003-02-12 22:52:28 +00:00
float fBrightness = SCALE( fYOffset, 0, -ARROW_SIZE, 1.f, 0.f );
2003-02-12 22:05:14 +00:00
CLAMP( fBrightness, 0, 1 );
2003-02-16 05:20:38 +00:00
// noisy printf( "fBrightness = %f\n", fBrightness );
2003-02-12 22:05:14 +00:00
return fBrightness;
}