PongFE/PongFE/Engines/Spawners/BallSpawner.cs

29 lines
928 B
C#

using Encompass;
using Microsoft.Xna.Framework.Graphics;
using PongFE.Components;
using PongFE.Messages;
namespace PongFE.Spawners
{
public class BallSpawner : Spawner<BallSpawnMessage>
{
private Texture2D BallTexture { get; }
public BallSpawner(Texture2D ballTexture)
{
BallTexture = ballTexture;
}
protected override void Spawn(BallSpawnMessage message)
{
var ball = CreateEntity();
AddComponent(ball, new PositionComponent(message.Position));
AddComponent(ball, new VelocityComponent(message.Velocity));
AddComponent(ball, new CollisionComponent(new MoonTools.Bonk.Rectangle(0, 0, 16, 16)));
AddComponent(ball, new Texture2DComponent(BallTexture, 0));
AddComponent(ball, new CanBeBouncedComponent());
AddComponent(ball, new BounceResponseComponent());
}
}
}