diff --git a/Engine b/Engine index bc1c76d..c8bb991 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit bc1c76d746d01281ecaa3c6937e1990fd1dcdcfc +Subproject commit c8bb991865c8efc99786a9a10767f08ce7b8709c diff --git a/Platforms/Desktop/Program.cs b/Platforms/Desktop/Program.cs index ee1056e..b47e210 100644 --- a/Platforms/Desktop/Program.cs +++ b/Platforms/Desktop/Program.cs @@ -43,7 +43,7 @@ Pong.PongUniverse.ApplyPongClient(universe, clientConfiguration.ServerAddress, c Pong.PongUniverse.ApplyPongUniverse(universe); universe.InstantiateUniverseObject().SetUniverseObject("Desktop HO") - .BehaviourController.AddBehaviour(); + .BehaviourController.AddBehaviour(); using MonoGameWindow monoGameWindow = new(universe); diff --git a/Shared/Behaviours/BallBehaviour.cs b/Shared/Behaviours/Ball.cs similarity index 90% rename from Shared/Behaviours/BallBehaviour.cs rename to Shared/Behaviours/Ball.cs index 623f80c..82b53bd 100644 --- a/Shared/Behaviours/BallBehaviour.cs +++ b/Shared/Behaviours/Ball.cs @@ -5,9 +5,9 @@ using Syntriax.Engine.Systems.Tween; namespace Pong.Behaviours; -public class BallBehaviour : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INetworkEntity, - IPacketListenerClient, - IPacketListenerClient +public class Ball : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INetworkEntity, + IPacketListenerClient, + IPacketListenerClient { public float Speed { get; set; } = 500f; public float SpeedUpMultiplier { get; set; } = .025f; @@ -62,8 +62,8 @@ public class BallBehaviour : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INe networkServer?.SendToAll(new BallUpdatePacket(this)); } - public BallBehaviour() { } - public BallBehaviour(float speed) => Speed = speed; + public Ball() { } + public Ball(float speed) => Speed = speed; void IPacketListenerClient.OnClientPacketArrived(IConnection sender, BallResetPacket packet) => ResetBall(); void IPacketListenerClient.OnClientPacketArrived(IConnection sender, BallUpdatePacket packet) @@ -85,7 +85,7 @@ public class BallBehaviour : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INe public Vector2D Velocity { get; set; } = Vector2D.Zero; public BallUpdatePacket() { } - public BallUpdatePacket(BallBehaviour ballBehaviour) + public BallUpdatePacket(Ball ballBehaviour) { Position = ballBehaviour.Transform.Position; Velocity = ballBehaviour.RigidBody.Velocity; diff --git a/Shared/Behaviours/CameraController.cs b/Shared/Behaviours/CameraController.cs index f19e985..60744ba 100644 --- a/Shared/Behaviours/CameraController.cs +++ b/Shared/Behaviours/CameraController.cs @@ -8,14 +8,14 @@ namespace Pong.Behaviours; public class CameraController : Behaviour, IFirstFrameUpdate, IUpdate { - private MonoGameCamera2DBehaviour cameraBehaviour = null!; + private MonoGameCamera2D cameraBehaviour = null!; private IButtonInputs buttonInputs = null!; private float defaultZoomLevel = 1f; public void FirstActiveFrame() { - cameraBehaviour = BehaviourController.GetRequiredBehaviour(); + cameraBehaviour = BehaviourController.GetRequiredBehaviour(); buttonInputs = Universe.FindRequiredBehaviour>(); buttonInputs.RegisterOnPress(Keys.F, SwitchToFullScreen); diff --git a/Shared/Behaviours/CircleBehaviour.cs b/Shared/Behaviours/DrawableColliderCircle.cs similarity index 77% rename from Shared/Behaviours/CircleBehaviour.cs rename to Shared/Behaviours/DrawableColliderCircle.cs index bc82865..6e945ee 100644 --- a/Shared/Behaviours/CircleBehaviour.cs +++ b/Shared/Behaviours/DrawableColliderCircle.cs @@ -3,7 +3,7 @@ using Syntriax.Engine.Integration.MonoGame; namespace Pong.Behaviours; -public class CircleBehaviour : Syntriax.Engine.Physics2D.Collider2DCircleBehaviour, IDrawableTriangle +public class DrawableColliderCircle : Syntriax.Engine.Physics2D.Collider2DCircle, IDrawableTriangle { private const float CIRCLE_SEGMENT_COUNT = 32f; @@ -24,6 +24,6 @@ public class CircleBehaviour : Syntriax.Engine.Physics2D.Collider2DCircleBehavio } } - public CircleBehaviour(Circle circle) : base(circle) { } - public CircleBehaviour(Circle circle, ColorRGBA color) : base(circle) { Color = color; } + public DrawableColliderCircle(Circle circle) : base(circle) { } + public DrawableColliderCircle(Circle circle, ColorRGBA color) : base(circle) { Color = color; } } diff --git a/Shared/Behaviours/ShapeBehaviour.cs b/Shared/Behaviours/DrawableColliderShape.cs similarity index 65% rename from Shared/Behaviours/ShapeBehaviour.cs rename to Shared/Behaviours/DrawableColliderShape.cs index a338ca9..abe3a22 100644 --- a/Shared/Behaviours/ShapeBehaviour.cs +++ b/Shared/Behaviours/DrawableColliderShape.cs @@ -5,7 +5,7 @@ using Syntriax.Engine.Integration.MonoGame; namespace Pong.Behaviours; -public class ShapeBehaviour : Syntriax.Engine.Physics2D.Collider2DShapeBehaviour, IDrawableTriangle +public class DrawableColliderShape : Syntriax.Engine.Physics2D.Collider2DShape, IDrawableTriangle { private readonly IList triangles = []; @@ -21,6 +21,6 @@ public class ShapeBehaviour : Syntriax.Engine.Physics2D.Collider2DShapeBehaviour triangleBatch.Draw(triangle, Color); } - public ShapeBehaviour(Shape2D shape) : base(shape) { } - public ShapeBehaviour(Shape2D shape, ColorRGBA color) : base(shape) { Color = color; } + public DrawableColliderShape(Shape2D shape) : base(shape) { } + public DrawableColliderShape(Shape2D shape, ColorRGBA color) : base(shape) { Color = color; } } diff --git a/Shared/Behaviours/TextBehaviour.cs b/Shared/Behaviours/Label.cs similarity index 80% rename from Shared/Behaviours/TextBehaviour.cs rename to Shared/Behaviours/Label.cs index 25010b5..ba41582 100644 --- a/Shared/Behaviours/TextBehaviour.cs +++ b/Shared/Behaviours/Label.cs @@ -6,7 +6,7 @@ using Syntriax.Engine.Integration.MonoGame; namespace Pong.Behaviours; -public class TextBehaviour : Behaviour2D, IDrawableSprite +public class Label : Behaviour2D, IDrawableSprite { public SpriteFont? Font { get; set; } = null; public int Size { get; set; } = 16; @@ -20,6 +20,6 @@ public class TextBehaviour : Behaviour2D, IDrawableSprite spriteBatch.DrawString(Font, Text, Transform.Position, Color.White, Transform.Rotation, Vector2D.One * .5f, Transform.Scale.Magnitude, SpriteEffects.None, 0f); } - public TextBehaviour() { } - public TextBehaviour(SpriteFont font) => Font = font; + public Label() { } + public Label(SpriteFont font) => Font = font; } diff --git a/Shared/Behaviours/MovementBallBehaviour.cs b/Shared/Behaviours/MovementBallBehaviour.cs deleted file mode 100644 index 8c3daba..0000000 --- a/Shared/Behaviours/MovementBallBehaviour.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Syntriax.Engine.Core; -using Syntriax.Engine.Physics2D; - -namespace Pong.Behaviours; - -public class MovementBallBehaviour : Behaviour2D, IFirstFrameUpdate, IUpdate -{ - public Vector2D StartDirection { get; private set; } = Vector2D.Zero; - public float Speed { get; set; } = 500f; - public float SpeedUpMultiplier { get; set; } = .0125f; - - private IRigidBody2D rigidBody = null!; - - public void FirstActiveFrame() - { - rigidBody = BehaviourController.GetRequiredBehaviour(); - - rigidBody.Velocity = StartDirection * Speed; - BehaviourController.GetRequiredBehaviour().OnCollisionDetected.AddListener(OnCollisionDetected); - } - - public void Update() - { - if (rigidBody.Velocity.MagnitudeSquared <= 0.01f) - return; - - Vector2D speedUp = rigidBody.Velocity.Normalized * Universe.Time.DeltaTime; - rigidBody.Velocity += speedUp * SpeedUpMultiplier; - } - - private void OnCollisionDetected(ICollider2D collider2D, CollisionDetectionInformation information) - { - if (Syntriax.Engine.Core.Math.Abs(information.Normal.Dot(Vector2D.Right)) > .25) - rigidBody.Velocity = information.Detector.Transform.Position.FromTo(information.Detected.Transform.Position).Normalized * rigidBody.Velocity.Magnitude; - else - rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal); - } - - public MovementBallBehaviour() { } - public MovementBallBehaviour(Vector2D startDirection, float speed) - { - StartDirection = Vector2D.Normalize(startDirection); - Speed = speed; - } -} diff --git a/Shared/Behaviours/PaddleBehaviour.cs b/Shared/Behaviours/Paddle.cs similarity index 92% rename from Shared/Behaviours/PaddleBehaviour.cs rename to Shared/Behaviours/Paddle.cs index e815d6f..d36f3d8 100644 --- a/Shared/Behaviours/PaddleBehaviour.cs +++ b/Shared/Behaviours/Paddle.cs @@ -10,9 +10,9 @@ using Syntriax.Engine.Systems.Tween; namespace Pong.Behaviours; -public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Speed) : Behaviour2D, +public class Paddle(Keys Up, Keys Down, float High, float Low, float Speed) : Behaviour2D, IFirstFrameUpdate, IPhysicsIteration, IPostPhysicsUpdate, - IPacketListenerServer, IPacketListenerClient + IPacketListenerServer, IPacketListenerClient { private Keys Up { get; } = Up; private Keys Down { get; } = Down; @@ -105,7 +105,7 @@ public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Sp public bool IsUpPressed { get; set; } = default!; public bool IsDownPressed { get; set; } = default!; - public PaddleKeyStatePacket Set(PaddleBehaviour paddleBehaviour) + public PaddleKeyStatePacket Set(Paddle paddleBehaviour) { EntityId = paddleBehaviour.Id; Position = paddleBehaviour.Transform.Position; @@ -116,6 +116,6 @@ public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Sp } public PaddleKeyStatePacket() { } - public PaddleKeyStatePacket(PaddleBehaviour paddleBehaviour) => Set(paddleBehaviour); + public PaddleKeyStatePacket(Paddle paddleBehaviour) => Set(paddleBehaviour); } } diff --git a/Shared/Behaviours/PongManagerBehaviour.cs b/Shared/Behaviours/PongManager.cs similarity index 82% rename from Shared/Behaviours/PongManagerBehaviour.cs rename to Shared/Behaviours/PongManager.cs index 3ce65ac..d1646de 100644 --- a/Shared/Behaviours/PongManagerBehaviour.cs +++ b/Shared/Behaviours/PongManager.cs @@ -9,16 +9,16 @@ using Syntriax.Engine.Systems.Input; namespace Pong.Behaviours; -public class PongManagerBehaviour : Behaviour, INetworkEntity, IFirstFrameUpdate, - IPacketListenerServer, - IPacketListenerClient +public class PongManager : Behaviour, INetworkEntity, IFirstFrameUpdate, + IPacketListenerServer, + IPacketListenerClient { - public Action? OnReset { get; set; } = null; - public Action? OnFinished { get; set; } = null; - public Action? OnScoreUpdated { get; set; } = null; + public Action? OnReset { get; set; } = null; + public Action? OnFinished { get; set; } = null; + public Action? OnScoreUpdated { get; set; } = null; private Random random = new(); - private BallBehaviour ball = null!; + private Ball ball = null!; private INetworkCommunicatorClient? networkClient = null!; private INetworkCommunicatorServer? networkServer = null; @@ -30,15 +30,15 @@ public class PongManagerBehaviour : Behaviour, INetworkEntity, IFirstFrameUpdate public int WinScore { get; } = 5; - public PongManagerBehaviour() => WinScore = 5; - public PongManagerBehaviour(int winScore) => WinScore = winScore; + public PongManager() => WinScore = 5; + public PongManager(int winScore) => WinScore = winScore; public void FirstActiveFrame() { IButtonInputs? buttonInputs = Universe.FindBehaviour>(); buttonInputs?.RegisterOnRelease(Keys.Space, (_, _1) => networkClient?.SendToServer(new RequestStartPacket())); - ball = Universe.FindRequiredBehaviour(); + ball = Universe.FindRequiredBehaviour(); networkClient = Universe.FindBehaviour(); networkServer = Universe.FindBehaviour(); logger = Universe.FindBehaviour(); @@ -125,7 +125,7 @@ public class PongManagerBehaviour : Behaviour, INetworkEntity, IFirstFrameUpdate public int Right { get; set; } public ScorePacket() { } - public ScorePacket(PongManagerBehaviour pongManagerBehaviour) + public ScorePacket(PongManager pongManagerBehaviour) { Left = pongManagerBehaviour.ScoreLeft; Right = pongManagerBehaviour.ScoreRight; diff --git a/Shared/Behaviours/TextScoreBehaviour.cs b/Shared/Behaviours/ScoreLabel.cs similarity index 78% rename from Shared/Behaviours/TextScoreBehaviour.cs rename to Shared/Behaviours/ScoreLabel.cs index 8cbe152..397163b 100644 --- a/Shared/Behaviours/TextScoreBehaviour.cs +++ b/Shared/Behaviours/ScoreLabel.cs @@ -5,18 +5,18 @@ using Syntriax.Engine.Integration.MonoGame; namespace Pong.Behaviours; -public class TextScoreBehaviour(bool IsLeft) : TextBehaviour, IFirstFrameUpdate +public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate { public readonly bool IsLeft = IsLeft; - private PongManagerBehaviour pongManager = null!; + private PongManager pongManager = null!; public void FirstActiveFrame() { MonoGameWindow monoGameWindow = Universe.FindRequiredBehaviour().Window; Font = monoGameWindow.Content.Load("UbuntuMono"); - pongManager = Universe.FindRequiredBehaviour(); + pongManager = Universe.FindRequiredBehaviour(); pongManager.OnScoreUpdated += UpdateScores; pongManager.OnReset += UpdateScores; @@ -24,7 +24,7 @@ public class TextScoreBehaviour(bool IsLeft) : TextBehaviour, IFirstFrameUpdate UpdateScores(pongManager); } - private void UpdateScores(PongManagerBehaviour pongManager) + private void UpdateScores(PongManager pongManager) { if (IsLeft) Text = pongManager.ScoreLeft.ToString(); diff --git a/Shared/Behaviours/WallScoreBehaviour.cs b/Shared/Behaviours/ScoreWall.cs similarity index 82% rename from Shared/Behaviours/WallScoreBehaviour.cs rename to Shared/Behaviours/ScoreWall.cs index ed0bd94..7d2ce93 100644 --- a/Shared/Behaviours/WallScoreBehaviour.cs +++ b/Shared/Behaviours/ScoreWall.cs @@ -5,7 +5,7 @@ using Syntriax.Engine.Physics2D; namespace Pong.Behaviours; -public class WallScoreBehaviour(Action OnCollision) : Behaviour2D, IFirstFrameUpdate +public class ScoreWall(Action OnCollision) : Behaviour2D, IFirstFrameUpdate { private Action OnCollision { get; } = OnCollision; diff --git a/Shared/PongUniverse.cs b/Shared/PongUniverse.cs index 2488158..f29c8a7 100644 --- a/Shared/PongUniverse.cs +++ b/Shared/PongUniverse.cs @@ -30,17 +30,17 @@ public static class PongUniverse universe.InstantiateUniverseObject().SetUniverseObject("Camera") .BehaviourController.AddBehaviour() .BehaviourController.AddBehaviour() - .BehaviourController.AddBehaviour(); + .BehaviourController.AddBehaviour(); //////////////////////////////////////////////////////////////////////////////////// universe.InstantiateUniverseObject().SetUniverseObject("Score Left") .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-250f, 250f), scale: Vector2D.One * .25f) - .BehaviourController.AddBehaviour(true); + .BehaviourController.AddBehaviour(true); universe.InstantiateUniverseObject().SetUniverseObject("Score Right") .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(250f, 250f), scale: Vector2D.One * .25f) - .BehaviourController.AddBehaviour(false); + .BehaviourController.AddBehaviour(false); return universe; } @@ -63,33 +63,33 @@ public static class PongUniverse //////////////////////////////////////////////////////////////////////////////////// - PongManagerBehaviour pongManager = universe.InstantiateUniverseObject().SetUniverseObject("Pong Game Manager") - .BehaviourController.AddBehaviour(5); + PongManager pongManager = universe.InstantiateUniverseObject().SetUniverseObject("Pong Game Manager") + .BehaviourController.AddBehaviour(5); //////////////////////////////////////////////////////////////////////////////////// universe.InstantiateUniverseObject().SetUniverseObject("Ball") .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(0, 0f), scale: new Vector2D(10f, 10f)) - .BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)) - .BehaviourController.AddBehaviour() + .BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)) + .BehaviourController.AddBehaviour() .BehaviourController.AddBehaviour(); //////////////////////////////////////////////////////////////////////////////////// IUniverseObject leftPaddle = UniverseObjectFactory.Instantiate().SetUniverseObject("Left Paddle"); leftPaddle.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-468f, 0f), scale: new Vector2D(15f, 60f)) - .BehaviourController.AddBehaviour(Shape2D.Square) + .BehaviourController.AddBehaviour(Shape2D.Square) .BehaviourController.AddBehaviour().IsStatic = true; - PaddleBehaviour leftPaddleBehaviour = BehaviourFactory.Instantiate(Keys.W, Keys.S, 228f, -228f, 400f); + Paddle leftPaddleBehaviour = BehaviourFactory.Instantiate(Keys.W, Keys.S, 228f, -228f, 400f); leftPaddleBehaviour.Id = "lp"; leftPaddle.BehaviourController.AddBehaviour(leftPaddleBehaviour); universe.Register(leftPaddle); IUniverseObject rightPaddle = UniverseObjectFactory.Instantiate().SetUniverseObject("Right Paddle"); rightPaddle.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(468f, 0f), scale: new Vector2D(15f, 60f)) - .BehaviourController.AddBehaviour(Shape2D.Square) + .BehaviourController.AddBehaviour(Shape2D.Square) .BehaviourController.AddBehaviour().IsStatic = true; - PaddleBehaviour rightPaddleBehaviour = BehaviourFactory.Instantiate(Keys.Up, Keys.Down, 228f, -228f, 400f); + Paddle rightPaddleBehaviour = BehaviourFactory.Instantiate(Keys.Up, Keys.Down, 228f, -228f, 400f); rightPaddleBehaviour.Id = "rp"; rightPaddle.BehaviourController.AddBehaviour(rightPaddleBehaviour); universe.Register(rightPaddle); @@ -98,24 +98,24 @@ public static class PongUniverse universe.InstantiateUniverseObject().SetUniverseObject("Wall Top") .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(0f, 308f), scale: new Vector2D(552f, 20f)) - .BehaviourController.AddBehaviour(Shape2D.Square) + .BehaviourController.AddBehaviour(Shape2D.Square) .BehaviourController.AddBehaviour().IsStatic = true; universe.InstantiateUniverseObject().SetUniverseObject("Wall Bottom") .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(0f, -308f), scale: new Vector2D(552f, 20f)) - .BehaviourController.AddBehaviour(Shape2D.Square) + .BehaviourController.AddBehaviour(Shape2D.Square) .BehaviourController.AddBehaviour().IsStatic = true; universe.InstantiateUniverseObject().SetUniverseObject("Wall Right") .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(532f, 0f), scale: new Vector2D(20f, 328f)) - .BehaviourController.AddBehaviour((Action)pongManager.ScoreToLeft) - .BehaviourController.AddBehaviour(Shape2D.Square) + .BehaviourController.AddBehaviour((Action)pongManager.ScoreToLeft) + .BehaviourController.AddBehaviour(Shape2D.Square) .BehaviourController.AddBehaviour().IsStatic = true; universe.InstantiateUniverseObject().SetUniverseObject("Wall Left") .BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-532f, 0f), scale: new Vector2D(20f, 328f)) - .BehaviourController.AddBehaviour((Action)pongManager.ScoreToRight) - .BehaviourController.AddBehaviour(Shape2D.Square) + .BehaviourController.AddBehaviour((Action)pongManager.ScoreToRight) + .BehaviourController.AddBehaviour(Shape2D.Square) .BehaviourController.AddBehaviour().IsStatic = true; return universe;