Files
MonoGame.Extended/Source/SpaceGame/Entities/BulletFactory.cs
T
2016-01-13 20:15:04 +10:00

34 lines
991 B
C#

using Microsoft.Xna.Framework;
using MonoGame.Extended.TextureAtlases;
using SpaceGame.Entities;
namespace SpaceGame
{
public interface IBulletFactory
{
void Create(Vector2 position, Vector2 direction, float rotation, float speed);
}
public class BulletFactory : IBulletFactory
{
private readonly IEntityManager _entityManager;
private readonly TextureRegion2D _bulletRegion;
public BulletFactory(IEntityManager entityManager, TextureRegion2D bulletRegion)
{
_entityManager = entityManager;
_bulletRegion = bulletRegion;
}
public void Create(Vector2 position, Vector2 direction, float rotation, float speed)
{
var velocity = direction * speed;
var laser = new Laser(_bulletRegion, velocity)
{
Position = position,
Rotation = rotation
};
_entityManager.AddEntity(laser);
}
}
}