little explosions and fixed more bugs in the ecs

This commit is contained in:
Dylan Wilson
2018-07-31 21:52:13 +10:00
parent defeac7b97
commit ccf03f18ed
8 changed files with 58 additions and 19 deletions
@@ -1,5 +1,6 @@
using JamGame.Components;
using Microsoft.Xna.Framework;
using MonoGame.Extended;
using MonoGame.Extended.Entities;
using MonoGame.Extended.Entities.Systems;
@@ -7,11 +8,13 @@ namespace JamGame.Systems
{
public class CollisionResponseSystem : EntityProcessingSystem
{
private readonly EntityFactory _entityFactory;
private ComponentMapper<Body> _bodyMapper;
public CollisionResponseSystem()
: base(Aspect.All(typeof(Body)))
public CollisionResponseSystem(EntityFactory entityFactory)
: base(Aspect.All(typeof(Body), typeof(Transform2)))
{
_entityFactory = entityFactory;
}
public override void Initialize(IComponentMapperService mapperService)
@@ -28,10 +31,17 @@ namespace JamGame.Systems
var entity = GetEntity(entityId);
if (entity.Has<Projectile>())
{
_entityFactory.SpawnExplosion(entity.Get<Transform2>().Position, body.Velocity / 2f);
entity.Destroy();
}
if (entity.Has<Enemy>())
{
_entityFactory.SpawnExplosion(entity.Get<Transform2>().Position, body.Velocity / 2f);
entity.Destroy();
}
}
}
}