#include "stdafx.h" /* ----------------------------------------------------------------------------- Class: BGAnimation Desc: Particles used initially for background effects Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Ben Nordstrom Chris Danford ----------------------------------------------------------------------------- */ #include "BGAnimationLayer.h" #include "PrefsManager.h" #include "GameState.h" #include "IniFile.h" #include "RageMath.h" #include "SDL_utils.h" #include inline float GetOffScreenLeft( Actor* pActor ) { return SCREEN_LEFT - pActor->GetZoomedWidth()/2; } inline float GetOffScreenRight( Actor* pActor ) { return SCREEN_RIGHT + pActor->GetZoomedWidth()/2; } inline float GetOffScreenTop( Actor* pActor ) { return SCREEN_TOP - pActor->GetZoomedHeight()/2; } inline float GetOffScreenBottom(Actor* pActor ) { return SCREEN_BOTTOM+ pActor->GetZoomedHeight()/2; } inline bool IsOffScreenLeft( Actor* pActor ) { return pActor->GetX() < GetOffScreenLeft(pActor); } inline bool IsOffScreenRight( Actor* pActor ) { return pActor->GetX() > GetOffScreenRight(pActor); } inline bool IsOffScreenTop( Actor* pActor ) { return pActor->GetY() < GetOffScreenTop(pActor); } inline bool IsOffScreenBottom(Actor* pActor ) { return pActor->GetY() > GetOffScreenBottom(pActor); } // guard rail is the area that keeps particles from going off screen inline float GetGuardRailLeft( Actor* pActor ) { return SCREEN_LEFT + pActor->GetZoomedWidth()/2; } inline float GetGuardRailRight( Actor* pActor ) { return SCREEN_RIGHT - pActor->GetZoomedWidth()/2; } inline float GetGuardRailTop( Actor* pActor ) { return SCREEN_TOP + pActor->GetZoomedHeight()/2; } inline float GetGuardRailBottom(Actor* pActor ) { return SCREEN_BOTTOM- pActor->GetZoomedHeight()/2; } inline bool HitGuardRailLeft( Actor* pActor ) { return pActor->GetX() < GetGuardRailLeft(pActor); } inline bool HitGuardRailRight( Actor* pActor ) { return pActor->GetX() > GetGuardRailRight(pActor); } inline bool HitGuardRailTop( Actor* pActor ) { return pActor->GetY() < GetGuardRailTop(pActor); } inline bool HitGuardRailBottom(Actor* pActor ) { return pActor->GetY() > GetGuardRailBottom(pActor); } const float PARTICLE_VELOCITY = 300; const float SPIRAL_MAX_ZOOM = 2; const float SPIRAL_MIN_ZOOM = 0.3f; BGAnimationLayer::BGAnimationLayer() { m_iNumSprites = 0; m_bCycleColor = false; m_bCycleAlpha = false; m_Effect = EFFECT_STRETCH_STILL; /* Why doesn't this use the existing tweening mechanism? I can't make * sense of what this code is doing; all I can tell is that it's duplicating * stuff we already have. -glenn */ m_PosX = m_PosY = 0; m_Zoom = 0; m_Rot = 0; m_ShowTime = 0; m_HideTime = 0; m_TweenStartTime = 0; m_TweenX = m_TweenY = 0.0; m_TweenSpeed = 0; m_TweenState = 0; m_TweenPassedX = m_TweenPassedY = 0; } /* Static background layers are simple, uncomposited background images with nothing * behind them. Since they have nothing behind them, they have no need for alpha, * so turn that off. */ void BGAnimationLayer::LoadFromStaticGraphic( CString sPath ) { RageTextureID ID(sPath); ID.iAlphaBits = 0; m_iNumSprites = 1; m_Sprites[0].LoadBG( ID ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); } void BGAnimationLayer::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind ) { m_iNumSprites = 1; m_Sprites[0].LoadBG( sMoviePath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].GetTexture()->Play(); SDL_Delay( 50 ); // decode a frame so we don't see a black flash at the beginning m_Sprites[0].GetTexture()->Pause(); m_bRewindMovie = bRewind; if( !bLoop ) m_Sprites[0].GetTexture()->SetLooping(false); } void BGAnimationLayer::LoadFromVisualization( CString sMoviePath ) { m_iNumSprites = 1; m_Sprites[0].LoadBG( sMoviePath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].SetBlendModeAdd(); } void BGAnimationLayer::LoadFromAniLayerFile( CString sPath, CString sSongBGPath ) { CString lcPath = sPath; lcPath.MakeLower(); if( lcPath.Find("usesongbg") != -1 ) { LoadFromStaticGraphic( sSongBGPath ); return; // this will ignore other effects in the file name } const CString EFFECT_STRING[NUM_EFFECTS] = { "center", "stretchstill", "stretchscrollleft", "stretchscrollright", "stretchscrollup", "stretchscrolldown", "stretchwater", "stretchbubble", "stretchtwist", "stretchspin", "particlesspiralout", "particlesspiralin", "particlesfloatup", "particlesfloatdown", "particlesfloatleft", "particlesfloatright", "particlesbounce", "tilestill", "tilescrollleft", "tilescrollright", "tilescrollup", "tilescrolldown", "tileflipx", "tileflipy", "tilepulse", "stretchscrollhorizontal" }; for( int i=0; im_fSongBeat; if( m_bCycleColor ) { for( int i=0; i SPIRAL_MAX_ZOOM ) m_Sprites[i].SetZoom( SPIRAL_MIN_ZOOM ); m_Sprites[i].SetRotation( m_Sprites[i].GetRotation() + fDeltaTime ); float fRadius = (m_Sprites[i].GetZoom()-SPIRAL_MIN_ZOOM); fRadius *= fRadius; fRadius *= 200; m_Sprites[i].SetX( CENTER_X + cosf(m_Sprites[i].GetRotation())*fRadius ); m_Sprites[i].SetY( CENTER_Y + sinf(m_Sprites[i].GetRotation())*fRadius ); } break; case EFFECT_PARTICLES_SPIRAL_IN: for( i=0; i m_TweenY) // passed the location we wanna go to? { m_Sprites[0].SetY(m_TweenY); // set it to the exact location we want m_TweenPassedY = 1; // say we passed it. } } else // travelling up { m_Sprites[0].SetY(m_Sprites[0].GetY() - ((m_TweenY + m_PosY)/(m_TweenSpeed*60))); if(m_Sprites[0].GetY() < m_TweenY) { m_Sprites[0].SetY(m_TweenY); m_TweenPassedY = 1; } } } if(m_TweenPassedX != 1) // Check to see if we still need to Tween Along the X Axis { if(m_Sprites[0].GetX() < m_TweenX) // it needs to travel right { m_Sprites[0].SetX(m_Sprites[0].GetX() + ((m_TweenX - m_PosX)/(m_TweenSpeed*60))); if(m_Sprites[0].GetX() > m_TweenX) { m_Sprites[0].SetX(m_TweenX); m_TweenPassedX = 1; } } else // travelling left { m_Sprites[0].SetX(m_Sprites[0].GetX() - ((m_TweenX + m_PosX)/(m_TweenSpeed*60))); if(m_Sprites[0].GetX() < m_TweenX) { m_Sprites[0].SetX(m_TweenX); m_TweenPassedX = 1; } } } if(m_TweenPassedY == 1 && m_TweenPassedX == 1) // totally passed both X and Y? Stop tweening. { m_TweenState = 0; } } if(m_ShowTime != 0 && !(m_ShowTime < 0)) { m_ShowTime -= fDeltaTime; if(m_ShowTime <= 0) // if we've gone past the magic point... show the beast.... { m_Sprites[0].SetDiffuse( RageColor(1,1,1,1) ); } } if(m_HideTime != 0 && !(m_HideTime < 0)) // make sure it's not 0 or less than 0... { m_HideTime -= fDeltaTime; if(m_HideTime <= 0) // if we've gone past the magic point... hide the beast.... { m_Sprites[0].SetDiffuse( RageColor(0,0,0,0) ); } } } void BGAnimationLayer::Draw() { for( int i=0; iSetPosition( 0 ); // if movie texture, pause and play movie so we don't waste CPU cycles decoding frames that won't be shown m_Sprites[0].GetTexture()->Play(); } void BGAnimationLayer::LosingFocus() { m_Sprites[0].GetTexture()->Pause(); }