public void ContinueSequence() { canvasBestScore.SetActive(false); dState = DeathStates.Rewinding; Time.timeScale = 1; rewindSpeed = distanceTravelled / rewindTime; timer = 0; musicManager.PlaySFX(rewindClip); }
public override void SetDeathState(DeathStates deathState) { if (deathState == DeathStates.Dead) StopMotion(); else StartMotion(); base.SetDeathState(deathState); }
public override void SetDeathState(DeathStates deathState) { if (deathState == DeathStates.Dead) { // Cast Slimy Trick CastEffect(9, this); ObjectState = ObjectStates.Removed; } }
public void StartDeathSequence() { if (GameObject.FindGameObjectWithTag("ScoreManager").GetComponent <ScoreManager>().Score > GameManager.instance.GetLowestBestScore()) { musicManager.PlaySFX(bestScoreClip); } deathSequence = true; GameObject.FindObjectOfType <ItemGenerator>().GetComponent <ItemGenerator>().StopGeneration(); GameObject.FindObjectOfType <ObjectDestroyer>().GetComponent <ObjectDestroyer>().DestroyScene(); dState = DeathStates.Stopping; timer = 0; }
public virtual void SetDeathState(DeathStates deathState) { if (deathState == DeathStates.Dead) { // Remove All Effects effectList.RemoveAll(); } this.deathState = deathState; }
/// <summary> /// Checks to see if given object is colliding with any other object and handles the collision /// </summary> /// <param name="physObj">object to see if anything is colliding with it</param> private void HandleCollisions(PhysicsObject physObj, ref GameStates gameState) { // keep track of all object colliding with physObj List<GameObject> collidingList = new List<GameObject>(); Vector2 gridPos = GridSpace.GetGridCoord(physObj.mPosition); //Goes through the 9 possible positions for collision to see if this physics object is colliding with anything for (int i = -1; i < 2; i++) { if (gridPos.Y + i < 0 || gridPos.Y + i >= mCollisionMatrix.Length) continue;//Bounds check for (int j = -1; j < 2; j++) { if (gridPos.X + j < 0 || gridPos.X + j >= mCollisionMatrix[(int)gridPos.Y + i].Length) continue;//Bounds check foreach (GameObject obj in mCollisionMatrix[(int)gridPos.Y+i][(int)gridPos.X+j]) { bool collided = false; if (physObj.IsSquare && obj.IsSquare)// both squares { collided = physObj.IsCollidingBoxAndBox(obj); } else if (!physObj.IsSquare && obj.IsSquare) // phys obj is circle { collided = physObj.IsCollidingCircleAndBox(obj); } else if (physObj.IsSquare && !obj.IsSquare) //obj is circle { collided = physObj.IsCollidingBoxAndCircle(obj); } else // both circles { collided = physObj.IsCollidingCircleandCircle(obj); } if (obj.Equals(physObj) || obj is PlayerEnd && !(physObj is Player)) continue; if (collided && !(obj is PlayerEnd)) { collidingList.Add(obj); } //If player reaches the end, set the timer to 0 if (collided && obj is PlayerEnd && physObj is Player) { mPlayer.mCurrentTexture = PlayerFaces.FromString("Laugh"); mPlayerEnd.mCurrentTexture = PlayerFaces.FromString("GirlLaugh3"); GameSound.StopOthersAndPlay(GameSound.level_stageVictory); mPhysicsEnvironment.GravityDirection = GravityDirections.Down; gameState = GameStates.Unlock; } //If player collided with a collectable object if (collided && ((physObj is Player) && obj.CollisionType == XmlKeys.COLLECTABLE || (obj is Player) && physObj.CollisionType == XmlKeys.COLLECTABLE)) { if (physObj.CollisionType == XmlKeys.COLLECTABLE) { mCollected.Add(physObj); mRemoveCollected.Add(physObj); mCollectableLocations.Remove(physObj.mPosition); } else if (obj.CollisionType == XmlKeys.COLLECTABLE) { mCollected.Add(obj); mRemoveCollected.Add(obj); mCollectableLocations.Remove(obj.mPosition); } GameSound.playerCol_collectable.Play(GameSound.volume * 0.8f, 0f, 0f); collectibleEngine.EmitterLocation = new Vector2(obj.mPosition.X + 32, obj.mPosition.Y + 32); collectibleEngine.Update(10); } //If player hits a hazard else if (collided && ((physObj is Player) && obj.CollisionType == XmlKeys.HAZARDOUS || (obj is Player) && physObj.CollisionType == XmlKeys.HAZARDOUS)) { // Particle Effects (don't work). //Vector2 one = new Vector2(obj.mPosition.X + 32, obj.mPosition.Y + 32); //Vector2 two = new Vector2(physObj.mPosition.X + 32, physObj.mPosition.Y + 32); //Vector2 midpoint = new Vector2((one.X + two.X) / 2, (one.Y + two.Y) / 2); //wallEngine.EmitterLocation = midpoint; //wallEngine.Update(10); GameSound.playerSound_death.Play(GameSound.volume * 0.8f, 0.0f, 0.0f); if (physObj is Player) { physObj.Kill(); mPlayerEnd.mCurrentTexture = PlayerFaces.FromString("GirlSad"); } else { ((Player)obj).Kill(); mPlayerEnd.mCurrentTexture = PlayerFaces.FromString("GirlSad"); } //Get difference of two positions mDeathPanLength = Vector3.Subtract(new Vector3(mPlayer.SpawnPoint.X - 275, mPlayer.SpawnPoint.Y - 100, 0), mCam.Position); //Divide by scaling factor to get camera pan at each update. mDeathPanLength = Vector3.Divide(mDeathPanLength, SCALING_FACTOR); //Set the update counter to zero mDeathPanUpdates = 0; gameState = GameStates.Death; mDeathState = DeathStates.Respawning; mHasRespawned = false; return; } } //Start any animations on walls we are touching if (physObj is Player) foreach (GameObject cObject in collidingList) { if (cObject is Wall) { KeyValuePair<Vector2, string> animation = ((Wall)cObject).NearestWallPosition(physObj.mPosition); if (!mActiveAnimations.ContainsKey(animation.Key)) mActiveAnimations.Add(animation.Key, GetAnimation(animation.Value)); // Particle Effects. //if (cObject != lastCollided[0] && cObject != lastCollided[1]) if (cObject != lastCollided) { Vector2 one = new Vector2(mPlayer.Position.X + 32, mPlayer.Position.Y + 32); Vector2 two = new Vector2(animation.Key.X + 32, animation.Key.Y + 32); Vector2 midpoint = new Vector2((one.X + two.X) / 2, (one.Y + two.Y) / 2); wallEngine.EmitterLocation = midpoint; wallEngine.Update(10); // play wall collision sound GameSound.playerCol_wall.Play(GameSound.volume * 0.8f, 0f, 0f); //lastCollided[1] = lastCollided[0]; //lastCollided[0] = cObject; lastCollided = cObject; } } else if (cObject is MovingTile && !((MovingTile)cObject).BeingAnimated && cObject.CollisionType != XmlKeys.HAZARDOUS) ((MovingTile)cObject).StartAnimation(GetAnimation(cObject.mName)); else if (cObject is ReverseTile && !((ReverseTile)cObject).BeingAnimated && cObject.CollisionType != XmlKeys.HAZARDOUS) ((ReverseTile)cObject).StartAnimation(GetAnimation(cObject.mName)); else if (cObject is StaticObject && cObject.CollisionType != XmlKeys.COLLECTABLE) { if (!mActiveAnimations.ContainsKey(cObject.mPosition)) mActiveAnimations.Add(cObject.mPosition, GetAnimation(cObject.mName)); // Particle Effects. //if (cObject != lastCollided[0] && cObject != lastCollided[1]) if (cObject != lastCollided) { Vector2 one = new Vector2(mPlayer.Position.X + 32, mPlayer.Position.Y + 32); Vector2 two = new Vector2(cObject.mPosition.X + 32, cObject.mPosition.Y + 32); Vector2 midpoint = new Vector2((one.X + two.X) / 2, (one.Y + two.Y) / 2); wallEngine.EmitterLocation = midpoint; wallEngine.Update(10); // play wall collision sound GameSound.playerCol_wall.Play(GameSound.volume * 0.8f, 0f, 0f); //lastCollided[1] = lastCollided[0]; //lastCollided[0] = cObject; lastCollided = cObject; } } } physObj.HandleCollisionList(collidingList); } } }
/// <summary> /// Updates the level's progress /// </summary> /// <param name="gameTime">The game time.</param> /// <param name="gameState">State of the game.</param> public void Update(GameTime gameTime, ref GameStates gameState) { if (mPlayer.mIsAlive)// only update while player is alive { for (int i = 0; i < backGroundParticleCount && !IsMainMenu; i++) { Random random = new Random(); Vector2 randomness = new Vector2((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1)); backgroundParticles[i].Velocity = Vector2.Multiply(mPhysicsEnvironment.GravityForce, 5) + Vector2.Multiply(mPlayer.mVelocity,.25f) + backgroundParticles[i].Randomness; backgroundParticles[i].Update(); Vector2 posDiff = mPlayer.Position - backgroundParticles[i].Position; if (posDiff.X < -mScreenRect.Width || posDiff.Y < -mScreenRect.Height || posDiff.X > mScreenRect.Width|| posDiff.Y > mScreenRect.Height) backgroundParticles[i].Position = posDiff + mPlayer.Position; } if (mDeathState == DeathStates.Playing) { mTimer += (gameTime.ElapsedGameTime.TotalSeconds); if (mPlayerEnd != null) mPlayerEnd.UpdateFace(mTimer); foreach (GameObject gObject in mObjects) { if (gObject.CollisionType == XmlKeys.COLLECTABLE) { if (mCollectableAnimation == null) { mCollectableAnimation = GetAnimation(gObject.mName); } if (!mCollectableLocations.Contains(gObject.mPosition)) { mCollectableLocations.Add(gObject.mPosition); } } if (gObject is PhysicsObject) { PhysicsObject pObject = (PhysicsObject)gObject; pObject.FixForBounds((int)Size.X, (int)Size.Y, isCameraFixed); Vector2 oldPos = GridSpace.GetGridCoord(pObject.mPosition); if (pObject is Player) { ((Player)pObject).CurrentTime = (int)mTimer; } pObject.Update(gameTime); // Update zoom based on players velocity pObject.FixForBounds((int)Size.X, (int)Size.Y, isCameraFixed); UpdateCollisionMatrix(pObject, oldPos); // handle collision right after you move HandleCollisions(pObject, ref gameState); if (pObject is Player) foreach (Trigger trigger in mTrigger) trigger.RunTrigger(mObjects, (Player)pObject); } if (!mHasRespawned) break; } //Update wall animations for(int i = 0; i < mActiveAnimations.Count; i++) { KeyValuePair<Vector2, AnimatedSprite> current = mActiveAnimations.ElementAt(i); current.Value.Update((float)gameTime.ElapsedGameTime.TotalSeconds); if (current.Value.Frame == 0 && current.Value.PreviousFrame == current.Value.LastFrame - 1) mActiveAnimations.Remove(current.Key); } //Update collectable animations if (mCollectableAnimation != null) mCollectableAnimation.Update((float)gameTime.ElapsedGameTime.TotalSeconds); //Check to see if we collected anything if (mRemoveCollected.Count > 0) { mNumCollected = mNumCollectable - (mNumCollectable - mCollected.Count()); //Safely remove the collected objects foreach (GameObject g in mRemoveCollected) { RemoveFromMatrix(g); mObjects.Remove(g); mCollectableLocations.Remove(g.mPosition); } //Then clear the list mRemoveCollected.Clear(); } //Update number of deaths occured mDeaths = 5 - mPlayer.mNumLives; // Update the camera to keep the player at the center of the screen // Also only update if the velocity if greater than 0.5f in either direction if (!isCameraFixed && (Math.Abs(mPlayer.ObjectVelocity.X) > 0.5f || Math.Abs(mPlayer.ObjectVelocity.Y) > 0.5f)) { mCam.Position = new Vector3(mPlayer.Position.X - 275, mPlayer.Position.Y - 175, 0); } else if(isCameraFixed) { mCam.Position = new Vector3(mPlayer.SpawnPoint.X - 275, mPlayer.SpawnPoint.Y - 100, 0); } //Pause if (mControls.isStartPressed(false) || Guide.IsVisible) if (gameState == GameStates.In_Game) gameState = GameStates.Pause; } else if (mDeathState == DeathStates.Respawning) { mDeathState = DeathStates.Panning; Respawn(); } else//Pan back to player after death { mCam.Position += mDeathPanLength; mDeathPanUpdates++; if (mDeathPanUpdates == SCALING_FACTOR) mDeathState = DeathStates.Playing; } } if (!mPlayer.mIsAlive) { mPlayer.StopRumble(); if (mControls.isAPressed(false))// resets game after game over { mPlayer.mNumLives = 5; mPlayer.mIsAlive = true; mNumCollected = 0; mTimer = 0; //Add the collected objects back to the object list foreach (GameObject collected in mCollected) mObjects.Add(collected); //Reset the collision matrix PrepareCollisionMatrix(); //Clear the collection lists mCollected.Clear(); mRemoveCollected.Clear(); } } collectibleEngine.Update(0); wallEngine.Update(0); }
// Update is called once per frame void Update() { if (!deathSequence) { distanceTravelled += -speed * Time.deltaTime; transform.position = pathCreator.path.GetPointAtDistance(distanceTravelled); transform.up = -pathCreator.path.GetDirectionAtDistance(distanceTravelled); } else { timer += Time.deltaTime; switch (dState) { case DeathStates.Stopping: speed = Mathf.Lerp(speed, 0, timer / stoppingTime); musicManager.setVolume(Mathf.Lerp(musicManager.GetMusicVolume(), 0, timer / stoppingTime)); foreach (RoundParallax par in parallaxList) { par.Speed = Mathf.Lerp(par.Speed, 0, timer / stoppingTime); } if (speed == 0) { if (GameObject.FindGameObjectWithTag("ScoreManager").GetComponent <ScoreManager>().Score > GameManager.instance.GetLowestBestScore()) { canvasBestScore.GetComponent <BestScoreMenuManager>().LoadData(); canvasBestScore.SetActive(true); Time.timeScale = 0; } else { dState = DeathStates.Rewinding; rewindSpeed = distanceTravelled / rewindTime; timer = 0; musicManager.PlaySFX(rewindClip); } } break; case DeathStates.Rewinding: Rewind(); if (distanceTravelled >= 0) { dState = DeathStates.LoadingScene; } break; case DeathStates.LoadingScene: musicManager.RestartSynchronization(); GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth>().RestartCharacter(); GameObject.FindObjectOfType <ItemGenerator>().GetComponent <ItemGenerator>().RestartLevelDifficulty(); GameObject.FindGameObjectWithTag("ScoreManager").GetComponent <ScoreManager>().ResetScore(); //SceneManager.LoadScene(SceneManager.GetActiveScene().name); for (int i = 0; i < parallaxList.Count; i++) { parallaxList[i].Speed = parallaxSpeedList[i]; } deathSequence = false; speed = initialSpeed; break; } } }
public override void SetDeathState(DeathStates deathState) { if (deathState == DeathStates.Dead) { respawnTimer = 3000; } base.SetDeathState(deathState); }
/// <summary> /// Updates the level's progress /// </summary> /// <param name="gameTime">The game time.</param> /// <param name="gameState">State of the game.</param> public void Update(GameTime gameTime, ref GameStates gameState) { if (_mPlayer.MIsAlive)// only update while player is alive { if (!_bw.IsBusy) _bw.RunWorkerAsync(); if (_mDeathState == DeathStates.Playing) { MTimer += (gameTime.ElapsedGameTime.TotalSeconds); if (_mPlayerEnd != null) _mPlayerEnd.UpdateFace(MTimer); foreach (var gObject in _mObjects) { if (gObject.CollisionType == XmlKeys.Collectable) { if (_mCollectableAnimation == null) { _mCollectableAnimation = GetAnimation(gObject.MName); } if (!_mCollectableLocations.Contains(gObject.MPosition)) { _mCollectableLocations.Add(gObject.MPosition); } } if (gObject.CollisionType == XmlKeys.Hazardous) { if (gObject is ReverseTile) { if (_mReverseHazardAnimation == null) { _mReverseHazardAnimation = GetAnimation("ReverseMovingHazard"); } } else if (gObject is MovingTile) { if (_mHazardAnimation == null) _mHazardAnimation = GetAnimation("MovingHazard"); } } if (gObject is PhysicsObject) { var pObject = (PhysicsObject)gObject; pObject.FixForBounds((int)Size.X, (int)Size.Y, IsMainMenu); var oldPos = GridSpace.GetGridCoord(pObject.MPosition); if (pObject is Player) { ((Player)pObject).CurrentTime = (int)MTimer; } pObject.Update(gameTime); // Update zoom based on players velocity pObject.FixForBounds((int)Size.X, (int)Size.Y, IsMainMenu); UpdateCollisionMatrix(pObject, oldPos); // handle collision right after you move HandleCollisions(pObject, ref gameState); if (pObject is Player) foreach (var trigger in _mTrigger) trigger.RunTrigger(_mObjects, (Player)pObject); } if (!_mHasRespawned) break; } //Update wall animations for(var i = 0; i < _mActiveAnimations.Count; i++) { var current = _mActiveAnimations.ElementAt(i); current.Value.Update((float)gameTime.ElapsedGameTime.TotalSeconds); if (current.Value.Frame == 0 && current.Value.PreviousFrame == current.Value.LastFrame - 1) _mActiveAnimations.Remove(current.Key); } //Update collectable animations if (_mCollectableAnimation != null) _mCollectableAnimation.Update((float)gameTime.ElapsedGameTime.TotalSeconds); //Update hazard animations if (_mHazardAnimation != null) _mHazardAnimation.Update((float)gameTime.ElapsedGameTime.TotalSeconds); if (_mReverseHazardAnimation != null) _mReverseHazardAnimation.Update((float)gameTime.ElapsedGameTime.TotalSeconds); //Check to see if we collected anything if (_mRemoveCollected.Count > 0) { MNumCollected = MNumCollectable - (MNumCollectable - _mCollected.Count()); //Safely remove the collected objects foreach (var g in _mRemoveCollected) { RemoveFromMatrix(g); _mObjects.Remove(g); _mCollectableLocations.Remove(g.MPosition); } //Then clear the list _mRemoveCollected.Clear(); } //Update number of deaths occured MDeaths = 5 - _mPlayer.MNumLives; // Update the camera to keep the player at the center of the screen // Also only update if the velocity if greater than 0.5f in either direction if (!IsMainMenu && (Math.Abs(_mPlayer.ObjectVelocity.X) > 0.5f || Math.Abs(_mPlayer.ObjectVelocity.Y) > 0.5f)) { MCam.Position = new Vector3(_mPlayer.Position.X - 275, _mPlayer.Position.Y - 175, 0); } else if(IsMainMenu) { MCam.Position = new Vector3(_mPlayer.SpawnPoint.X - 275, _mPlayer.SpawnPoint.Y - 100, 0); } //Pause if (_mControls.IsStartPressed(false) || Guide.IsVisible) if (gameState == GameStates.InGame) gameState = GameStates.Pause; } else if (_mDeathState == DeathStates.Respawning) { _mDeathState = DeathStates.Panning; Respawn(); } else//Pan back to player after death { MCam.Position += _mDeathPanLength; _mDeathPanUpdates++; if (_mDeathPanUpdates == ScalingFactor) _mDeathState = DeathStates.Playing; } } if (!_mPlayer.MIsAlive) { _mPlayer.StopRumble(); if (_mControls.IsAPressed(false))// resets game after game over { _mPlayer.MNumLives = 5; _mPlayer.MIsAlive = true; MNumCollected = 0; MTimer = 0; //Add the collected objects back to the object list foreach (var collected in _mCollected) _mObjects.Add(collected); //Reset the collision matrix PrepareCollisionMatrix(); //Clear the collection lists _mCollected.Clear(); _mRemoveCollected.Clear(); } } _collectibleEngine.Update(0); _wallEngine.Update(0); }