From 427ab5ed54e083f82a23334813319a919d2d3f2a Mon Sep 17 00:00:00 2001 From: Syntriax Date: Thu, 25 Jan 2024 22:15:52 +0300 Subject: [PATCH] feat: Mouse Movement --- Game/Behaviours/MovementMouseBehaviour.cs | 13 +++++++++++++ Game/EngineConverter.cs | 2 ++ Game/Game1.cs | 5 ++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 Game/Behaviours/MovementMouseBehaviour.cs diff --git a/Game/Behaviours/MovementMouseBehaviour.cs b/Game/Behaviours/MovementMouseBehaviour.cs new file mode 100644 index 0000000..afdb67e --- /dev/null +++ b/Game/Behaviours/MovementMouseBehaviour.cs @@ -0,0 +1,13 @@ +using System; +using Microsoft.Xna.Framework.Input; +using Syntriax.Engine.Core; + +namespace Pong.Behaviours; + +public class MovementMouseBehaviour : BehaviourOverride +{ + protected override void OnUpdate() + { + GameObject.Transform.Position = Mouse.GetState().Position.ToVector2D().ApplyDisplayScale(); + } +} diff --git a/Game/EngineConverter.cs b/Game/EngineConverter.cs index 6458aea..fe904cc 100644 --- a/Game/EngineConverter.cs +++ b/Game/EngineConverter.cs @@ -13,6 +13,8 @@ public static class EngineConverter [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector2D ToVector2D(this Vector2 vector) => new(vector.X, vector.Y); [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector2D ToVector2D(this Point point) => new(point.X, point.Y); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector2 ToVector2(this Vector2D vector) => new(vector.X, vector.Y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector2 ToDisplayVector2(this Vector2D vector) => vector.Scale(screenScale).ToVector2(); diff --git a/Game/Game1.cs b/Game/Game1.cs index 00e7486..05a7b27 100644 --- a/Game/Game1.cs +++ b/Game/Game1.cs @@ -77,10 +77,9 @@ public class Game1 : Game IGameObject gameObjectCircle2 = gameManager.InstantiateGameObject(); gameObjectCircle2.Name = "Circle2"; - gameObjectCircle2.Transform.Position = new Vector2D(0f, 50f); + gameObjectCircle2.Transform.Position = new Vector2D(5f, 50f); gameObjectCircle2.Transform.Scale = new Vector2D(25f, 25f); - gameObjectCircle2.BehaviourController.AddBehaviour(); - gameObjectCircle2.BehaviourController.AddBehaviour(Keys.Up, Keys.Down, 268f, -268f, 400f); + gameObjectCircle2.BehaviourController.AddBehaviour(); gameObjectCircle2.BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)); engine.AddRigidBody(gameObjectCircle2.BehaviourController.AddBehaviour());