Engine DeMonoGame #2
This commit is contained in:
@@ -6,12 +6,12 @@ using Syntriax.Engine.Input;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
public class MovementBallBehaviour(Vector2 StartDirection, float Speed) : BehaviourOverride
|
||||
public class MovementBallBehaviour(Vector2D StartDirection, float Speed) : BehaviourOverride
|
||||
{
|
||||
public Vector2 StartDirection { get; private set; } = Vector2.Normalize(StartDirection);
|
||||
public Vector2D StartDirection { get; private set; } = Vector2D.Normalize(StartDirection);
|
||||
public float Speed { get; set; } = Speed;
|
||||
|
||||
protected override void OnFirstActiveFrame(GameTime time)
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? rigidBody))
|
||||
throw new Exception($"Where's my {nameof(IRigidBody2D)}????");
|
||||
|
@@ -17,25 +17,25 @@ public class MovementBoxBehaviour(Keys Up, Keys Down, float High, float Low, flo
|
||||
private bool isUpPressed = false;
|
||||
private bool isDownPressed = false;
|
||||
|
||||
private IKeyboardInputs inputs = null!;
|
||||
private IButtonInputs<Keys> inputs = null!;
|
||||
|
||||
protected override void OnUpdate(GameTime time)
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (isUpPressed && isDownPressed)
|
||||
return;
|
||||
|
||||
if (isUpPressed)
|
||||
GameObject.Transform.Position = GameObject.Transform.Position + Vector2.UnitY * (float)time.ElapsedGameTime.TotalSeconds * Speed;
|
||||
GameObject.Transform.Position = GameObject.Transform.Position + Vector2D.Up * (float)Time.Elapsed.TotalSeconds * Speed;
|
||||
else if (isDownPressed)
|
||||
GameObject.Transform.Position = GameObject.Transform.Position + -Vector2.UnitY * (float)time.ElapsedGameTime.TotalSeconds * Speed;
|
||||
GameObject.Transform.Position = GameObject.Transform.Position + -Vector2D.Up * (float)Time.Elapsed.TotalSeconds * Speed;
|
||||
|
||||
GameObject.Transform.Position = new Vector2(GameObject.Transform.Position.X, MathF.Max(MathF.Min(GameObject.Transform.Position.Y, High), Low));
|
||||
GameObject.Transform.Position = new Vector2D(GameObject.Transform.Position.X, MathF.Max(MathF.Min(GameObject.Transform.Position.Y, High), Low));
|
||||
}
|
||||
|
||||
protected override void OnFirstActiveFrame(GameTime time)
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (!BehaviourController.TryGetBehaviour<IKeyboardInputs>(out var behaviourResult))
|
||||
throw new Exception($"{nameof(IKeyboardInputs)} is missing on ${GameObject.Name}.");
|
||||
if (!BehaviourController.TryGetBehaviour<IButtonInputs<Keys>>(out var behaviourResult))
|
||||
throw new Exception($"{nameof(IButtonInputs<Keys>)} is missing on ${GameObject.Name}.");
|
||||
|
||||
inputs = behaviourResult;
|
||||
|
||||
@@ -55,8 +55,8 @@ public class MovementBoxBehaviour(Keys Up, Keys Down, float High, float Low, flo
|
||||
inputs.UnregisterOnRelease(Down, OnDownReleased);
|
||||
}
|
||||
|
||||
private void OnUpPressed(IKeyboardInputs inputs, Keys keys) => isUpPressed = true;
|
||||
private void OnUpReleased(IKeyboardInputs inputs, Keys keys) => isUpPressed = false;
|
||||
private void OnDownPressed(IKeyboardInputs inputs, Keys keys) => isDownPressed = true;
|
||||
private void OnDownReleased(IKeyboardInputs inputs, Keys keys) => isDownPressed = false;
|
||||
private void OnUpPressed(IButtonInputs<Keys> inputs, Keys keys) => isUpPressed = true;
|
||||
private void OnUpReleased(IButtonInputs<Keys> inputs, Keys keys) => isUpPressed = false;
|
||||
private void OnDownPressed(IButtonInputs<Keys> inputs, Keys keys) => isDownPressed = true;
|
||||
private void OnDownReleased(IButtonInputs<Keys> inputs, Keys keys) => isDownPressed = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user