feat: Movement Box Boundaries

This commit is contained in:
2023-11-27 17:06:18 +03:00
parent 1c248c0e97
commit 74077cd051
2 changed files with 8 additions and 4 deletions

View File

@@ -6,10 +6,12 @@ using Syntriax.Engine.Input;
namespace Pong.Behaviours;
public class MovementBoxBehaviour(Keys Up, Keys Down, float Speed) : BehaviourOverride
public class MovementBoxBehaviour(Keys Up, Keys Down, float High, float Low, float Speed) : BehaviourOverride
{
private Keys Up { get; } = Up;
private Keys Down { get; } = Down;
public float High { get; } = High;
public float Low { get; } = Low;
public float Speed { get; set; } = Speed;
private bool isUpPressed = false;
@@ -26,6 +28,8 @@ public class MovementBoxBehaviour(Keys Up, Keys Down, float Speed) : BehaviourOv
GameObject.Transform.Position = GameObject.Transform.Position + Vector2.UnitY * (float)time.ElapsedGameTime.TotalSeconds * Speed;
else if (isDownPressed)
GameObject.Transform.Position = GameObject.Transform.Position + -Vector2.UnitY * (float)time.ElapsedGameTime.TotalSeconds * Speed;
GameObject.Transform.Position = new Vector2(GameObject.Transform.Position.X, MathF.Max(MathF.Min(GameObject.Transform.Position.Y, High), Low));
}
protected override void OnInitialize()