#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 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; } void BGAnimationLayer::LoadFromStaticGraphic( CString sPath ) { m_iNumSprites = 1; m_Sprites[0].Load( sPath ); 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].Load( sMoviePath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].GetTexture()->Play(); ::Sleep( 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].Load( 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 ) { sPath.MakeLower(); if( sPath.Find("usesongbg") != -1 ) { LoadFromStaticGraphic( sSongBGPath ); return; // this will ignore other effects in the file name } const CString EFFECT_STRING[NUM_EFFECTS] = { "center", "stretchstill", "scretchscrollleft", "stretchscrollright", "stretchscrollup", "stretchscrolldown", "stretchwater", "stretchbubble", "stretchtwist", "stretchspin", "particlesspiralout", "particlesspiralin", "particlesfloatup", "particlesfloatdown", "particlesfloatleft", "particlesfloatright", "particlesbounce", "tilestill", "tilescrollleft", "tilescrollright", "tilescrollup", "tilescrolldown", "tileflipx", "tileflipy", "tilepulse", }; 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; 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(); }