diff --git a/Game/Behaviours/MovementBallBehaviour.cs b/Game/Behaviours/MovementBallBehaviour.cs new file mode 100644 index 0000000..dd75ac1 --- /dev/null +++ b/Game/Behaviours/MovementBallBehaviour.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using Syntriax.Engine.Core; +using Syntriax.Engine.Input; + +namespace Pong.Behaviours; + +public class MovementBallBehaviour(Vector2 StartDirection, float Speed) : BehaviourOverride +{ + public Vector2 StartDirection { get; } = StartDirection; + public float Speed { get; set; } = Speed; + + protected override void OnInitialize() => StartDirection.Normalize(); + + protected override void OnUpdate(GameTime time) + { + GameObject.Transform.Position += StartDirection * (time.ElapsedGameTime.Nanoseconds * .001f) * Speed; + } +} diff --git a/Game/Behaviours/MovementBehaviour.cs b/Game/Behaviours/MovementBoxBehaviour.cs similarity index 95% rename from Game/Behaviours/MovementBehaviour.cs rename to Game/Behaviours/MovementBoxBehaviour.cs index a04888b..8173914 100644 --- a/Game/Behaviours/MovementBehaviour.cs +++ b/Game/Behaviours/MovementBoxBehaviour.cs @@ -6,7 +6,7 @@ using Syntriax.Engine.Input; namespace Pong.Behaviours; -public class MovementBehaviour(Keys Up, Keys Down, float Speed) : BehaviourOverride +public class MovementBoxBehaviour(Keys Up, Keys Down, float Speed) : BehaviourOverride { private Keys Up { get; } = Up; private Keys Down { get; } = Down; diff --git a/Game/Game1.cs b/Game/Game1.cs index af2b4b5..f0e99ec 100644 --- a/Game/Game1.cs +++ b/Game/Game1.cs @@ -44,6 +44,7 @@ public class Game1 : Game gameObjectBall.Name = "Ball"; gameObjectBall.Transform.Position = new Vector2(Window.ClientBounds.Width * .5f, Window.ClientBounds.Height * .5f); gameObjectBall.Transform.Scale = new Vector2(.025f, .025f); + gameObjectBall.BehaviourController.AddBehaviour(new Vector2(.1f, .1f), 100f); gameObjectBall.BehaviourController.AddBehaviour().Assign(spriteBall); IGameObject gameObjectLeft = gameManager.InstantiateGameObject(); @@ -51,7 +52,7 @@ public class Game1 : Game gameObjectLeft.Transform.Position = new Vector2(Window.ClientBounds.Width * .1f, Window.ClientBounds.Height * .5f); gameObjectLeft.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); gameObjectLeft.BehaviourController.AddBehaviour(); - gameObjectLeft.BehaviourController.AddBehaviour(Keys.S, Keys.W, 200f); + gameObjectLeft.BehaviourController.AddBehaviour(Keys.S, Keys.W, 200f); gameObjectLeft.BehaviourController.AddBehaviour().Assign(spriteBox); IGameObject gameObjectRight = gameManager.InstantiateGameObject(); @@ -59,7 +60,7 @@ public class Game1 : Game gameObjectRight.Transform.Position = new Vector2(Window.ClientBounds.Width * .9f, Window.ClientBounds.Height * .5f); gameObjectRight.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f); gameObjectRight.BehaviourController.AddBehaviour(); - gameObjectRight.BehaviourController.AddBehaviour(Keys.Down, Keys.Up, 200f); + gameObjectRight.BehaviourController.AddBehaviour(Keys.Down, Keys.Up, 200f); gameObjectRight.BehaviourController.AddBehaviour().Assign(spriteBox); // TODO: use this.Content to load your game content here }