partial void ChangeLocationType(Location location, string prevName, LocationTypeChange change) { //focus on the location var mapAnim = new MapAnim() { EndZoom = zoom * 1.5f, EndLocation = location, Duration = CurrentLocation == location ? 1.0f : 2.0f, StartDelay = 1.0f }; if (change.Messages != null && change.Messages.Count > 0) { mapAnim.EndMessage = change.Messages[Rand.Range(0, change.Messages.Count)] .Replace("[previousname]", prevName) .Replace("[name]", location.Name); } mapAnimQueue.Enqueue(mapAnim); mapAnimQueue.Enqueue(new MapAnim() { EndZoom = zoom, StartLocation = location, EndLocation = CurrentLocation, Duration = 1.0f, StartDelay = 0.5f }); }
private void UpdateMapAnim(MapAnim anim, float deltaTime) { //pause animation while there are messageboxes on screen if (GUIMessageBox.MessageBoxes.Count > 0) { return; } if (!string.IsNullOrEmpty(anim.StartMessage)) { new GUIMessageBox("", anim.StartMessage); anim.StartMessage = null; return; } if (anim.StartZoom == null) { anim.StartZoom = zoom; } if (anim.EndZoom == null) { anim.EndZoom = zoom; } anim.StartPos = (anim.StartLocation == null) ? -drawOffset : anim.StartLocation.MapPosition; anim.Timer = Math.Min(anim.Timer + deltaTime, anim.Duration); float t = anim.Duration <= 0.0f ? 1.0f : Math.Max(anim.Timer / anim.Duration, 0.0f); drawOffset = -Vector2.SmoothStep(anim.StartPos.Value, anim.EndLocation.MapPosition, t); drawOffset += new Vector2( (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.3f % 255, Timing.TotalTime * 0.4f % 255, 0) - 0.5f, (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.4f % 255, Timing.TotalTime * 0.3f % 255, 0.5f) - 0.5f) * 50.0f * (float)Math.Sin(t * MathHelper.Pi); zoom = MathHelper.SmoothStep(anim.StartZoom.Value, anim.EndZoom.Value, t); if (anim.Timer >= anim.Duration) { if (!string.IsNullOrEmpty(anim.EndMessage)) { new GUIMessageBox("", anim.EndMessage); anim.EndMessage = null; return; } anim.Finished = true; } }