From ed2a45d9d95548a3bea02914595c606e6809f9c9 Mon Sep 17 00:00:00 2001 From: Ivan Shakhov Date: Thu, 2 Mar 2023 15:30:36 +0100 Subject: [PATCH] use Vector2.Clamp --- mono/dodge_the_creeps/Player.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mono/dodge_the_creeps/Player.cs b/mono/dodge_the_creeps/Player.cs index 2b4cdacb0b..7d6ef25f95 100644 --- a/mono/dodge_the_creeps/Player.cs +++ b/mono/dodge_the_creeps/Player.cs @@ -5,8 +5,7 @@ public partial class Player : Area2D [Signal] public delegate void HitEventHandler(); - [Export] - public int Speed { get; set; } = 400; // How fast the player will move (pixels/sec). + [Export] public int Speed { get; set; } = 400; // How fast the player will move (pixels/sec). public Vector2 ScreenSize; // Size of the game window. @@ -33,10 +32,7 @@ public override void _Process(double delta) } Position += velocity * (float)delta; - Position = new Vector2( - x: Mathf.Clamp(Position.X, 0, ScreenSize.X), - y: Mathf.Clamp(Position.Y, 0, ScreenSize.Y) - ); + Position = Position.Clamp(Position, ScreenSize); if (velocity.X != 0) {