level boundaries
parent
72d99b36f3
commit
24ffd2c9ba
|
@ -0,0 +1,18 @@
|
|||
using Encompass;
|
||||
using PongFE.Components;
|
||||
using PongFE.Messages;
|
||||
|
||||
namespace PongFE.Spawners
|
||||
{
|
||||
public class BoundarySpawner : Spawner<BoundarySpawnMessage>
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
)
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue