/// <summary> /// Occurs when the level is about to be played /// </summary> public void Reset() { mTimeRemainingSecs = mTimeRemainingInitialSecs; mTimeState = eLevelTimeState.Normal; SoundBase.Ref.StopAllSounds(); if (!String.IsNullOrEmpty(mBackgroundMusicSoundName)) { SoundBase.Ref.PlaySound(mBackgroundMusicSoundName, true); } }
/// <summary> /// /// </summary> /// <param name="pDt"></param> public void OnFrameMove(float pDt) { // Check level complete if (mBalls.Count == 0) { Game.LevelComplete(); return; } // Manage remaining Time mTimeRemainingSecs -= pDt; if (mTimeRemainingSecs <= 0) { Game.mPlayer.LifeDown(); mTimeRemainingSecs = mTimeRemainingInitialSecs; mTimeState = eLevelTimeState.Normal; // Make the level re-start in pause mode Game.mPlayer.CollectPrize(Prize.ePrize.Pause); } else if (mTimeRemainingSecs <= 10) { if (mTimeState != eLevelTimeState.TimeAlmostUp) { mTimeState = eLevelTimeState.TimeAlmostUp; SoundBase.Ref.StopSound(mBackgroundMusicSoundName); SoundBase.Ref.StopSound(Level.mHurryUpMusicSoundName); SoundBase.Ref.PlaySound(Level.mTimeIsAlmostOverMusicSoundName); } } else if (mTimeRemainingSecs <= 30) { if (mTimeState != eLevelTimeState.HurryUp) { mTimeState = eLevelTimeState.HurryUp; SoundBase.Ref.StopSound(mBackgroundMusicSoundName); SoundBase.Ref.StopSound(Level.mTimeIsAlmostOverMusicSoundName); SoundBase.Ref.PlaySound(Level.mHurryUpMusicSoundName); } } // Manage pause time mPauseTime -= pDt; if (mPauseTime < 0) { mPauseTime = 0; } Ball.BallsPaused = mPauseTime > 0; // The management of balls, arrows, prizes, etc, could end up destroying elements like bricks, arrows... To allow directly modifying the collections without // exceptions in the loops, create backup lists List <Ball> ballsBackup = mBalls.ToList(); List <Arrow> arrowsBackup = mArrows.ToList(); List <Brick> bricksBackup = mBricks.ToList(); List <Prize> prizesBackup = mPrizes.ToList(); // Load contents for each element in level foreach (Brick brk in bricksBackup) { brk.OnFrameMove(pDt); } foreach (Ball b in ballsBackup) { // Check if all balls should be dinamited if (mDinamiteAllBalls && b.BallSize != eBallSize.S) { KillBall(b); break; } b.OnFrameMove(pDt); if (CheckIntersect_Player_Ball(Game.mPlayer, b)) { break; } } foreach (Arrow a in arrowsBackup) { a.OnFrameMove(pDt); // Check hits with balls foreach (Ball b in ballsBackup) { // If there's a hit, do not continue checking with other balls if (CheckIntersect_Arrow_Ball(a, b)) { break; } } // Check hits with bricks foreach (Brick b in bricksBackup) { // If there's a hit, do not continue checking with other bricks if (CheckIntersect_Arrow_Brick(a, b)) { break; } } } foreach (Prize p in prizesBackup) { p.OnFrameMove(pDt); // Check if player collects the prize if (Game.mPlayer.State != Player.eState.Dying && p.mDrawRectangle.Intersects(Game.mPlayer.mDrawRectangle)) { Game.mPlayer.CollectPrize(p.mType); mPrizes.Remove(p); } } foreach (Ladder l in mLadders) { l.OnFrameMove(pDt); } }