public override void updateEvenIfFarmerIsntHere(GameTime time, bool skipWasUpdatedFlush = false) { base.updateEvenIfFarmerIsntHere(time, skipWasUpdatedFlush); if (train.Value != null && train.Value.Update(time, this) && Game1.IsMasterGame) { train.Value = null; } if (!Game1.IsMasterGame) { return; } if (Game1.timeOfDay == trainTime - trainTime % 10 && (int)trainTimer == 0 && !Game1.isFestival() && train.Value == null) { setTrainComing(15000); } if ((int)trainTimer > 0) { trainTimer.Value -= time.ElapsedGameTime.Milliseconds; if ((int)trainTimer <= 0) { train.Value = new Train(); playSound("trainWhistle"); } if ((int)trainTimer < 3500 && Game1.currentLocation == this && Game1.soundBank != null && (trainLoop == null || !trainLoop.IsPlaying)) { trainLoop = Game1.soundBank.GetCue("trainLoop"); trainLoop.SetVariable("Volume", 0f); trainLoop.Play(); } } if (train.Value != null) { if (Game1.currentLocation == this && Game1.soundBank != null && (trainLoop == null || !trainLoop.IsPlaying)) { trainLoop = Game1.soundBank.GetCue("trainLoop"); trainLoop.SetVariable("Volume", 0f); trainLoop.Play(); } if (trainLoop != null && trainLoop.GetVariable("Volume") < 100f) { trainLoop.SetVariable("Volume", trainLoop.GetVariable("Volume") + 0.5f); } } else if (trainLoop != null && (int)trainTimer <= 0) { trainLoop.SetVariable("Volume", trainLoop.GetVariable("Volume") - 0.15f); if (trainLoop.GetVariable("Volume") <= 0f) { trainLoop.Stop(AudioStopOptions.Immediate); trainLoop = null; } } else if ((int)trainTimer > 0 && trainLoop != null) { trainLoop.SetVariable("Volume", trainLoop.GetVariable("Volume") + 0.15f); } }
public bool tick(GameTime time) { if (hasQuit) { return(true); } if (quit && !hasQuit) { Game1.warpFarmer("BusStop", 12, 11, flip: false); if (roadNoise != null) { roadNoise.Stop(AudioStopOptions.Immediate); } Game1.exitActiveMenu(); hasQuit = true; return(true); } switch (currentState) { case 0: updateUpperClouds(time); break; case 1: globalYPanDY = Math.Min(4f, globalYPanDY + (float)time.ElapsedGameTime.Milliseconds * (speed / 140f)); globalYPan -= globalYPanDY; updateUpperClouds(time); if (globalYPan < -1f) { globalYPan = screenHeight * 3; currentState = 2; transformMatrix = Matrix.CreateScale(3f); transformMatrix.Translation = new Vector3(0f, globalYPan, 0f); if (Game1.soundBank != null && roadNoise != null) { roadNoise.SetVariable("Volume", 0); roadNoise.Play(); } Game1.loadForNewGame(); } break; case 2: { int startPanY = screenHeight * 3; int endPanY = -Math.Max(0, 900 - (int)((float)Game1.viewport.Height * Game1.options.zoomLevel)); globalYPanDY = Math.Max(0.5f, globalYPan / 100f); globalYPan -= globalYPanDY; if (globalYPan <= (float)endPanY) { globalYPan = endPanY; } transformMatrix = Matrix.CreateScale(3f); transformMatrix.Translation = new Vector3(0f, globalYPan, 0f); updateRoad(time); if (Game1.soundBank != null && roadNoise != null) { float vol = (globalYPan - (float)startPanY) / (float)(endPanY - startPanY) * 10f + 90f; roadNoise.SetVariable("Volume", vol); } if (globalYPan <= (float)endPanY) { currentState = 3; } break; } case 3: updateRoad(time); drivingTimer += time.ElapsedGameTime.Milliseconds; if (drivingTimer > 5700f) { drivingTimer = 0f; currentState = 4; } break; case 4: updateRoad(time); drivingTimer += time.ElapsedGameTime.Milliseconds; if (!(drivingTimer > 2000f)) { break; } busPosition.X += (float)time.ElapsedGameTime.Milliseconds / 8f; if (Game1.soundBank != null && roadNoise != null) { roadNoise.SetVariable("Volume", Math.Max(0f, roadNoise.GetVariable("Volume") - 1f)); } speed = Math.Max(0f, speed - (float)time.ElapsedGameTime.Milliseconds / 70000f); if (!addedSign) { addedSign = true; roadsideObjects.RemoveAt(roadsideObjects.Count - 1); roadsideObjects.Add(5); Game1.playSound("busDriveOff"); } if (speed <= 0f && birdPosition.Equals(Vector2.Zero)) { int position = 0; for (int i = 0; i < roadsideObjects.Count; i++) { if (roadsideObjects[i] == 5) { position = i; break; } } birdPosition = new Vector2((float)(position * 16) - roadPosition - 32f + 16f, -16f); Game1.playSound("SpringBirds"); fadeAlpha = 0f; } if (!birdPosition.Equals(Vector2.Zero) && birdPosition.Y < 116f) { float dy = Math.Max(0.5f, (116f - birdPosition.Y) / 116f * 2f); birdPosition.Y += dy; birdPosition.X += (float)Math.Sin((double)birdXTimer / (Math.PI * 16.0)) * dy / 2f; birdTimer += time.ElapsedGameTime.Milliseconds; birdXTimer += time.ElapsedGameTime.Milliseconds; if (birdTimer >= 100) { birdFrame = (birdFrame + 1) % 4; birdTimer = 0; } } else if (!birdPosition.Equals(Vector2.Zero)) { birdFrame = ((birdTimer > 1500) ? 5 : 4); birdTimer += time.ElapsedGameTime.Milliseconds; if (birdTimer > 2400 || (birdTimer > 1800 && Game1.random.NextDouble() < 0.006)) { birdTimer = 0; if (Game1.random.NextDouble() < 0.5) { Game1.playSound("SpringBirds"); birdPosition.Y -= 4f; } } } if (!(drivingTimer > 14000f)) { break; } fadeAlpha += (float)time.ElapsedGameTime.Milliseconds * 0.1f / 128f; if (fadeAlpha >= 1f) { Game1.warpFarmer("BusStop", 12, 11, flip: false); if (roadNoise != null) { roadNoise.Stop(AudioStopOptions.Immediate); } Game1.exitActiveMenu(); return(true); } break; } return(false); }
protected override void updateAnimation(GameTime time) { if (Game1.soundBank != null && (buzz == null || !buzz.IsPlaying) && (base.currentLocation == null || base.currentLocation.Equals(Game1.currentLocation))) { buzz = Game1.soundBank.GetCue("flybuzzing"); buzz.SetVariable("Volume", 0f); buzz.Play(); } if ((double)Game1.fadeToBlackAlpha > 0.8 && Game1.fadeIn && buzz != null) { buzz.Stop(AudioStopOptions.AsAuthored); } else if (buzz != null) { buzz.SetVariable("Volume", Math.Max(0f, buzz.GetVariable("Volume") - 1f)); float volume = Math.Max(0f, 100f - Vector2.Distance(base.Position, base.Player.Position) / 64f / 16f * 100f); if (volume > buzz.GetVariable("Volume")) { buzz.SetVariable("Volume", volume); } } if (wasHitCounter >= 0) { wasHitCounter -= time.ElapsedGameTime.Milliseconds; } Sprite.Animate(time, (FacingDirection == 0) ? 8 : ((FacingDirection != 2) ? (FacingDirection * 4) : 0), 4, 75f); if (spawningCounter >= 0) { spawningCounter -= time.ElapsedGameTime.Milliseconds; base.Scale = 1f - (float)spawningCounter / 1000f; } else if ((withinPlayerThreshold() || Utility.isOnScreen(position, 256)) && invincibleCountdown <= 0) { faceDirection(0); float xSlope3 = -(base.Player.GetBoundingBox().Center.X - GetBoundingBox().Center.X); float ySlope3 = base.Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y; float t = Math.Max(1f, Math.Abs(xSlope3) + Math.Abs(ySlope3)); if (t < 64f) { xVelocity = Math.Max(-7f, Math.Min(7f, xVelocity * 1.1f)); yVelocity = Math.Max(-7f, Math.Min(7f, yVelocity * 1.1f)); } xSlope3 /= t; ySlope3 /= t; if (wasHitCounter <= 0) { targetRotation = (float)Math.Atan2(0f - ySlope3, xSlope3) - (float)Math.PI / 2f; if ((double)(Math.Abs(targetRotation) - Math.Abs(rotation)) > Math.PI * 7.0 / 8.0 && Game1.random.NextDouble() < 0.5) { turningRight = true; } else if ((double)(Math.Abs(targetRotation) - Math.Abs(rotation)) < Math.PI / 8.0) { turningRight = false; } if (turningRight) { rotation -= (float)Math.Sign(targetRotation - rotation) * ((float)Math.PI / 64f); } else { rotation += (float)Math.Sign(targetRotation - rotation) * ((float)Math.PI / 64f); } rotation %= (float)Math.PI * 2f; wasHitCounter = 5 + Game1.random.Next(-1, 2); } float maxAccel = Math.Min(7f, Math.Max(2f, 7f - t / 64f / 2f)); xSlope3 = (float)Math.Cos((double)rotation + Math.PI / 2.0); ySlope3 = 0f - (float)Math.Sin((double)rotation + Math.PI / 2.0); xVelocity += (0f - xSlope3) * maxAccel / 6f + (float)Game1.random.Next(-10, 10) / 100f; yVelocity += (0f - ySlope3) * maxAccel / 6f + (float)Game1.random.Next(-10, 10) / 100f; if (Math.Abs(xVelocity) > Math.Abs((0f - xSlope3) * 7f)) { xVelocity -= (0f - xSlope3) * maxAccel / 6f; } if (Math.Abs(yVelocity) > Math.Abs((0f - ySlope3) * 7f)) { yVelocity -= (0f - ySlope3) * maxAccel / 6f; } } resetAnimationSpeed(); }
/// <summary>Raised after the game state is updated (≈60 times per second).</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnUpdateTicked(object sender, UpdateTickedEventArgs e) { if (this.Cue != null) { ICue sound = this.Cue; sound.SetVariable("Volume", 100); sound.SetVariable("Frequency", this.Frequency); sound.SetVariable("Pitch", this.Pitch); if (!sound.IsPlaying) { sound.Play(); } if (e.IsMultipleOf(30)) { this.Monitor.Log($"Playing {sound.Name} from {this.Source} @ freq: {sound.GetVariable("Frequency")}, vol: {sound.GetVariable("Volume")}, pitch: {sound.GetVariable("Pitch")}, state: {this.GetPlaybackState(sound)}"); } } }
protected override void updateAnimation(GameTime time) { if (!sound.IsPlaying && currentLocation.Equals(Game1.currentLocation)) { sound.SetVariable("Volume", 0f); Utilities.TryPlayCue(sound); } if (Game1.fadeToBlackAlpha > 0.8f && Game1.fadeIn) { Utilities.TryStopCue(sound); } else { sound.SetVariable("Volume", Math.Max(0f, sound.GetVariable("Volume") - 1f)); float max = Math.Max(0f, 400f - Vector2.Distance(Position, Player.Position) / 64f / 16f * 150f); if (max > sound.GetVariable("Volume")) { sound.SetVariable("Volume", max); } } if (wasHitCounter.Value >= 0) { wasHitCounter.Value -= time.ElapsedGameTime.Milliseconds; } Sprite.Animate(time, (FacingDirection == 0) ? 8 : ((FacingDirection != 2) ? (FacingDirection * 4) : 0), 4, 50f); if ((withinPlayerThreshold() || Utility.isOnScreen(position, 256)) && invincibleCountdown <= 0) { faceDirection(0); float xDistance = -(Player.GetBoundingBox().Center.X - GetBoundingBox().Center.X); float yDistance = Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y; float xyDistance = Math.Max(1f, Math.Abs(xDistance) + Math.Abs(yDistance)); if (xyDistance < 64f) { xVelocity = Math.Max(-maxSpeed, Math.Min(maxSpeed, xVelocity * 1.1f)); yVelocity = Math.Max(-maxSpeed, Math.Min(maxSpeed, yVelocity * 1.1f)); } xDistance /= xyDistance; yDistance /= xyDistance; if (wasHitCounter.Value <= 0) { float targetRotation = (float)Math.Atan2(0f - yDistance, xDistance) - (float)Math.PI / 2f; if ((double)(Math.Abs(targetRotation) - Math.Abs(rotation)) > Math.PI * 7.0 / 8.0 && Game1.random.NextDouble() < 0.5) { turningRight.Value = true; } else if ((double)(Math.Abs(targetRotation) - Math.Abs(rotation)) < Math.PI / 8.0) { turningRight.Value = false; } float rotationChange = (float)Math.Sign(targetRotation - rotation) * ((float)Math.PI / 64f); if (turningRight.Value) { rotation -= rotationChange; } else { rotation += rotationChange; } rotation %= (float)Math.PI * 2f; wasHitCounter.Value = 5 + Game1.random.Next(-1, 2); } float factor = Math.Min(maxSpeed, Math.Max(2f, maxSpeed - xyDistance / 64f / 2f)); xDistance = (float)Math.Cos((double)rotation + Math.PI / 2.0); yDistance = 0f - (float)Math.Sin((double)rotation + Math.PI / 2.0); xVelocity += (0f - xDistance) * factor / 6f + (float)Game1.random.Next(-10, 10) / 100f; if (Math.Abs(xVelocity) > Math.Abs((0f - xDistance) * maxSpeed)) { xVelocity -= (0f - xDistance) * factor / 6f; } yVelocity += (0f - yDistance) * factor / 6f + (float)Game1.random.Next(-10, 10) / 100f; if (Math.Abs(yVelocity) > Math.Abs((0f - yDistance) * maxSpeed)) { yVelocity -= (0f - yDistance) * factor / 6f; } } resetAnimationSpeed(); }