public static Lerp ( float value1, float value2, float amount ) : float | ||
value1 | float | |
value2 | float | |
amount | float | |
Результат | float |
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="dt"></param> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { var dt = gameTime.ElapsedGameTime.TotalMilliseconds; // Tween to target Y positions Users.ForEach(user => { user.Y = MathHelper.Lerp(user.Y, user.TargetYPosition, (float)Math.Min(dt / 120, 1)); // Tween X Position based on if the scoreboard is hidden if (ConfigManager.ScoreboardVisible.Value) { var target = Team == MultiplayerTeam.Red ? 0 : WindowManager.Width - user.Width; user.X = MathHelper.Lerp(user.X, target, (float)Math.Min(dt / 120, 1)); } else { var target = Team == MultiplayerTeam.Red ? -user.Width - 10 : WindowManager.Width + user.Width + 10; user.X = MathHelper.Lerp(user.X, target, (float)Math.Min(dt / 90, 1)); } user.Visible = user.X >= -user.Width + 10; }); // Lerp team banner in and out if (TeamBanner != null) { var target = Team == MultiplayerTeam.Red ? 0 : WindowManager.Width - TeamBanner.Width; TeamBanner.X = MathHelper.Lerp(TeamBanner.X, target, (float)Math.Min(dt / 120, 1)); } base.Update(gameTime); }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="dt"></param> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { var dt = gameTime.ElapsedGameTime.TotalMilliseconds; // Fade in on map start if (Screen.Timing.Time < -500) { var alpha = MathHelper.Lerp(Title.Alpha, 1, (float)Math.Min(dt / AnimationScale, 1)); Title.Alpha = alpha; Difficulty.Alpha = alpha; Creator.Alpha = alpha; Rating.Alpha = alpha; Mods.Alpha = alpha; if (Screen.InReplayMode) { Watching.Alpha = alpha; } } else { var alpha = MathHelper.Lerp(Title.Alpha, 0, (float)Math.Min(dt / AnimationScale, 1)); Title.Alpha = alpha; Difficulty.Alpha = alpha; Creator.Alpha = alpha; Rating.Alpha = alpha; Mods.Alpha = alpha; } base.Update(gameTime); }
public override void Update(GameTime gameTime) { PerformLoadingWheelRotation(); Button.Alpha = MathHelper.Lerp(Button.Alpha, Button.IsHovered ? 0.4f : 0f, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / 60, 1)); base.Update(gameTime); }
/// <summary> /// Handles the input for all pause input. /// </summary> /// <param name="gameTime"></param> private void HandlePauseInput(GameTime gameTime) { // Go back to editor if we're currently play testing. if (IsPlayTesting && (KeyboardManager.IsUniqueKeyPress(Keys.Escape) || KeyboardManager.CurrentState.IsKeyDown(ConfigManager.KeyPause.Value))) { if (AudioEngine.Track.IsPlaying) { AudioEngine.Track.Pause(); AudioEngine.Track.Seek(PlayTestAudioTime); } Exit(() => new EditorScreen(OriginalEditorMap)); } if (IsCalibratingOffset && (KeyboardManager.IsUniqueKeyPress(Keys.Escape) || KeyboardManager.CurrentState.IsKeyDown(ConfigManager.KeyPause.Value))) { OffsetConfirmDialog.Exit(this); } if (!IsPaused && (KeyboardManager.CurrentState.IsKeyDown(ConfigManager.KeyPause.Value) || KeyboardManager.CurrentState.IsKeyDown(Keys.Escape))) { Pause(gameTime); } // The user wants to resume their play. else if (IsPaused && (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeyPause.Value) || KeyboardManager.IsUniqueKeyPress(Keys.Escape))) { if (ChatManager.IsActive) { ChatManager.ToggleChatOverlay(); return; } Pause(); TimePauseKeyHeld = 0; GameBase.Game.GlobalUserInterface.Cursor.Alpha = 0; } else { TimePauseKeyHeld = 0; var screenView = (GameplayScreenView)View; if (Failed || IsPlayComplete || IsPaused) { return; } // Properly fade in now. if (!screenView.FadingOnRestartKeyPress) { screenView.Transitioner.Alpha = MathHelper.Lerp(screenView.Transitioner.Alpha, 0, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / 120, 1)); } } }
/// <summary> /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { if (!HasMap || OnlineManager.CurrentGame?.HostId == OnlineManager.Self.OnlineUser.Id) { DownloadButton.Alpha = MathHelper.Lerp(DownloadButton.Alpha, DownloadButton.IsHovered ? 0.3f : 0f, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / 60, 1)); } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { G.update_input(); switch (state) { case OnlineState.AskingRole: if (G.ks.IsKeyDown(Keys.H)) { onlineGame = new HostOnlineGame(6666); state = OnlineState.Connecting; onlineGame.OnConnection += OnlineGame_OnConnection; imMisterH = true; } else if (G.ks.IsKeyDown(Keys.J)) { onlineGame = new JoinOnlineGame("127.0.0.1", 6666); state = OnlineState.Connecting; onlineGame.OnConnection += OnlineGame_OnConnection; imMisterH = false; } break; case OnlineState.Connecting: Window.Title = "connecting"; //on connection invoke for the characters //start the background thread for the two player // change state for playing break; case OnlineState.Playing: onlineGame.hostChar.update(); onlineGame.joinChar.update(); if (G.ks.IsKeyDown(Keys.A)) { G.zoom = MH.Lerp(G.zoom, 0.1f, 0.01f); } if (G.ks.IsKeyDown(Keys.D)) { G.zoom = MH.Lerp(G.zoom, 5f, 0.001f); } break; } base.Update(gameTime); }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { var dt = gameTime.ElapsedGameTime.TotalMilliseconds; // Gradually fade out the line. foreach (var line in LineObjectPool) { line.Alpha = MathHelper.Lerp(line.Alpha, 0, (float)Math.Min(dt / 960, 1)); } // Tween the chevron to the last hit if (CurrentLinePoolIndex != -1) { LastHitCheveron.X = MathHelper.Lerp(LastHitCheveron.X, LineObjectPool[CurrentLinePoolIndex].X, (float)Math.Min(dt / 360, 1)); } base.Update(gameTime); }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { HandleWaitingForPlayersDialog(); CheckIfNewScoreboardUsers(); HandlePlayCompletion(gameTime); BattleRoyaleBackgroundAlerter?.Update(gameTime); Screen.Ruleset?.Update(gameTime); Container?.Update(gameTime); // Update the position and size of the grade display. GradeDisplay.X = AccuracyDisplay.X - AccuracyDisplay.Width - 8; GradeDisplay.Height = AccuracyDisplay.Height; GradeDisplay.UpdateWidth(); if (SpectatorDialog != null) { SpectatorDialog.Alpha = MathHelper.Lerp(SpectatorDialog.Alpha, Screen.IsPaused ? 1 : 0, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / 100, 1)); } }
/// <summary> /// Handles the input for all pause input. /// </summary> /// <param name="gameTime"></param> private void HandlePauseInput(GameTime gameTime) { if (!IsPaused && (KeyboardManager.CurrentState.IsKeyDown(ConfigManager.KeyPause.Value) || KeyboardManager.CurrentState.IsKeyDown(Keys.Escape))) { Pause(gameTime); } // The user wants to resume their play. else if (IsPaused && (KeyboardManager.IsUniqueKeyPress(ConfigManager.KeyPause.Value) || KeyboardManager.IsUniqueKeyPress(Keys.Escape))) { if (ChatManager.IsActive) { ChatManager.ToggleChatOverlay(); return; } Pause(); TimePauseKeyHeld = 0; GameBase.Game.GlobalUserInterface.Cursor.Alpha = 0; } else { TimePauseKeyHeld = 0; var screenView = (GameplayScreenView)View; if (Failed || IsPlayComplete || IsPaused) { return; } // Properly fade in now. if (!screenView.FadingOnRestartKeyPress) { screenView.Transitioner.Alpha = MathHelper.Lerp(screenView.Transitioner.Alpha, 0, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / 120, 1)); } } }
/// <summary> /// Pauses the game. /// </summary> internal void Pause(GameTime gameTime = null) { // Don't allow pausing if the play is already finished. if (IsPlayComplete) { return; } // Grab the casted version of the screenview. var screenView = (GameplayScreenView)View; // Handle pause. // Spectating is an exception here because we're not technically "paused" if (!IsPaused || SpectatorClient != null) { // Handle cases where someone (a developer) calls pause but there is not GameTime. // shouldn't ever happen though. if (gameTime == null) { const string log = "Cannot pause if GameTime is null"; Logger.Error(log, LogType.Runtime); throw new InvalidOperationException(log); } // Increase the time the pause key has been held. TimePauseKeyHeld += gameTime.ElapsedGameTime.TotalMilliseconds; screenView.Transitioner.Alpha = MathHelper.Lerp(screenView.Transitioner.Alpha, 1, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / TimeToHoldPause, 1)); // Make the user hold the pause key down before pausing if tap to pause is disabled. if (!ConfigManager.TapToPause.Value && TimePauseKeyHeld < TimeToHoldPause) { return; } IsPaused = true; IsResumeInProgress = false; PauseCount++; GameBase.Game.GlobalUserInterface.Cursor.Alpha = 1; // Exit right away if playing a replay. if (InReplayMode) { CustomAudioSampleCache.StopAll(); ModManager.RemoveAllMods(); if (SpectatorClient != null) { OnlineManager.Client?.StopSpectating(); } Exit(() => new SelectScreen()); return; } // Show notification to the user that their score is invalid. NotificationManager.Show(NotificationLevel.Warning, "WARNING! Your score will not be submitted due to pausing during gameplay!"); // Add the pause mod to their score. if (!ModManager.IsActivated(ModIdentifier.Paused)) { ModManager.AddMod(ModIdentifier.Paused); ReplayCapturer.Replay.Mods |= ModIdentifier.Paused; Ruleset.ScoreProcessor.Mods |= ModIdentifier.Paused; } try { AudioEngine.Track.Pause(); } catch (Exception) { // ignored } CustomAudioSampleCache.PauseAll(); DiscordHelper.Presence.State = $"Paused for the {StringHelper.AddOrdinal(PauseCount)} time"; DiscordHelper.Presence.EndTimestamp = 0; DiscordRpc.UpdatePresence(ref DiscordHelper.Presence); OnlineManager.Client?.UpdateClientStatus(GetClientStatus()); // Fade in the transitioner. screenView.Transitioner.Animations.Clear(); screenView.Transitioner.Animations.Add(new Animation(AnimationProperty.Alpha, Easing.Linear, screenView.Transitioner.Alpha, 0.75f, 400)); // Activate pause menu screenView.PauseScreen?.Activate(); return; } if (IsResumeInProgress) { return; } // Setting the resume time in this case allows us to give the user time to react // with a delay before starting the audio track again. // When that resume time is past the specific set offset, it'll unpause the game. IsResumeInProgress = true; ResumeTime = GameBase.Game.TimeRunning; // Fade screen transitioner screenView.Transitioner.Animations.Clear(); var alphaTransformation = new Animation(AnimationProperty.Alpha, Easing.Linear, 0.75f, 0, 400); screenView.Transitioner.Animations.Add(alphaTransformation); // Deactivate pause screen. screenView.PauseScreen?.Deactivate(); SetRichPresence(); OnlineManager.Client?.UpdateClientStatus(GetClientStatus()); GameBase.Game.GlobalUserInterface.Cursor.Alpha = 0; }
/// <summary> /// Handles the input for all pause input. /// </summary> /// <param name="gameTime"></param> private void HandlePauseInput(GameTime gameTime) { if (OnlineManager.CurrentGame != null) { return; } // If the pause key is not pressed... if (KeyboardManager.CurrentState.IsKeyUp(Keys.Escape) && KeyboardManager.CurrentState.IsKeyUp(ConfigManager.KeyPause.Value)) { if (Failed || IsPlayComplete || IsPaused) { return; } // Remove the pause fade. var screenView = (GameplayScreenView)View; if (!screenView.FadingOnRestartKeyPress) { screenView.Transitioner.Alpha = MathHelper.Lerp(screenView.Transitioner.Alpha, 0, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / 120, 1)); } return; } // If the pause key was just pressed... if (KeyboardManager.IsUniqueKeyPress(Keys.Escape) || KeyboardManager.IsUniqueKeyPress(ConfigManager.KeyPause.Value)) { // Go back to editor if we're currently play testing. if (IsPlayTesting) { if (AudioEngine.Track.IsPlaying) { AudioEngine.Track.Pause(); AudioEngine.Track.Seek(PlayTestAudioTime); } CustomAudioSampleCache.StopAll(); Exit(() => new EditorScreen(OriginalEditorMap)); } // Exit the offset calibration. else if (IsCalibratingOffset) { OffsetConfirmDialog.Exit(this); } // Resume the play if paused, or pause. else { TimePauseKeyHeld = 0; Pause(gameTime); } return; } // Otherwise (the pause key is held but wasn't just pressed), call Pause() to advance the hold to pause timer. if (!IsPaused || SpectatorClient != null) { Pause(gameTime); } }
/// <inheritdoc /> /// <summary> /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { Alpha = MathHelper.Lerp(Alpha, IsHovered ? 0.40f : 1.0f, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / 60, 1)); base.Update(gameTime); }