diff --git a/Game/Behaviours/MovementBoxBehaviour.cs b/Game/Behaviours/MovementBoxBehaviour.cs index 8173914..b31360e 100644 --- a/Game/Behaviours/MovementBoxBehaviour.cs +++ b/Game/Behaviours/MovementBoxBehaviour.cs @@ -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() diff --git a/Game/Game1.cs b/Game/Game1.cs index fea46b9..fdaf183 100644 --- a/Game/Game1.cs +++ b/Game/Game1.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -59,7 +59,7 @@ public class Game1 : Game gameObjectLeft.Transform.Position = new Vector2(-350f, 0f); gameObjectLeft.Transform.Scale = new Vector2(10f, 40f); gameObjectLeft.BehaviourController.AddBehaviour(); - gameObjectLeft.BehaviourController.AddBehaviour(Keys.W, Keys.S, 400f); + gameObjectLeft.BehaviourController.AddBehaviour(Keys.W, Keys.S, 268f, -268f, 400f); gameObjectLeft.BehaviourController.AddBehaviour().Assign(spriteBox); IGameObject gameObjectRight = gameManager.InstantiateGameObject(); @@ -67,7 +67,7 @@ public class Game1 : Game gameObjectRight.Transform.Position = new Vector2(350f, 0f); gameObjectRight.Transform.Scale = new Vector2(10f, 40f); gameObjectRight.BehaviourController.AddBehaviour(); - gameObjectRight.BehaviourController.AddBehaviour(Keys.Up, Keys.Down, 400f); + gameObjectRight.BehaviourController.AddBehaviour(Keys.Up, Keys.Down, 268f, -268f, 400f); gameObjectRight.BehaviourController.AddBehaviour().Assign(spriteBox); // TODO: use this.Content to load your game content here }