From 24ffd2c9bad651bea06161f9a84d6ac25b8fb861 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Tue, 14 Jul 2020 18:53:55 -0700 Subject: [PATCH] level boundaries --- PongFE/Engines/Spawners/BoundarySpawner.cs | 18 +++++++++++++ PongFE/Messages/BoundarySpawnMessage.cs | 19 ++++++++++++++ PongFE/PongFEGame.cs | 30 +++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 PongFE/Engines/Spawners/BoundarySpawner.cs create mode 100644 PongFE/Messages/BoundarySpawnMessage.cs diff --git a/PongFE/Engines/Spawners/BoundarySpawner.cs b/PongFE/Engines/Spawners/BoundarySpawner.cs new file mode 100644 index 0000000..626727b --- /dev/null +++ b/PongFE/Engines/Spawners/BoundarySpawner.cs @@ -0,0 +1,18 @@ +using Encompass; +using PongFE.Components; +using PongFE.Messages; + +namespace PongFE.Spawners +{ + public class BoundarySpawner : Spawner + { + protected override void Spawn(BoundarySpawnMessage message) + { + var entity = CreateEntity(); + + AddComponent(entity, new PositionComponent(message.Position)); + AddComponent(entity, new CollisionComponent(new MoonTools.Bonk.Rectangle(0, 0, message.Width, message.Height))); + AddComponent(entity, new CanCauseBounceComponent()); + } + } +} diff --git a/PongFE/Messages/BoundarySpawnMessage.cs b/PongFE/Messages/BoundarySpawnMessage.cs new file mode 100644 index 0000000..9744122 --- /dev/null +++ b/PongFE/Messages/BoundarySpawnMessage.cs @@ -0,0 +1,19 @@ +using Encompass; +using MoonTools.Structs; + +namespace PongFE.Messages +{ + public struct BoundarySpawnMessage : IMessage + { + public Position2D Position { get; } + public int Width { get; } + public int Height { get; } + + public BoundarySpawnMessage(Position2D position, int width, int height) + { + Position = position; + Width = width; + Height = height; + } + } +} diff --git a/PongFE/PongFEGame.cs b/PongFE/PongFEGame.cs index ec00db7..9976f06 100644 --- a/PongFE/PongFEGame.cs +++ b/PongFE/PongFEGame.cs @@ -64,6 +64,7 @@ namespace PongFE WorldBuilder.AddEngine(new UpdateVelocityEngine()); WorldBuilder.AddEngine(new BallSpawner(BallTexture)); + WorldBuilder.AddEngine(new BoundarySpawner()); WorldBuilder.AddOrderedRenderer(new Texture2DRenderer(SpriteBatch)); @@ -78,7 +79,34 @@ namespace PongFE WorldBuilder.SendMessage( new BallSpawnMessage( new MoonTools.Structs.Position2D(640, 360), - new System.Numerics.Vector2(-100, -20) + new System.Numerics.Vector2(-200, -50) + ) + ); + + // top boundary + WorldBuilder.SendMessage( + new BoundarySpawnMessage( + new MoonTools.Structs.Position2D(0, -6), + 1280, + 6 + ) + ); + + // right boundary + WorldBuilder.SendMessage( + new BoundarySpawnMessage( + new MoonTools.Structs.Position2D(1280, 0), + 6, + 720 + ) + ); + + // bottom boundary + WorldBuilder.SendMessage( + new BoundarySpawnMessage( + new MoonTools.Structs.Position2D(0, 720), + 1280, + 6 ) );