feat: Movement Box Boundaries
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user