Skip to content

Commit

Permalink
use Vector2.Clamp
Browse files Browse the repository at this point in the history
  • Loading branch information
van800 committed Mar 2, 2023
1 parent 4585770 commit ed2a45d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions mono/dodge_the_creeps/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)
{
Expand Down

0 comments on commit ed2a45d

Please sign in to comment.