diff --git a/Source/Demos/JamGame/Content/0x72_16x16DungeonTileset.v4.png b/Source/Demos/JamGame/Content/0x72_16x16DungeonTileset.v4.png index ea123ef5..ad97407b 100644 Binary files a/Source/Demos/JamGame/Content/0x72_16x16DungeonTileset.v4.png and b/Source/Demos/JamGame/Content/0x72_16x16DungeonTileset.v4.png differ diff --git a/Source/Demos/JamGame/EntityFactory.cs b/Source/Demos/JamGame/EntityFactory.cs index d31b6261..fb17553a 100644 --- a/Source/Demos/JamGame/EntityFactory.cs +++ b/Source/Demos/JamGame/EntityFactory.cs @@ -1,6 +1,9 @@ -using JamGame.Components; +using System.Linq; +using JamGame.Components; using Microsoft.Xna.Framework; using MonoGame.Extended; +using MonoGame.Extended.Animations; +using MonoGame.Extended.Animations.SpriteSheets; using MonoGame.Extended.Entities; using MonoGame.Extended.Sprites; @@ -31,7 +34,7 @@ namespace JamGame var entity = World.CreateEntity(); entity.Attach(new Sprite(_tileset.GetTile(145))); entity.Attach(new Transform2(x, y)); - entity.Attach(new Body { Size = new Size2(16, 16) }); + entity.Attach(new Body { Size = new Size2(16, 16), Velocity = new Vector2(-8, 0) }); entity.Attach(new Enemy()); } @@ -49,7 +52,7 @@ namespace JamGame var entity = World.CreateEntity(); entity.Attach(new Sprite(_tileset.GetTile(213))); entity.Attach(new Transform2(x, y)); - entity.Attach(new Body { Size = new Size2(16, 16) }); + entity.Attach(new Body { Size = new Size2(16, 16), Velocity = new Vector2(-2, 0) }); entity.Attach(new Enemy()); } @@ -62,5 +65,18 @@ namespace JamGame entity.Attach(new Projectile()); return entity; } + + public void SpawnExplosion(Vector2 position, Vector2 velocity) + { + var frames = new[] {256, 257, 258, 259, 260, 261, 262, 263, 264}; + var animationFactory = new SpriteSheetAnimationFactory(frames.Select(f => _tileset.GetTile(f))); + animationFactory.Add("explode", new SpriteSheetAnimationData(new []{0,1,2,3,4,5,6,7,8}, isLooping: false, frameDuration: 1f / 32f)); + var entity = World.CreateEntity(); + var animatedSprite = new AnimatedSprite(animationFactory); + entity.Attach(animatedSprite); + entity.Attach(new Transform2(position)); + entity.Attach(new Body {Velocity = velocity}); + animatedSprite.Play("explode", () => entity.Destroy()); + } } } \ No newline at end of file diff --git a/Source/Demos/JamGame/GameMain.cs b/Source/Demos/JamGame/GameMain.cs index aac501ec..566ca580 100644 --- a/Source/Demos/JamGame/GameMain.cs +++ b/Source/Demos/JamGame/GameMain.cs @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using MonoGame.Extended; using MonoGame.Extended.BitmapFonts; using MonoGame.Extended.Entities; @@ -44,15 +45,20 @@ namespace JamGame .AddSystem(new PlayerControlSystem(this, entityFactory)) .AddSystem(new BodyMovementSystem()) .AddSystem(new CollisionSystem()) - .AddSystem(new CollisionResponseSystem()) + .AddSystem(new CollisionResponseSystem(entityFactory)) .Build(); entityFactory.World = _world; entityFactory.SpawnPlayer(100, 100); - entityFactory.SpawnZombie(200, 80); - entityFactory.SpawnSkeleton(200, 100); - entityFactory.SpawnPurpleThing(200, 120); + var random = new FastRandom(); + + for (var i = 0; i < 20; i++) + { + entityFactory.SpawnZombie(random.Next(150, 800), random.Next(0, 480)); + //entityFactory.SpawnSkeleton(random.Next(150, 250), random.Next(110, 250)); + //entityFactory.SpawnPurpleThing(random.Next(150, 250), random.Next(110, 250)); + } } protected override void UnloadContent() diff --git a/Source/Demos/JamGame/Systems/CollisionResponseSystem.cs b/Source/Demos/JamGame/Systems/CollisionResponseSystem.cs index ffdf5f04..37abcab8 100644 --- a/Source/Demos/JamGame/Systems/CollisionResponseSystem.cs +++ b/Source/Demos/JamGame/Systems/CollisionResponseSystem.cs @@ -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
_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