diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..2fe98d26 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: craftworkgames diff --git a/Logos/github-social-media-large.png b/Logos/github-social-media-large.png new file mode 100644 index 00000000..70c5594d Binary files /dev/null and b/Logos/github-social-media-large.png differ diff --git a/Source/Demos/Features/Content/Content.mgcb b/Source/Demos/Features/Content/Content.mgcb index 3fa77c22..2ef3dafd 100644 --- a/Source/Demos/Features/Content/Content.mgcb +++ b/Source/Demos/Features/Content/Content.mgcb @@ -31,12 +31,7 @@ /processor:TexturePackerProcessor /build:adventure-gui-atlas.json -#begin small-font.fnt -/importer:BitmapFontImporter -/processor:BitmapFontProcessor -/build:small-font.fnt - -#begin small-font_0.png +#begin Animations/fireball.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -46,7 +41,42 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:small-font_0.png +/build:Animations/fireball.png + +#begin Animations/motw.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Animations/motw.png + +#begin Animations/zombie.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Animations/zombie.png + +#begin Animations/zombie-animations.aa +/importer:AstridAnimatorImporter +/processor:AstridAnimatorProcessor +/build:Animations/zombie-animations.aa + +#begin Animations/zombie-atlas.json +/importer:JsonContentImporter +/processor:JsonContentProcessor +/processorParam:ContentType=TextureAtlas +/build:Animations/zombie-atlas.json #begin Fonts/impact-32.fnt /importer:BitmapFontImporter @@ -82,19 +112,12 @@ /processorParam:TextureFormat=Color /build:Fonts/montserrat-32_0.png -#begin Textures/logo-square-512.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/logo-square-512.png +#begin small-font.fnt +/importer:BitmapFontImporter +/processor:BitmapFontProcessor +/build:small-font.fnt -#begin Textures/vignette.png +#begin small-font_0.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -104,175 +127,7 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/vignette.png - -#begin Textures/hills.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/hills.png - -#begin Textures/hills-sky.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/hills-sky.png - -#begin Textures/hills-clouds.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/hills-clouds.png - -#begin Textures/hills-4.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/hills-4.png - -#begin Textures/hills-3.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/hills-3.png - -#begin Textures/hills-2.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/hills-2.png - -#begin Textures/hills-1.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/hills-1.png - -#begin Textures/logo-square-128.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/logo-square-128.png - -#begin Textures/car-wheel.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/car-wheel.png - -#begin Textures/car-hull.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/car-hull.png - -#begin Textures/spike_ball.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/spike_ball.png - -#begin Textures/particle.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/particle.png - -#begin Textures/clipping-test.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/clipping-test.png - -#begin Textures/bg_sharbi.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/bg_sharbi.png +/build:small-font_0.png #begin Textures/axe.png /importer:TextureImporter @@ -286,7 +141,7 @@ /processorParam:TextureFormat=Color /build:Textures/axe.png -#begin Animations/fireball.png +#begin Textures/bg_sharbi.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -296,9 +151,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Animations/fireball.png +/build:Textures/bg_sharbi.png -#begin Animations/motw.png +#begin Textures/car-hull.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -308,19 +163,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Animations/motw.png +/build:Textures/car-hull.png -#begin Animations/zombie-animations.aa -/importer:AstridAnimatorImporter -/processor:AstridAnimatorProcessor -/build:Animations/zombie-animations.aa - -#begin Animations/zombie-atlas.json -/importer:TexturePackerJsonImporter -/processor:TexturePackerProcessor -/build:Animations/zombie-atlas.json - -#begin Animations/zombie.png +#begin Textures/car-wheel.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -330,7 +175,175 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Animations/zombie.png +/build:Textures/car-wheel.png + +#begin Textures/clipping-test.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/clipping-test.png + +#begin Textures/colored_castle.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/colored_castle.png + +#begin Textures/hills.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/hills.png + +#begin Textures/hills-1.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/hills-1.png + +#begin Textures/hills-2.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/hills-2.png + +#begin Textures/hills-3.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/hills-3.png + +#begin Textures/hills-4.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/hills-4.png + +#begin Textures/hills-clouds.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/hills-clouds.png + +#begin Textures/hills-sky.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/hills-sky.png + +#begin Textures/logo-square-128.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/logo-square-128.png + +#begin Textures/logo-square-512.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/logo-square-512.png + +#begin Textures/particle.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/particle.png + +#begin Textures/spike_ball.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/spike_ball.png + +#begin Textures/vignette.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/vignette.png #begin TiledMaps/abstractTiles_sheet.png /importer:TextureImporter @@ -444,6 +457,11 @@ /processor:TiledMapProcessor /build:TiledMaps/level07.tmx +#begin TiledMaps/level08.tmx +/importer:TiledMapImporter +/processor:TiledMapProcessor +/build:TiledMaps/level08.tmx + #begin TiledMaps/non-uniform-tileset.png /importer:TextureImporter /processor:TextureProcessor @@ -492,20 +510,3 @@ /processorParam:TextureFormat=Color /build:TiledMaps/voxelTiles_sheet.png -#begin TiledMaps/level08.tmx -/importer:TiledMapImporter -/processor:TiledMapProcessor -/build:TiledMaps/level08.tmx - -#begin Textures/colored_castle.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/colored_castle.png - diff --git a/Source/Demos/Features/Demos/AnimationsDemo.cs b/Source/Demos/Features/Demos/AnimationsDemo.cs index 4b6faf64..23c1767f 100644 --- a/Source/Demos/Features/Demos/AnimationsDemo.cs +++ b/Source/Demos/Features/Demos/AnimationsDemo.cs @@ -1,5 +1,6 @@ using System; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using MonoGame.Extended; @@ -26,6 +27,8 @@ namespace Features.Demos public AnimationsDemo(GameMain game) : base(game) { + ContentTypeReaderManager.AddTypeCreator("TextureAtlas", () => new TextureAtlasJsonContentTypeReader()); + ContentTypeReaderManager.AddTypeCreator("Default", () => new JsonContentTypeReader()); } //protected override void Initialize() @@ -288,7 +291,7 @@ namespace Features.Demos //public void Draw(SpriteBatch spriteBatch) //{ - // //spriteBatch.Draw(_sprite); + // spriteBatch.Draw(_sprite, _transform); //} public void Walk(float direction) diff --git a/Source/Demos/Features/Demos/CollisionDemo.cs b/Source/Demos/Features/Demos/CollisionDemo.cs index 77977625..dcc448b9 100644 --- a/Source/Demos/Features/Demos/CollisionDemo.cs +++ b/Source/Demos/Features/Demos/CollisionDemo.cs @@ -36,21 +36,21 @@ namespace Features.Demos _blankTexture = new Texture2D(GraphicsDevice, 1, 1); _blankTexture.SetData(new[] { Color.WhiteSmoke }); - var demoBall1 = new DemoBall(new Sprite(_spikeyBallTexture)) + var spikyBallLeft = new DemoBall(new Sprite(_spikeyBallTexture)) { Position = new Vector2(200, 240), Velocity = new Vector2(0, -120) }; - _actors.Add(demoBall1); + _actors.Add(spikyBallLeft); - var demoBall2 = new DemoBall(new Sprite(_spikeyBallTexture)) + var spikeyBallRight = new DemoBall(new Sprite(_spikeyBallTexture)) { Position = new Vector2(600, 240), Velocity = new Vector2(0, 120) }; - _actors.Add(demoBall2); + _actors.Add(spikeyBallRight); - var controllableBall = new DemoBall(new Sprite(_spikeyBallTexture)) + var controllableBall = new ControllableBall(new Sprite(_spikeyBallTexture)) { Position = new Vector2(400, 240), Velocity = new Vector2(0, 0) @@ -58,26 +58,26 @@ namespace Features.Demos _actors.Add(controllableBall); _controllableBall = controllableBall; - var wall1 = new DemoWall(new Sprite(_blankTexture)) + var topWall = new DemoWall(new Sprite(_blankTexture)) { Bounds = new RectangleF(0, 0, 800, 20), Position = new Vector2(0, 0) }; - _actors.Add(wall1); + _actors.Add(topWall); - var wall2 = new DemoWall(new Sprite(_blankTexture)) + var bottomWall = new DemoWall(new Sprite(_blankTexture)) { Position = new Vector2(0, 460), Bounds = new RectangleF(0, 0, 800, 20) }; - _actors.Add(wall2); + _actors.Add(bottomWall); - var centerWall = new DemoWall(new Sprite(_blankTexture)) + var spikeyBallCenter = new StationaryBall(new Sprite(_spikeyBallTexture)) { - Bounds = new RectangleF(0, 0, 50, 50), - Position = new Vector2(400, 200) + Position = new Vector2(400, 240), + Velocity = Vector2.Zero, }; - _actors.Add(centerWall); + _actors.Add(spikeyBallCenter); foreach (var actor in _actors) { @@ -126,13 +126,6 @@ namespace Features.Demos foreach (var actor in _actors) { actor.Draw(_spriteBatch); - if (actor.Bounds is RectangleF rect) - { - _spriteBatch.Draw(_blankTexture, rect.ToRectangle(), Color.WhiteSmoke); - } else if (actor.Bounds is CircleF circle) - { - _spriteBatch.Draw(_blankTexture, circle.Position, Color.WhiteSmoke); - } } _spriteBatch.End(); @@ -153,9 +146,10 @@ namespace Features.Demos Bounds = sprite.GetBoundingRectangle(new Transform2()); } - - public Vector2 Offset { get; set; } - + /// + /// Gets or sets the actor's position and updates teh actor's bounds + /// position. + /// public Vector2 Position { get { return _position; } @@ -166,8 +160,20 @@ namespace Features.Demos } } + /// + /// Gets or sets the actor's collision bounds. + /// public IShapeF Bounds { get; set; } + /// + /// Gets or sets how far the actor's collision bounds are offset from + /// the actor's position. + /// + public Vector2 Offset { get; set; } + + /// + /// Gets or sets the actor's velocity. + /// public Vector2 Velocity { get; set; } public virtual void OnCollision(CollisionEventArgs collisionInfo) @@ -201,14 +207,12 @@ namespace Features.Demos { public DemoBall(Sprite sprite) : base(sprite) { - Offset = new Vector2(75, 75); Bounds = new CircleF(Position + Offset, 60); } public override void Update(GameTime gameTime) { base.Update(gameTime); - Bounds.Position = Position; } public override void OnCollision(CollisionEventArgs collisionInfo) @@ -220,5 +224,40 @@ namespace Features.Demos } } + /// + /// Ball that doesn't move when collided with. + /// + class StationaryBall : DemoBall + { + public StationaryBall(Sprite sprite) : base(sprite) + { + } + + public override void OnCollision(CollisionEventArgs collisionInfo) + { + } + } + + /// + /// Player controlled ball. + /// + class ControllableBall : DemoBall + { + public ControllableBall(Sprite sprite) : base(sprite) + { + Bounds = new CircleF(Position + Offset, 60); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + } + + public override void OnCollision(CollisionEventArgs collisionInfo) + { + Position -= collisionInfo.PenetrationVector; + } + } + #endregion } \ No newline at end of file diff --git a/Source/Demos/Features/Demos/ShapesDemo.cs b/Source/Demos/Features/Demos/ShapesDemo.cs new file mode 100644 index 00000000..70a976dc --- /dev/null +++ b/Source/Demos/Features/Demos/ShapesDemo.cs @@ -0,0 +1,53 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using MonoGame.Extended; +using MonoGame.Extended.Shapes; + +namespace Features.Demos +{ + public class ShapesDemo : DemoBase + { + private SpriteBatch _spriteBatch; + + public ShapesDemo(GameMain game) + : base(game) + { + } + + public override string Name => "Shapes"; + + private readonly Polygon _polygon = new Polygon(new[] + { + new Vector2(0, 0), + new Vector2(40, 0), + new Vector2(40, 40), + new Vector2(60, 40), + new Vector2(60, 60), + new Vector2(0, 60), + }); + + protected override void LoadContent() + { + _spriteBatch = new SpriteBatch(GraphicsDevice); + } + + protected override void Draw(GameTime gameTime) + { + _spriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend); + + _spriteBatch.FillRectangle(10, 10, 50, 50, Color.DarkRed); + _spriteBatch.DrawRectangle(10, 10, 50, 50, Color.Red, 2); + + _spriteBatch.DrawCircle(100, 100, 32, 32, Color.Green, 4); + _spriteBatch.DrawEllipse(new Vector2(200, 200), new Vector2(50, 25), 32, Color.Orange, 8); + + _spriteBatch.DrawLine(300, 300, 400, 100, Color.White, 6); + + _spriteBatch.DrawPoint(500, 300, Color.Brown, 64); + + _spriteBatch.DrawPolygon(new Vector2(600, 200), _polygon, Color.Aqua); + + _spriteBatch.End(); + } + } +} \ No newline at end of file diff --git a/Source/Demos/Features/Demos/ViewportAdaptersDemo.cs b/Source/Demos/Features/Demos/ViewportAdaptersDemo.cs index 0e48ab9d..6c5ba0b0 100644 --- a/Source/Demos/Features/Demos/ViewportAdaptersDemo.cs +++ b/Source/Demos/Features/Demos/ViewportAdaptersDemo.cs @@ -40,7 +40,7 @@ namespace Features.Demos // the boxing viewport adapter uses letterboxing or pillarboxing to maintain aspect ratio // it's a little more complicated and needs to listen to the window client size changing event - _boxingViewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480, 88, 70); + _boxingViewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);//, 88, 70); // typically you'll only ever want to use one viewport adapter for a game, but in this sample we'll be // switching between them. @@ -68,13 +68,13 @@ namespace Features.Demos Exit(); if (keyboardState.IsKeyDown(Keys.D)) - _currentViewportAdapter = _defaultViewportAdapter; + SwitchAdapter(_defaultViewportAdapter); if (keyboardState.IsKeyDown(Keys.S)) - _currentViewportAdapter = _scalingViewportAdapter; + SwitchAdapter(_scalingViewportAdapter); if (keyboardState.IsKeyDown(Keys.B)) - _currentViewportAdapter = _boxingViewportAdapter; + SwitchAdapter(_boxingViewportAdapter); // if we've changed the viewport adapter mid game we need to reset the viewport back to the window size // this wouldn't normally be required if you're only ever using one viewport adapter @@ -90,6 +90,12 @@ namespace Features.Demos base.Update(gameTime); } + private void SwitchAdapter(ViewportAdapter viewportAdapter) + { + _currentViewportAdapter?.Dispose(); + _currentViewportAdapter = viewportAdapter; + } + protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); diff --git a/Source/Demos/Features/GameMain.cs b/Source/Demos/Features/GameMain.cs index 8f5b1bf6..a527bdef 100644 --- a/Source/Demos/Features/GameMain.cs +++ b/Source/Demos/Features/GameMain.cs @@ -45,6 +45,7 @@ namespace Features //new GuiLayoutDemo(this), //new GuiDemo(this), //new ScreensDemo(this), + new ShapesDemo(this), new ViewportAdaptersDemo(this), new CollisionDemo(this), new TiledMapsDemo(this), diff --git a/Source/Demos/JamGame/Components/Body.cs b/Source/Demos/JamGame/Components/Body.cs deleted file mode 100644 index d71c8426..00000000 --- a/Source/Demos/JamGame/Components/Body.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Xna.Framework; -using MonoGame.Extended; - -namespace JamGame.Components -{ - public class Body - { - public Vector2 Velocity { get; set; } - public Size2 Size { get; set; } - public bool IsHit { get; set; } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Components/Enemy.cs b/Source/Demos/JamGame/Components/Enemy.cs deleted file mode 100644 index cf1c6020..00000000 --- a/Source/Demos/JamGame/Components/Enemy.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace JamGame.Components -{ - public class Enemy - { - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Components/Expiry.cs b/Source/Demos/JamGame/Components/Expiry.cs deleted file mode 100644 index ad6a4698..00000000 --- a/Source/Demos/JamGame/Components/Expiry.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace JamGame.Components -{ - public class Expiry - { - public Expiry(float timeRemaining) - { - TimeRemaining = timeRemaining; - } - - public float TimeRemaining; - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Components/Player.cs b/Source/Demos/JamGame/Components/Player.cs deleted file mode 100644 index 84d2de8d..00000000 --- a/Source/Demos/JamGame/Components/Player.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace JamGame.Components -{ - public class Player - { - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Components/Projectile.cs b/Source/Demos/JamGame/Components/Projectile.cs deleted file mode 100644 index 04037cb0..00000000 --- a/Source/Demos/JamGame/Components/Projectile.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace JamGame.Components -{ - public class Projectile - { - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Content/0x72_16x16DungeonTileset.v4.png b/Source/Demos/JamGame/Content/0x72_16x16DungeonTileset.v4.png deleted file mode 100644 index ad97407b..00000000 Binary files a/Source/Demos/JamGame/Content/0x72_16x16DungeonTileset.v4.png and /dev/null differ diff --git a/Source/Demos/JamGame/Content/Content.mgcb b/Source/Demos/JamGame/Content/Content.mgcb deleted file mode 100644 index a188a3bc..00000000 --- a/Source/Demos/JamGame/Content/Content.mgcb +++ /dev/null @@ -1,45 +0,0 @@ - -#----------------------------- Global Properties ----------------------------# - -/outputDir:bin/$(Platform) -/intermediateDir:obj/$(Platform) -/platform:DesktopGL -/config: -/profile:Reach -/compress:False - -#-------------------------------- References --------------------------------# - -/reference:..\..\..\MonoGame.Extended.Content.Pipeline\bin\netstandard2.0\MonoGame.Extended.Content.Pipeline.dll - -#---------------------------------- Content ---------------------------------# - -#begin 0x72_16x16DungeonTileset.v4.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:0x72_16x16DungeonTileset.v4.png - -#begin Sensation.fnt -/importer:BitmapFontImporter -/processor:BitmapFontProcessor -/build:Sensation.fnt - -#begin Sensation_0.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Sensation_0.png - diff --git a/Source/Demos/JamGame/Content/Sensation.fnt b/Source/Demos/JamGame/Content/Sensation.fnt deleted file mode 100644 index 47145d09..00000000 --- a/Source/Demos/JamGame/Content/Sensation.fnt +++ /dev/null @@ -1,461 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Source/Demos/JamGame/Content/Sensation_0.png b/Source/Demos/JamGame/Content/Sensation_0.png deleted file mode 100644 index 3d76fb67..00000000 Binary files a/Source/Demos/JamGame/Content/Sensation_0.png and /dev/null differ diff --git a/Source/Demos/JamGame/Content/fireball.aseprite b/Source/Demos/JamGame/Content/fireball.aseprite deleted file mode 100644 index e19c47d5..00000000 Binary files a/Source/Demos/JamGame/Content/fireball.aseprite and /dev/null differ diff --git a/Source/Demos/JamGame/Content/fireball.gif b/Source/Demos/JamGame/Content/fireball.gif deleted file mode 100644 index a858d841..00000000 Binary files a/Source/Demos/JamGame/Content/fireball.gif and /dev/null differ diff --git a/Source/Demos/JamGame/Content/fireball.json b/Source/Demos/JamGame/Content/fireball.json deleted file mode 100644 index f6e66d36..00000000 --- a/Source/Demos/JamGame/Content/fireball.json +++ /dev/null @@ -1,47 +0,0 @@ -{ "frames": [ - { - "filename": "fireball 0.aseprite", - "frame": { "x": 0, "y": 0, "w": 16, "h": 16 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 16, "h": 16 }, - "sourceSize": { "w": 16, "h": 16 }, - "duration": 100 - }, - { - "filename": "fireball 1.aseprite", - "frame": { "x": 16, "y": 0, "w": 16, "h": 16 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 16, "h": 16 }, - "sourceSize": { "w": 16, "h": 16 }, - "duration": 100 - }, - { - "filename": "fireball 2.aseprite", - "frame": { "x": 32, "y": 0, "w": 16, "h": 16 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 16, "h": 16 }, - "sourceSize": { "w": 16, "h": 16 }, - "duration": 100 - }, - { - "filename": "fireball 3.aseprite", - "frame": { "x": 48, "y": 0, "w": 16, "h": 16 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 16, "h": 16 }, - "sourceSize": { "w": 16, "h": 16 }, - "duration": 100 - } - ], - "meta": { - "app": "http://www.aseprite.org/", - "version": "1.2.9-x64", - "image": "D:\\Github\\MonoGame.Extended\\Source\\Demos\\JamGame\\Content\\fireball.png", - "format": "I8", - "size": { "w": 64, "h": 16 }, - "scale": "1" - } -} diff --git a/Source/Demos/JamGame/Content/fireball.png b/Source/Demos/JamGame/Content/fireball.png deleted file mode 100644 index 3b91d460..00000000 Binary files a/Source/Demos/JamGame/Content/fireball.png and /dev/null differ diff --git a/Source/Demos/JamGame/Content/level-1.tmx b/Source/Demos/JamGame/Content/level-1.tmx deleted file mode 100644 index 2f48861d..00000000 --- a/Source/Demos/JamGame/Content/level-1.tmx +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - eJzt00kKwkAQheG0unAbxQNEj+AxFDyAguNOwSFewOHgvoWBJnTHhJCF6X/xQaUaXiVFx0RR1JGuGEc9k7mjbxpiz6kie89fubEMZOipl7Jy9OOvkVXn9QrOMv3csz0nb1GQs5ZNwXmWm8hYJp76KCdHP2mIPaeKs1xK5E5r2MpO9nKomfUPrnKTVO4B7OEhT3nJu8Qe2sq3h9C09Z77hHbPQ/te/msAAAAAAAAAAAAAAAAAAAAAgM8HRmLDQA== - - - - - eJzt08EJAjEQBdBVK1ArUDuwKO1A+9h+BLEBy7ANc/AQcIUwiQbkPfgQQpj5lwwDrR1Sjr1L/NAp5fw67wve3wveXMNt2nh03k+d1n9wbDjrG/I/yLtL7wIfzFMWWWYTd9GUzIrsq+m4SllnWU7cRVMyK7KvpuM2ZZdlM3EXTcmsyL6ajkDcrXcBAAAAAAAAAAAAAP7aE8RUFWM= - - - diff --git a/Source/Demos/JamGame/EntityFactory.cs b/Source/Demos/JamGame/EntityFactory.cs deleted file mode 100644 index fb17553a..00000000 --- a/Source/Demos/JamGame/EntityFactory.cs +++ /dev/null @@ -1,82 +0,0 @@ -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; - -namespace JamGame -{ - public class EntityFactory - { - private readonly Tileset _tileset; - - public EntityFactory(Tileset tileset) - { - _tileset = tileset; - } - - public World World { get; set; } - - public void SpawnPlayer(float x, float y) - { - var entity = World.CreateEntity(); - entity.Attach(new Sprite(_tileset.GetTile(232))); - entity.Attach(new Transform2(x, y)); - entity.Attach(new Player()); - entity.Attach(new Body { Size = new Size2(16, 16) }); - } - - public void SpawnSkeleton(float x, float y) - { - 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), Velocity = new Vector2(-8, 0) }); - entity.Attach(new Enemy()); - } - - public void SpawnZombie(float x, float y) - { - var entity = World.CreateEntity(); - entity.Attach(new Sprite(_tileset.GetTile(165))); - entity.Attach(new Transform2(x, y)); - entity.Attach(new Body {Size = new Size2(16, 16), Velocity = new Vector2(-4, 0) }); - entity.Attach(new Enemy()); - } - - public void SpawnPurpleThing(float x, float y) - { - 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), Velocity = new Vector2(-2, 0) }); - entity.Attach(new Enemy()); - } - - public Entity SpawnFireball(float x, float y) - { - var entity = World.CreateEntity(); - entity.Attach(new Sprite(_tileset.GetTile(240))); - entity.Attach(new Transform2(x, y) { Scale = Vector2.One * 0.75f }); - entity.Attach(new Body { Size = new Size2(16, 16) }); - 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 deleted file mode 100644 index 566ca580..00000000 --- a/Source/Demos/JamGame/GameMain.cs +++ /dev/null @@ -1,87 +0,0 @@ -using JamGame.Systems; -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; - -namespace JamGame -{ - public class MainGame : Game - { - // ReSharper disable once NotAccessedField.Local - private GraphicsDeviceManager _graphicsDeviceManager; - private SpriteBatch _spriteBatch; - private World _world; - - public MainGame() - { - _graphicsDeviceManager = new GraphicsDeviceManager(this) - { - PreferredBackBufferWidth = 1400, - PreferredBackBufferHeight = 900 - }; - Content.RootDirectory = "Content"; - IsMouseVisible = true; - Window.AllowUserResizing = true; - } - - public MouseState MouseState { get; private set; } - public KeyboardState KeyboardState { get; private set; } - - protected override void LoadContent() - { - var font = Content.Load("Sensation"); - var texture = Content.Load("0x72_16x16DungeonTileset.v4"); - var tileset = new Tileset(texture, 16, 16); - var entityFactory = new EntityFactory(tileset); - - _spriteBatch = new SpriteBatch(GraphicsDevice); - _world = new WorldBuilder() - .AddSystem(new MapRenderingSystem(GraphicsDevice, tileset)) - .AddSystem(new SpriteRenderingSystem(GraphicsDevice, texture)) - .AddSystem(new HudSystem(this, GraphicsDevice, font, tileset)) - .AddSystem(new PlayerControlSystem(this, entityFactory)) - .AddSystem(new BodyMovementSystem()) - .AddSystem(new CollisionSystem()) - .AddSystem(new CollisionResponseSystem(entityFactory)) - .Build(); - - entityFactory.World = _world; - entityFactory.SpawnPlayer(100, 100); - - 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() - { - _spriteBatch.Dispose(); - } - - protected override void Update(GameTime gameTime) - { - MouseState = Mouse.GetState(); - KeyboardState = Keyboard.GetState(); - - if (KeyboardState.IsKeyDown(Keys.Escape)) - Exit(); - - _world.Update(gameTime); - base.Update(gameTime); - } - - protected override void Draw(GameTime gameTime) - { - _world.Draw(gameTime); - base.Draw(gameTime); - } - } -} diff --git a/Source/Demos/JamGame/Icon.bmp b/Source/Demos/JamGame/Icon.bmp deleted file mode 100644 index 2b481653..00000000 Binary files a/Source/Demos/JamGame/Icon.bmp and /dev/null differ diff --git a/Source/Demos/JamGame/Icon.ico b/Source/Demos/JamGame/Icon.ico deleted file mode 100644 index 7d9dec18..00000000 Binary files a/Source/Demos/JamGame/Icon.ico and /dev/null differ diff --git a/Source/Demos/JamGame/JamGame.csproj b/Source/Demos/JamGame/JamGame.csproj deleted file mode 100644 index a9095669..00000000 --- a/Source/Demos/JamGame/JamGame.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - WinExe - netcoreapp2.0 - - - - - - - - - - - - - - - - - - diff --git a/Source/Demos/JamGame/Program.cs b/Source/Demos/JamGame/Program.cs deleted file mode 100644 index d7e343f0..00000000 --- a/Source/Demos/JamGame/Program.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace JamGame -{ - public static class Program - { - [STAThread] - public static void Main() - { - using (var game = new MainGame()) - game.Run(); - } - } -} diff --git a/Source/Demos/JamGame/README.md b/Source/Demos/JamGame/README.md deleted file mode 100644 index 5cd75402..00000000 --- a/Source/Demos/JamGame/README.md +++ /dev/null @@ -1,5 +0,0 @@ - -## Assets Used - - - [16x16 Dungeon Tileset](https://0x72.itch.io/16x16-dungeon-tileset) - - [Kyrise's Free 16x16 RPG Icon Pack](https://kyrise.itch.io/kyrises-free-16x16-rpg-icon-pack) diff --git a/Source/Demos/JamGame/Systems/BodyMovementSystem.cs b/Source/Demos/JamGame/Systems/BodyMovementSystem.cs deleted file mode 100644 index 9d6fefc0..00000000 --- a/Source/Demos/JamGame/Systems/BodyMovementSystem.cs +++ /dev/null @@ -1,38 +0,0 @@ -using JamGame.Components; -using Microsoft.Xna.Framework; -using MonoGame.Extended; -using MonoGame.Extended.Entities; -using MonoGame.Extended.Entities.Systems; - -namespace JamGame.Systems -{ - public class BodyMovementSystem : EntityUpdateSystem - { - private ComponentMapper _transformMapper; - private ComponentMapper _bodyMapper; - - public BodyMovementSystem() - : base(Aspect.All(typeof(Transform2), typeof(Body))) - { - } - - public override void Initialize(IComponentMapperService mapperService) - { - _transformMapper = mapperService.GetMapper(); - _bodyMapper = mapperService.GetMapper(); - } - - public override void Update(GameTime gameTime) - { - var elapsedSeconds = gameTime.GetElapsedSeconds(); - - foreach (var entity in ActiveEntities) - { - var transform = _transformMapper.Get(entity); - var body = _bodyMapper.Get(entity); - - transform.Position += body.Velocity * elapsedSeconds; - } - } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Systems/CollisionResponseSystem.cs b/Source/Demos/JamGame/Systems/CollisionResponseSystem.cs deleted file mode 100644 index 37abcab8..00000000 --- a/Source/Demos/JamGame/Systems/CollisionResponseSystem.cs +++ /dev/null @@ -1,48 +0,0 @@ -using JamGame.Components; -using Microsoft.Xna.Framework; -using MonoGame.Extended; -using MonoGame.Extended.Entities; -using MonoGame.Extended.Entities.Systems; - -namespace JamGame.Systems -{ - public class CollisionResponseSystem : EntityProcessingSystem - { - private readonly EntityFactory _entityFactory; - private ComponentMapper _bodyMapper; - - public CollisionResponseSystem(EntityFactory entityFactory) - : base(Aspect.All(typeof(Body), typeof(Transform2))) - { - _entityFactory = entityFactory; - } - - public override void Initialize(IComponentMapperService mapperService) - { - _bodyMapper = mapperService.GetMapper(); - } - - public override void Process(GameTime gameTime, int entityId) - { - var body = _bodyMapper.Get(entityId); - - if (body.IsHit) - { - var entity = GetEntity(entityId); - - if (entity.Has()) - { - _entityFactory.SpawnExplosion(entity.Get().Position, body.Velocity / 2f); - entity.Destroy(); - } - - - if (entity.Has()) - { - _entityFactory.SpawnExplosion(entity.Get().Position, body.Velocity / 2f); - entity.Destroy(); - } - } - } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Systems/CollisionSystem.cs b/Source/Demos/JamGame/Systems/CollisionSystem.cs deleted file mode 100644 index 7abc71f0..00000000 --- a/Source/Demos/JamGame/Systems/CollisionSystem.cs +++ /dev/null @@ -1,56 +0,0 @@ -using JamGame.Components; -using Microsoft.Xna.Framework; -using MonoGame.Extended; -using MonoGame.Extended.Entities; -using MonoGame.Extended.Entities.Systems; - -namespace JamGame.Systems -{ - public class CollisionSystem : EntityUpdateSystem - { - private ComponentMapper _bodyMapper; - private ComponentMapper _transformMapper; - - public CollisionSystem() - : base(Aspect.All(typeof(Body), typeof(Transform2))) - { - - } - - public override void Initialize(IComponentMapperService mapperService) - { - _bodyMapper = mapperService.GetMapper(); - _transformMapper = mapperService.GetMapper(); - } - - public override void Update(GameTime gameTime) - { - foreach (var entityA in ActiveEntities) - { - var bodyA = _bodyMapper.Get(entityA); - var transformA = _transformMapper.Get(entityA); - var rectangleA = GetBoundingRectangle(transformA, bodyA); - - bodyA.IsHit = false; - - foreach (var entityB in ActiveEntities) - { - var bodyB = _bodyMapper.Get(entityB); - var transformB = _transformMapper.Get(entityB); - var rectangleB = GetBoundingRectangle(transformB, bodyB); - - if (entityA != entityB && rectangleA.Intersects(rectangleB)) - { - bodyA.IsHit = true; - bodyB.IsHit = true; - } - } - } - } - - private static RectangleF GetBoundingRectangle(Transform2 transform, Body body) - { - return new RectangleF(transform.Position.X - body.Size.Width / 2f, transform.Position.Y + body.Size.Height / 2f, body.Size.Width, body.Size.Height); - } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Systems/HudSystem.cs b/Source/Demos/JamGame/Systems/HudSystem.cs deleted file mode 100644 index 6cf64414..00000000 --- a/Source/Demos/JamGame/Systems/HudSystem.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using MonoGame.Extended; -using MonoGame.Extended.BitmapFonts; -using MonoGame.Extended.Entities.Systems; -using MonoGame.Extended.TextureAtlases; - -namespace JamGame.Systems -{ - public class HudSystem : DrawSystem - { - private readonly MainGame _game; - private readonly BitmapFont _font; - private readonly Tileset _tileset; - private readonly SpriteBatch _spriteBatch; - - public HudSystem(MainGame game, GraphicsDevice graphicsDevice, BitmapFont font, Tileset tileset) - { - _game = game; - _font = font; - _tileset = tileset; - _spriteBatch = new SpriteBatch(graphicsDevice); - } - - public override void Draw(GameTime gameTime) - { - var tx = _game.MouseState.X / _tileset.TileWidth / 2; - var ty = _game.MouseState.Y / _tileset.TileHeight / 2; - var region = _tileset.GetTileAt(tx, ty); - - _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(2)); - _spriteBatch.DrawString(_font, $"{tx}, {ty}", Vector2.Zero, Color.AliceBlue); - _spriteBatch.DrawRectangle(tx * _tileset.TileWidth, ty * _tileset.TileHeight, _tileset.TileWidth, _tileset.TileHeight, Color.White); - - if(region != null) - _spriteBatch.Draw(region, new Vector2(350, 0), Color.White); - - _spriteBatch.End(); - } - - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Systems/MapRenderingSystem.cs b/Source/Demos/JamGame/Systems/MapRenderingSystem.cs deleted file mode 100644 index f323cacf..00000000 --- a/Source/Demos/JamGame/Systems/MapRenderingSystem.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using MonoGame.Extended; -using MonoGame.Extended.Entities.Systems; -using MonoGame.Extended.TextureAtlases; - -namespace JamGame.Systems -{ - public class MapRenderingSystem : DrawSystem - { - private readonly GraphicsDevice _graphicsDevice; - private readonly Tileset _tileset; - private readonly SpriteBatch _spriteBatch; - private readonly FastRandom _random = new FastRandom(); - - private const int _mapWidth = 30; - private const int _mapHeight = 30; - private readonly int[,] _mapData = new int[_mapWidth, _mapHeight]; - - public MapRenderingSystem(GraphicsDevice graphicsDevice, Tileset tileset) - { - _graphicsDevice = graphicsDevice; - _tileset = tileset; - _spriteBatch = new SpriteBatch(graphicsDevice); - - for (var x = 0; x < _mapWidth; x++) - { - for (var y = 0; y < _mapHeight; y++) - _mapData[x, y] = GetTileIndexAt(x, y); - } - } - - private int GetTileIndexAt(int x, int y) - { - if (x < 3 || x > 19) - return -1; - - if (y < 2 || y > 19) - return -1; - - switch (y) - { - case 2: return x == 3 ? 0 : (x == 19 ? 1 : 2); - case 3: return x == 3 ? 16 : (x == 19 ? 18 : 17); - case 4: return _random.Next(32, 34); - default: return 50; - } - } - - public override void Draw(GameTime gameTime) - { - _graphicsDevice.Clear(Color.DarkBlue * 0.2f); - _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(2)); - - for (var x = 0; x < _mapWidth; x++) - { - for (var y = 0; y < _mapHeight; y++) - { - var tileIndex = _mapData[x, y]; - - if (tileIndex >= 0) - { - var tile = _tileset.GetTile(tileIndex); - var position = new Vector2(x * _tileset.TileWidth, y * _tileset.TileHeight); - - _spriteBatch.Draw(tile, position, Color.White); - } - } - } - - _spriteBatch.End(); - } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Systems/PlayerControlSystem.cs b/Source/Demos/JamGame/Systems/PlayerControlSystem.cs deleted file mode 100644 index 7d6b8f71..00000000 --- a/Source/Demos/JamGame/Systems/PlayerControlSystem.cs +++ /dev/null @@ -1,82 +0,0 @@ -using JamGame.Components; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using MonoGame.Extended; -using MonoGame.Extended.Entities; -using MonoGame.Extended.Entities.Systems; -using MonoGame.Extended.Sprites; - -namespace JamGame.Systems -{ - public class PlayerControlSystem : EntityUpdateSystem - { - private readonly MainGame _mainGame; - private readonly EntityFactory _entityFactory; - private ComponentMapper _transformMapper; - private ComponentMapper _spriteMapper; - private const int _playerSpeed = 64; - private KeyboardState _previousKeyboardState; - - private Entity _spawningFireball; - - public PlayerControlSystem(MainGame mainGame, EntityFactory entityFactory) - : base(Aspect.All(typeof(Player), typeof(Transform2), typeof(Sprite))) - { - _mainGame = mainGame; - _entityFactory = entityFactory; - } - - public override void Initialize(IComponentMapperService mapperService) - { - _transformMapper = mapperService.GetMapper(); - _spriteMapper = mapperService.GetMapper(); - } - - public override void Update(GameTime gameTime) - { - var elapsedSeconds = gameTime.GetElapsedSeconds(); - - foreach (var entity in ActiveEntities) - { - var transform = _transformMapper.Get(entity); - var sprite = _spriteMapper.Get(entity); - - if (_mainGame.KeyboardState.IsKeyDown(Keys.Left)) - { - transform.Position += new Vector2(-_playerSpeed, 0) * elapsedSeconds; - sprite.Effect = SpriteEffects.FlipHorizontally; - } - - if (_mainGame.KeyboardState.IsKeyDown(Keys.Right)) - { - transform.Position += new Vector2(_playerSpeed, 0) * elapsedSeconds; - sprite.Effect = SpriteEffects.None; - } - - if (_mainGame.KeyboardState.IsKeyDown(Keys.Up)) - transform.Position += new Vector2(0, -_playerSpeed) * elapsedSeconds; - - if (_mainGame.KeyboardState.IsKeyDown(Keys.Down)) - transform.Position += new Vector2(0, _playerSpeed) * elapsedSeconds; - - if (_previousKeyboardState.IsKeyUp(Keys.Space) && _mainGame.KeyboardState.IsKeyDown(Keys.Space)) - _spawningFireball = _entityFactory.SpawnFireball(transform.Position.X + 16, transform.Position.Y); - - // Kinda hacky but it works for now. - var spawningFireballBody = _spawningFireball?.Get(); - if (spawningFireballBody != null && _previousKeyboardState.IsKeyDown(Keys.Space) && _mainGame.KeyboardState.IsKeyUp(Keys.Space)) - { - spawningFireballBody.Velocity = new Vector2(200, 0); - _spawningFireball = null; - } - - var spawningFireballTransform = _spawningFireball?.Get(); - if(spawningFireballTransform != null) - spawningFireballTransform.Position = new Vector2(transform.Position.X + 16, transform.Position.Y); - } - - _previousKeyboardState = _mainGame.KeyboardState; - } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Systems/SpriteRenderingSystem.cs b/Source/Demos/JamGame/Systems/SpriteRenderingSystem.cs deleted file mode 100644 index 9c30c706..00000000 --- a/Source/Demos/JamGame/Systems/SpriteRenderingSystem.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using MonoGame.Extended; -using MonoGame.Extended.Animations; -using MonoGame.Extended.Entities; -using MonoGame.Extended.Entities.Systems; -using MonoGame.Extended.Sprites; - -namespace JamGame.Systems -{ - public class SpriteRenderingSystem : EntityDrawSystem - { - private readonly SpriteBatch _spriteBatch; - - private ComponentMapper _transformMapper; - private ComponentMapper _spriteMapper; - private ComponentMapper _animatedSpriteMapper; - - public SpriteRenderingSystem(GraphicsDevice graphicsDevice, Texture2D texture) - : base(Aspect.All(typeof(Transform2)).One(typeof(Sprite), typeof(AnimatedSprite))) - { - _spriteBatch = new SpriteBatch(graphicsDevice); - } - - public override void Initialize(IComponentMapperService mapperService) - { - _transformMapper = mapperService.GetMapper(); - _spriteMapper = mapperService.GetMapper(); - _animatedSpriteMapper = mapperService.GetMapper(); - } - - public override void Draw(GameTime gameTime) - { - _spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(2)); - - foreach (var entity in ActiveEntities) - { - var transform = _transformMapper.Get(entity); - var animatedSprite = _animatedSpriteMapper.Get(entity); - var sprite = _spriteMapper.Get(entity); - - animatedSprite?.Update(gameTime); - - _spriteBatch.Draw(sprite ?? animatedSprite, transform); - } - - _spriteBatch.End(); - } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/Tileset.cs b/Source/Demos/JamGame/Tileset.cs deleted file mode 100644 index 8add7038..00000000 --- a/Source/Demos/JamGame/Tileset.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Xna.Framework.Graphics; -using MonoGame.Extended.TextureAtlases; - -namespace JamGame -{ - public class Tileset - { - private readonly int _columns; - private readonly TextureAtlas _atlas; - - public Tileset(Texture2D texture, int tileWidth, int tileHeight) - { - TileWidth = tileWidth; - TileHeight = tileHeight; - - _atlas = TextureAtlas.Create("", texture, tileWidth, tileHeight); - _columns = texture.Width / tileWidth; - } - - public int TileWidth { get; } - public int TileHeight { get; } - - public TextureRegion2D GetTile(int index) - { - if (index < 0 || index >= _atlas.RegionCount) - return null; - - return _atlas[index]; - } - - public TextureRegion2D GetTileAt(int x, int y) - { - if (x >= _columns) - return null; - - var index = y * _columns + x; - - return GetTile(index); - } - } -} \ No newline at end of file diff --git a/Source/Demos/JamGame/app.manifest b/Source/Demos/JamGame/app.manifest deleted file mode 100644 index 0acf5bcd..00000000 --- a/Source/Demos/JamGame/app.manifest +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true/pm - - - - diff --git a/Source/MonoGame.Extended.Animations/MonoGame.Extended.Animations.csproj b/Source/MonoGame.Extended.Animations/MonoGame.Extended.Animations.csproj index 64f02a02..3275006d 100644 --- a/Source/MonoGame.Extended.Animations/MonoGame.Extended.Animations.csproj +++ b/Source/MonoGame.Extended.Animations/MonoGame.Extended.Animations.csproj @@ -9,7 +9,6 @@ monogame animations spritesheet sprite https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Animations/SpriteSheets/SpriteSheetAnimationFactoryReader.cs b/Source/MonoGame.Extended.Animations/SpriteSheets/SpriteSheetAnimationFactoryReader.cs index f0cf722e..f457b525 100644 --- a/Source/MonoGame.Extended.Animations/SpriteSheets/SpriteSheetAnimationFactoryReader.cs +++ b/Source/MonoGame.Extended.Animations/SpriteSheets/SpriteSheetAnimationFactoryReader.cs @@ -1,52 +1,64 @@ -using System.Collections.Generic; -using Microsoft.Xna.Framework.Content; -using MonoGame.Extended.Content; -using MonoGame.Extended.TextureAtlases; +//using System.Collections.Generic; +//using Microsoft.Xna.Framework.Content; +//using MonoGame.Extended.Content; +//using MonoGame.Extended.TextureAtlases; -namespace MonoGame.Extended.Animations.SpriteSheets -{ - //public class SpriteSheetAnimationFactoryReader : ContentTypeReader - //{ - // protected override SpriteSheetAnimationFactory Read(ContentReader reader, SpriteSheetAnimationFactory existingInstance) - // { - // var textureAtlasAssetName = reader.GetRelativeAssetName(reader.ReadString()); - // var textureAtlas = reader.ContentManager.Load(textureAtlasAssetName); - // var frameCount = reader.ReadInt32(); - // var regions = new List(); +//namespace MonoGame.Extended.Animations.SpriteSheets +//{ +//<<<<<<< HEAD +// //public class SpriteSheetAnimationFactoryReader : ContentTypeReader +// //{ +// // protected override SpriteSheetAnimationFactory Read(ContentReader reader, SpriteSheetAnimationFactory existingInstance) +// // { +// // var textureAtlasAssetName = reader.GetRelativeAssetName(reader.ReadString()); +// // var textureAtlas = reader.ContentManager.Load(textureAtlasAssetName); +// // var frameCount = reader.ReadInt32(); +// // var regions = new List(); +//======= +// public class SpriteSheetAnimationFactoryReader : ContentTypeReader +// { +// protected override SpriteSheetAnimationFactory Read(ContentReader reader, SpriteSheetAnimationFactory existingInstance) +// { +// var relativeName = reader.ReadString(); +// var textureAtlasAssetName = reader.GetRelativeAssetName(relativeName); +// var textureAtlas = reader.ContentManager.Load(textureAtlasAssetName); +// var frameCount = reader.ReadInt32(); +// var regions = new List(); +//>>>>>>> develop - // for (var i = 0; i < frameCount; i++) - // { - // var frameName = reader.ReadString(); - // var textureRegion = textureAtlas[frameName]; - // regions.Add(textureRegion); - // } +// // for (var i = 0; i < frameCount; i++) +// // { +// // var frameName = reader.ReadString(); +// // var textureRegion = textureAtlas[frameName]; +// // regions.Add(textureRegion); +// // } - // var animationFactory = new SpriteSheetAnimationFactory(regions); - // var animationCount = reader.ReadInt32(); +// // var animationFactory = new SpriteSheetAnimationFactory(regions); +// // var animationCount = reader.ReadInt32(); - // for (var i = 0; i < animationCount; i++) - // { - // var name = reader.ReadString(); - // var framesPerSecond = reader.ReadInt32(); - // var isLooping = reader.ReadBoolean(); - // var isReversed = reader.ReadBoolean(); - // var isPingPong = reader.ReadBoolean(); - // var frameDuration = 1.0f / framesPerSecond; - // var frameIndexCount = reader.ReadInt32(); - // var frameIndicies = new int[frameIndexCount]; +// // for (var i = 0; i < animationCount; i++) +// // { +// // var name = reader.ReadString(); +// // var framesPerSecond = reader.ReadInt32(); +// // var isLooping = reader.ReadBoolean(); +// // var isReversed = reader.ReadBoolean(); +// // var isPingPong = reader.ReadBoolean(); +// // var frameDuration = 1.0f / framesPerSecond; +// // var frameIndexCount = reader.ReadInt32(); +// // var frameIndicies = new int[frameIndexCount]; - // for (var f = 0; f < frameIndexCount; f++) - // { - // var frameIndex = reader.ReadInt32(); - // frameIndicies[f] = frameIndex; - // } +// // for (var f = 0; f < frameIndexCount; f++) +// // { +// // var frameIndex = reader.ReadInt32(); +// // frameIndicies[f] = frameIndex; +// // } - // var animationData = new SpriteSheetAnimationData(frameIndicies, frameDuration, isLooping, isReversed, - // isPingPong); - // animationFactory.Add(name, animationData); - // } +// // var animationData = new SpriteSheetAnimationData(frameIndicies, frameDuration, isLooping, isReversed, +// // isPingPong); +// // animationFactory.Add(name, animationData); +// // } - // return animationFactory; - // } - //} -} \ No newline at end of file +// // return animationFactory; +// // } +// //} +//} \ No newline at end of file diff --git a/Source/MonoGame.Extended.Collisions/MonoGame.Extended.Collisions.csproj b/Source/MonoGame.Extended.Collisions/MonoGame.Extended.Collisions.csproj index 783db4f4..453366bf 100644 --- a/Source/MonoGame.Extended.Collisions/MonoGame.Extended.Collisions.csproj +++ b/Source/MonoGame.Extended.Collisions/MonoGame.Extended.Collisions.csproj @@ -9,7 +9,6 @@ monogame collisions https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs b/Source/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs index c8e009d3..7d4b9b2f 100644 --- a/Source/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs +++ b/Source/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs @@ -36,20 +36,13 @@ namespace MonoGame.Extended.Collisions /// public override void Update(GameTime gameTime) { - // Update bounding box locations. - foreach (var value in _targetDataDictionary.Values) - { - _collisionTree.Remove(value); - value.Bounds = value.Target.Bounds; - _collisionTree.Insert(value); - } - // Detect collisions foreach (var value in _targetDataDictionary.Values) { + _collisionTree.Remove(value); + var target = value.Target; - var collisions =_collisionTree.Query(target.Bounds) - .Where(data => data.Target != target); + var collisions =_collisionTree.Query(target.Bounds); // Generate list of collision Infos foreach (var other in collisions) @@ -61,7 +54,9 @@ namespace MonoGame.Extended.Collisions }; target.OnCollision(collisionInfo); + value.Bounds = value.Target.Bounds; } + _collisionTree.Insert(value); } } @@ -156,7 +151,10 @@ namespace MonoGame.Extended.Collisions private static Vector2 PenetrationVector(CircleF circ1, CircleF circ2) { - Debug.Assert(circ1.Intersects(circ2)); + if (!circ1.Intersects(circ2)) + { + return Vector2.Zero; + } var displacement = Point2.Displacement(circ1.Center, circ2.Center); diff --git a/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentImporter.cs b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentImporter.cs new file mode 100644 index 00000000..437d7eb1 --- /dev/null +++ b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentImporter.cs @@ -0,0 +1,15 @@ +using System.IO; +using Microsoft.Xna.Framework.Content.Pipeline; + +namespace MonoGame.Extended.Content.Pipeline.Json +{ + [ContentImporter(".json", DefaultProcessor = nameof(JsonContentProcessor), DisplayName = "JSON Importer - MonoGame.Extended")] + public class JsonContentImporter : ContentImporter> + { + public override ContentImporterResult Import(string filename, ContentImporterContext context) + { + var json = File.ReadAllText(filename); + return new ContentImporterResult(filename, json); + } + } +} diff --git a/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessor.cs b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessor.cs new file mode 100644 index 00000000..6be4ac36 --- /dev/null +++ b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessor.cs @@ -0,0 +1,31 @@ +using System; +using System.ComponentModel; +using Microsoft.Xna.Framework.Content.Pipeline; + +namespace MonoGame.Extended.Content.Pipeline.Json +{ + [ContentProcessor(DisplayName = "JSON Processor - MonoGame.Extended")] + public class JsonContentProcessor : ContentProcessor, JsonContentProcessorResult> + { + [DefaultValue(typeof(Type), "System.Object")] + public string ContentType { get; set; } + + public override JsonContentProcessorResult Process(ContentImporterResult input, ContentProcessorContext context) + { + try + { + var output = new JsonContentProcessorResult + { + ContentType = ContentType, + Json = input.Data + }; + return output; + } + catch (Exception ex) + { + context.Logger.LogMessage("Error {0}", ex); + throw; + } + } + } +} \ No newline at end of file diff --git a/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessorResult.cs b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessorResult.cs new file mode 100644 index 00000000..eaef99eb --- /dev/null +++ b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessorResult.cs @@ -0,0 +1,8 @@ +namespace MonoGame.Extended.Content.Pipeline.Json +{ + public class JsonContentProcessorResult + { + public string ContentType { get; set; } + public string Json { get; set; } + } +} \ No newline at end of file diff --git a/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentTypeWriter.cs b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentTypeWriter.cs new file mode 100644 index 00000000..c221922b --- /dev/null +++ b/Source/MonoGame.Extended.Content.Pipeline/Json/JsonContentTypeWriter.cs @@ -0,0 +1,27 @@ +using Microsoft.Xna.Framework.Content.Pipeline; +using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; + +namespace MonoGame.Extended.Content.Pipeline.Json +{ + [ContentTypeWriter] + public class JsonContentTypeWriter : ContentTypeWriter + { + private string _runtimeType; + + protected override void Write(ContentWriter writer, JsonContentProcessorResult result) + { + _runtimeType = result.ContentType; + writer.Write(result.Json); + } + + public override string GetRuntimeReader(TargetPlatform targetPlatform) + { + return _runtimeType;// "MonoGame.Extended.Serialization.JsonContentTypeReader, MonoGame.Extended"; + } + + public override string GetRuntimeType(TargetPlatform targetPlatform) + { + return _runtimeType;// "MonoGame.Extended.Serialization.JsonContentTypeReader, MonoGame.Extended"; + } + } +} \ No newline at end of file diff --git a/Source/MonoGame.Extended.Content.Pipeline/MonoGame.Extended.Content.Pipeline.csproj b/Source/MonoGame.Extended.Content.Pipeline/MonoGame.Extended.Content.Pipeline.csproj index 8cd82a96..ef460b63 100644 --- a/Source/MonoGame.Extended.Content.Pipeline/MonoGame.Extended.Content.Pipeline.csproj +++ b/Source/MonoGame.Extended.Content.Pipeline/MonoGame.Extended.Content.Pipeline.csproj @@ -1,15 +1,19 @@  netstandard2.0 + True + + + + craftworkgames Content Pipeline importers and processors to make MonoGame more awesome. monogame content importer processor reader tiled texturepacker bmfont animations https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Entities/MonoGame.Extended.Entities.csproj b/Source/MonoGame.Extended.Entities/MonoGame.Extended.Entities.csproj index 9745826b..b17e06f7 100644 --- a/Source/MonoGame.Extended.Entities/MonoGame.Extended.Entities.csproj +++ b/Source/MonoGame.Extended.Entities/MonoGame.Extended.Entities.csproj @@ -9,7 +9,6 @@ monogame ecs entity component system https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Entities/World.cs b/Source/MonoGame.Extended.Entities/World.cs index a4f34d47..022d4b8c 100644 --- a/Source/MonoGame.Extended.Entities/World.cs +++ b/Source/MonoGame.Extended.Entities/World.cs @@ -26,6 +26,9 @@ namespace MonoGame.Extended.Entities foreach (var drawSystem in _drawSystems) drawSystem.Dispose(); + _updateSystems.Clear(); + _drawSystems.Clear(); + base.Dispose(); } diff --git a/Source/MonoGame.Extended.Graphics/MonoGame.Extended.Graphics.csproj b/Source/MonoGame.Extended.Graphics/MonoGame.Extended.Graphics.csproj index d5173b43..694f63d1 100644 --- a/Source/MonoGame.Extended.Graphics/MonoGame.Extended.Graphics.csproj +++ b/Source/MonoGame.Extended.Graphics/MonoGame.Extended.Graphics.csproj @@ -9,7 +9,6 @@ monogame graphics batcher effects https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Gui/MonoGame.Extended.Gui.csproj b/Source/MonoGame.Extended.Gui/MonoGame.Extended.Gui.csproj index ba408280..2741cea3 100644 --- a/Source/MonoGame.Extended.Gui/MonoGame.Extended.Gui.csproj +++ b/Source/MonoGame.Extended.Gui/MonoGame.Extended.Gui.csproj @@ -9,7 +9,6 @@ monogame gui https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Input/InputListeners/KeyboardListener.cs b/Source/MonoGame.Extended.Input/InputListeners/KeyboardListener.cs index ceb225e3..9fc85a0f 100644 --- a/Source/MonoGame.Extended.Input/InputListeners/KeyboardListener.cs +++ b/Source/MonoGame.Extended.Input/InputListeners/KeyboardListener.cs @@ -7,6 +7,8 @@ namespace MonoGame.Extended.Input.InputListeners { public class KeyboardListener : InputListener { + private Array _keysValues = Enum.GetValues(typeof(Keys)); + private bool _isInitial; private TimeSpan _lastPressTime; @@ -50,7 +52,7 @@ namespace MonoGame.Extended.Input.InputListeners { if (!currentState.IsKeyDown(Keys.LeftAlt) && !currentState.IsKeyDown(Keys.RightAlt)) { - var pressedKeys = Enum.GetValues(typeof(Keys)) + var pressedKeys = _keysValues .Cast() .Where(key => currentState.IsKeyDown(key) && _previousState.IsKeyUp(key)); @@ -72,7 +74,7 @@ namespace MonoGame.Extended.Input.InputListeners private void RaiseReleasedEvents(KeyboardState currentState) { - var releasedKeys = Enum.GetValues(typeof(Keys)) + var releasedKeys = _keysValues .Cast() .Where(key => currentState.IsKeyUp(key) && _previousState.IsKeyDown(key)); @@ -99,4 +101,4 @@ namespace MonoGame.Extended.Input.InputListeners } } } -} \ No newline at end of file +} diff --git a/Source/MonoGame.Extended.Input/MonoGame.Extended.Input.csproj b/Source/MonoGame.Extended.Input/MonoGame.Extended.Input.csproj index 2c87b097..f1d90971 100644 --- a/Source/MonoGame.Extended.Input/MonoGame.Extended.Input.csproj +++ b/Source/MonoGame.Extended.Input/MonoGame.Extended.Input.csproj @@ -9,7 +9,6 @@ monogame input event based listeners https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.NuclexGui/MonoGame.Extended.NuclexGui.csproj b/Source/MonoGame.Extended.NuclexGui/MonoGame.Extended.NuclexGui.csproj index 6dfc8e02..7ce0767e 100644 --- a/Source/MonoGame.Extended.NuclexGui/MonoGame.Extended.NuclexGui.csproj +++ b/Source/MonoGame.Extended.NuclexGui/MonoGame.Extended.NuclexGui.csproj @@ -9,7 +9,6 @@ monogame nuclex gui https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Particles/MonoGame.Extended.Particles.csproj b/Source/MonoGame.Extended.Particles/MonoGame.Extended.Particles.csproj index 0f8952b8..d2ceec67 100644 --- a/Source/MonoGame.Extended.Particles/MonoGame.Extended.Particles.csproj +++ b/Source/MonoGame.Extended.Particles/MonoGame.Extended.Particles.csproj @@ -9,7 +9,6 @@ monogame particle system https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.SceneGraphs/MonoGame.Extended.SceneGraphs.csproj b/Source/MonoGame.Extended.SceneGraphs/MonoGame.Extended.SceneGraphs.csproj index dcc3bd78..37bed689 100644 --- a/Source/MonoGame.Extended.SceneGraphs/MonoGame.Extended.SceneGraphs.csproj +++ b/Source/MonoGame.Extended.SceneGraphs/MonoGame.Extended.SceneGraphs.csproj @@ -9,7 +9,6 @@ monogame scene graph node entity https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Tiled/MonoGame.Extended.Tiled.csproj b/Source/MonoGame.Extended.Tiled/MonoGame.Extended.Tiled.csproj index 371ee4d0..67c1e74c 100644 --- a/Source/MonoGame.Extended.Tiled/MonoGame.Extended.Tiled.csproj +++ b/Source/MonoGame.Extended.Tiled/MonoGame.Extended.Tiled.csproj @@ -9,7 +9,6 @@ monogame tiled maps orthographic isometric https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.Tiled/TiledMap.cs b/Source/MonoGame.Extended.Tiled/TiledMap.cs index e2328b7c..d9b1d14b 100644 --- a/Source/MonoGame.Extended.Tiled/TiledMap.cs +++ b/Source/MonoGame.Extended.Tiled/TiledMap.cs @@ -69,6 +69,10 @@ namespace MonoGame.Extended.Tiled private void AddLayer(TiledMapLayer layer, bool root) { if (root) _layers.Add(layer); + + if (_layersByName.ContainsKey(layer.Name)) + throw new ArgumentException($"The TiledMap '{Name}' contains two or more layers named '{layer.Name}'. Please ensure all layers have unique names."); + _layersByName.Add(layer.Name, layer); switch(layer) diff --git a/Source/MonoGame.Extended.Tweening/MonoGame.Extended.Tweening.csproj b/Source/MonoGame.Extended.Tweening/MonoGame.Extended.Tweening.csproj index 32dc7a8d..31cb9f88 100644 --- a/Source/MonoGame.Extended.Tweening/MonoGame.Extended.Tweening.csproj +++ b/Source/MonoGame.Extended.Tweening/MonoGame.Extended.Tweening.csproj @@ -9,7 +9,6 @@ monogame animations tweening https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended.sln b/Source/MonoGame.Extended.sln index 53d8e3dd..9672d16e 100644 --- a/Source/MonoGame.Extended.sln +++ b/Source/MonoGame.Extended.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2010 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.156 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGame.Extended", "MonoGame.Extended\MonoGame.Extended.csproj", "{41724C52-3D50-45BB-81EB-3C8A247EAFD1}" EndProject @@ -92,8 +92,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpaceGame", "Demos\SpaceGam EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StarWarrior", "Demos\StarWarrior\StarWarrior.csproj", "{B8D1B045-627E-4587-8CE0-6D5556A2B706}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JamGame", "Demos\JamGame\JamGame.csproj", "{DA792AA2-8905-46A0-A7B8-76A84FA41BA8}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -342,14 +340,6 @@ Global {B8D1B045-627E-4587-8CE0-6D5556A2B706}.Release|Any CPU.Build.0 = Release|Any CPU {B8D1B045-627E-4587-8CE0-6D5556A2B706}.Release|x86.ActiveCfg = Release|Any CPU {B8D1B045-627E-4587-8CE0-6D5556A2B706}.Release|x86.Build.0 = Release|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Debug|x86.ActiveCfg = Debug|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Debug|x86.Build.0 = Debug|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Release|Any CPU.Build.0 = Release|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Release|x86.ActiveCfg = Release|Any CPU - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -372,7 +362,6 @@ Global {EC27F5D2-30A3-40BC-A81F-CACC58CE6C6C} = {932F8931-4A8D-4205-BFCF-98E794207786} {6238F2A3-ABAE-4D9B-99BF-B195FBA49159} = {932F8931-4A8D-4205-BFCF-98E794207786} {B8D1B045-627E-4587-8CE0-6D5556A2B706} = {932F8931-4A8D-4205-BFCF-98E794207786} - {DA792AA2-8905-46A0-A7B8-76A84FA41BA8} = {932F8931-4A8D-4205-BFCF-98E794207786} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8ED5A62D-25EC-4331-9F99-BDD1E10C02A0} diff --git a/Source/MonoGame.Extended/Collections/Bag.cs b/Source/MonoGame.Extended/Collections/Bag.cs index cfa59689..292c1d19 100644 --- a/Source/MonoGame.Extended/Collections/Bag.cs +++ b/Source/MonoGame.Extended/Collections/Bag.cs @@ -85,11 +85,11 @@ namespace MonoGame.Extended.Collections if(Count == 0) return; - Count = 0; - // non-primitive types are cleared so the garbage collector can release them if (!_isPrimitive) Array.Clear(_items, 0, Count); + + Count = 0; } public bool Contains(T element) @@ -191,4 +191,4 @@ namespace MonoGame.Extended.Collections } } } -} \ No newline at end of file +} diff --git a/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs b/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs index ef33841f..f4c51a4f 100644 --- a/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs +++ b/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs @@ -15,10 +15,15 @@ namespace MonoGame.Extended.Content return (GraphicsDevice)_contentReaderGraphicsDeviceFieldInfo.GetValue(contentReader); } + public static string RemoveExtension(string path) + { + return Path.ChangeExtension(path, null).TrimEnd('.'); + } + public static string GetRelativeAssetName(this ContentReader contentReader, string relativeName) { var assetDirectory = Path.GetDirectoryName(contentReader.AssetName); - var assetName = Path.Combine(assetDirectory, relativeName).Replace('\\', '/'); + var assetName = RemoveExtension(Path.Combine(assetDirectory, relativeName).Replace('\\', '/')); return ShortenRelativePath(assetName); } diff --git a/Source/MonoGame.Extended/Math/ShapeExtensions.cs b/Source/MonoGame.Extended/Math/ShapeExtensions.cs index 51ea932e..5424ada8 100644 --- a/Source/MonoGame.Extended/Math/ShapeExtensions.cs +++ b/Source/MonoGame.Extended/Math/ShapeExtensions.cs @@ -18,7 +18,12 @@ namespace MonoGame.Extended if (_whitePixelTexture == null) { _whitePixelTexture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); - _whitePixelTexture.SetData(new[] {Color.White}); + _whitePixelTexture.SetData(new[] { Color.White }); + spriteBatch.Disposing += (sender, args) => + { + _whitePixelTexture?.Dispose(); + _whitePixelTexture = null; + }; } return _whitePixelTexture; @@ -33,10 +38,10 @@ namespace MonoGame.Extended /// The polygon to draw /// The color to use /// The thickness of the lines - public static void DrawPolygon(this SpriteBatch spriteBatch, Vector2 position, Polygon polygon, Color color, - float thickness = 1f) + /// /// The depth of the layer of this shape + public static void DrawPolygon(this SpriteBatch spriteBatch, Vector2 position, Polygon polygon, Color color, float thickness = 1f, int layerDepth = 0) { - DrawPolygon(spriteBatch, position, polygon.Vertices, color, thickness); + DrawPolygon(spriteBatch, position, polygon.Vertices, color, thickness, layerDepth); } /// @@ -48,61 +53,61 @@ namespace MonoGame.Extended /// The points to connect with lines /// The color to use /// The thickness of the lines - public static void DrawPolygon(this SpriteBatch spriteBatch, Vector2 offset, IReadOnlyList points, Color color, - float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawPolygon(this SpriteBatch spriteBatch, Vector2 offset, IReadOnlyList points, Color color, float thickness = 1f, int layerDepth = 0) { if (points.Count == 0) return; if (points.Count == 1) { - DrawPoint(spriteBatch, points[0], color, (int) thickness); + DrawPoint(spriteBatch, points[0], color, (int)thickness); return; } var texture = GetTexture(spriteBatch); for (var i = 0; i < points.Count - 1; i++) - DrawPolygonEdge(spriteBatch, texture, points[i] + offset, points[i + 1] + offset, color, thickness); + DrawPolygonEdge(spriteBatch, texture, points[i] + offset, points[i + 1] + offset, color, thickness, layerDepth); - DrawPolygonEdge(spriteBatch, texture, points[points.Count - 1] + offset, points[0] + offset, color, - thickness); + DrawPolygonEdge(spriteBatch, texture, points[points.Count - 1] + offset, points[0] + offset, color, thickness, layerDepth); } - private static void DrawPolygonEdge(SpriteBatch spriteBatch, Texture2D texture, Vector2 point1, Vector2 point2, - Color color, float thickness) + private static void DrawPolygonEdge(SpriteBatch spriteBatch, Texture2D texture, Vector2 point1, Vector2 point2, Color color, float thickness, int layerDepth) { var length = Vector2.Distance(point1, point2); - var angle = (float) Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); + var angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); var scale = new Vector2(length, thickness); - spriteBatch.Draw(texture, point1, null, color, angle, Vector2.Zero, scale, SpriteEffects.None, 0); + spriteBatch.Draw(texture, point1, null, color, angle, Vector2.Zero, scale, SpriteEffects.None, layerDepth); } /// - /// Draws a filled rectangle + /// Draws a filled rectangle /// /// The destination drawing surface /// The rectangle to draw /// The color to draw the rectangle in - public static void FillRectangle(this SpriteBatch spriteBatch, RectangleF rectangle, Color color) + /// The depth of the layer of this shape + public static void FillRectangle(this SpriteBatch spriteBatch, RectangleF rectangle, Color color, int layerDepth = 0) { - FillRectangle(spriteBatch, rectangle.Position, rectangle.Size, color); + FillRectangle(spriteBatch, rectangle.Position, rectangle.Size, color, layerDepth); } /// - /// Draws a filled rectangle + /// Draws a filled rectangle /// /// The destination drawing surface /// Where to draw /// The size of the rectangle /// The color to draw the rectangle in - public static void FillRectangle(this SpriteBatch spriteBatch, Vector2 location, Size2 size, Color color) + /// The depth of the layer of this shape + public static void FillRectangle(this SpriteBatch spriteBatch, Vector2 location, Size2 size, Color color, int layerDepth = 0) { - spriteBatch.Draw(GetTexture(spriteBatch), location, null, color, 0, Vector2.Zero, size, SpriteEffects.None, 0); + spriteBatch.Draw(GetTexture(spriteBatch), location, null, color, 0, Vector2.Zero, size, SpriteEffects.None, layerDepth); } /// - /// Draws a filled rectangle + /// Draws a filled rectangle /// /// The destination drawing surface /// The X coord of the left side @@ -110,19 +115,21 @@ namespace MonoGame.Extended /// Width /// Height /// The color to draw the rectangle in - public static void FillRectangle(this SpriteBatch spriteBatch, float x, float y, float width, float height, Color color) + /// The depth of the layer of this shape + public static void FillRectangle(this SpriteBatch spriteBatch, float x, float y, float width, float height, Color color, int layerDepth = 0) { - FillRectangle(spriteBatch, new Vector2(x, y), new Size2(width, height), color); + FillRectangle(spriteBatch, new Vector2(x, y), new Size2(width, height), color, layerDepth); } /// - /// Draws a rectangle with the thickness provided + /// Draws a rectangle with the thickness provided /// /// The destination drawing surface /// The rectangle to draw /// The color to draw the rectangle in /// The thickness of the lines - public static void DrawRectangle(this SpriteBatch spriteBatch, RectangleF rectangle, Color color, float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawRectangle(this SpriteBatch spriteBatch, RectangleF rectangle, Color color, float thickness = 1f, int layerDepth = 0) { var texture = GetTexture(spriteBatch); var topLeft = new Vector2(rectangle.X, rectangle.Y); @@ -131,10 +138,10 @@ namespace MonoGame.Extended var horizontalScale = new Vector2(rectangle.Width, thickness); var verticalScale = new Vector2(thickness, rectangle.Height); - spriteBatch.Draw(texture, topLeft, null, color, 0f, Vector2.Zero, horizontalScale, SpriteEffects.None, 0); - spriteBatch.Draw(texture, topLeft, null, color, 0f, Vector2.Zero, verticalScale, SpriteEffects.None, 0); - spriteBatch.Draw(texture, topRight, null, color, 0f, Vector2.Zero, verticalScale, SpriteEffects.None, 0); - spriteBatch.Draw(texture, bottomLeft, null, color, 0f, Vector2.Zero, horizontalScale, SpriteEffects.None, 0); + spriteBatch.Draw(texture, topLeft, null, color, 0f, Vector2.Zero, horizontalScale, SpriteEffects.None, layerDepth); + spriteBatch.Draw(texture, topLeft, null, color, 0f, Vector2.Zero, verticalScale, SpriteEffects.None, layerDepth); + spriteBatch.Draw(texture, topRight, null, color, 0f, Vector2.Zero, verticalScale, SpriteEffects.None, layerDepth); + spriteBatch.Draw(texture, bottomLeft, null, color, 0f, Vector2.Zero, horizontalScale, SpriteEffects.None, layerDepth); } /// @@ -145,23 +152,23 @@ namespace MonoGame.Extended /// The size of the rectangle /// The color to draw the rectangle in /// The thickness of the line - public static void DrawRectangle(this SpriteBatch spriteBatch, Vector2 location, Size2 size, Color color, - float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawRectangle(this SpriteBatch spriteBatch, Vector2 location, Size2 size, Color color, float thickness = 1f, int layerDepth = 0) { - DrawRectangle(spriteBatch, new RectangleF(location.X, location.Y, size.Width, size.Height), color, thickness); + DrawRectangle(spriteBatch, new RectangleF(location.X, location.Y, size.Width, size.Height), color, thickness, layerDepth); } /// /// Draws a rectangle outline. /// - public static void DrawRectangle(this SpriteBatch spriteBatch, float x, float y, float width, float height, Color color, float thickness = 1f) + public static void DrawRectangle(this SpriteBatch spriteBatch, float x, float y, float width, float height, Color color, float thickness = 1f, int layerDepth = 0) { - DrawRectangle(spriteBatch, new RectangleF(x, y, width, height), color, thickness); + DrawRectangle(spriteBatch, new RectangleF(x, y, width, height), color, thickness, layerDepth); } /// - /// Draws a line from point1 to point2 with an offset + /// Draws a line from point1 to point2 with an offset /// /// The destination drawing surface /// The X coord of the first point @@ -170,34 +177,34 @@ namespace MonoGame.Extended /// The Y coord of the second point /// The color to use /// The thickness of the line - public static void DrawLine(this SpriteBatch spriteBatch, float x1, float y1, float x2, float y2, Color color, - float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawLine(this SpriteBatch spriteBatch, float x1, float y1, float x2, float y2, Color color, float thickness = 1f, int layerDepth = 0) { - DrawLine(spriteBatch, new Vector2(x1, y1), new Vector2(x2, y2), color, thickness); + DrawLine(spriteBatch, new Vector2(x1, y1), new Vector2(x2, y2), color, thickness, layerDepth); } /// - /// Draws a line from point1 to point2 with an offset + /// Draws a line from point1 to point2 with an offset /// /// The destination drawing surface /// The first point /// The second point /// The color to use /// The thickness of the line - public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point1, Vector2 point2, Color color, - float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point1, Vector2 point2, Color color, float thickness = 1f, int layerDepth = 0) { // calculate the distance between the two vectors var distance = Vector2.Distance(point1, point2); // calculate the angle between the two vectors - var angle = (float) Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); + var angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); - DrawLine(spriteBatch, point1, distance, angle, color, thickness); + DrawLine(spriteBatch, point1, distance, angle, color, thickness, layerDepth); } /// - /// Draws a line from point1 to point2 with an offset + /// Draws a line from point1 to point2 with an offset /// /// The destination drawing surface /// The starting point @@ -205,48 +212,48 @@ namespace MonoGame.Extended /// The angle of this line from the starting point /// The color to use /// The thickness of the line - public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point, float length, float angle, Color color, - float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point, float length, float angle, Color color, float thickness = 1f, int layerDepth = 0) { var origin = new Vector2(0f, 0.5f); var scale = new Vector2(length, thickness); - spriteBatch.Draw(GetTexture(spriteBatch), point, null, color, angle, origin, scale, SpriteEffects.None, 0); + spriteBatch.Draw(GetTexture(spriteBatch), point, null, color, angle, origin, scale, SpriteEffects.None, layerDepth); } /// - /// Draws a point at the specified x, y position. The center of the point will be at the position. + /// Draws a point at the specified x, y position. The center of the point will be at the position. /// - public static void DrawPoint(this SpriteBatch spriteBatch, float x, float y, Color color, float size = 1f) + public static void DrawPoint(this SpriteBatch spriteBatch, float x, float y, Color color, float size = 1f, int layerDepth = 0) { - DrawPoint(spriteBatch, new Vector2(x, y), color, size); + DrawPoint(spriteBatch, new Vector2(x, y), color, size, layerDepth); } /// - /// Draws a point at the specified position. The center of the point will be at the position. + /// Draws a point at the specified position. The center of the point will be at the position. /// - public static void DrawPoint(this SpriteBatch spriteBatch, Vector2 position, Color color, float size = 1f) + public static void DrawPoint(this SpriteBatch spriteBatch, Vector2 position, Color color, float size = 1f, int layerDepth = 0) { - var scale = Vector2.One*size; - var offset = new Vector2(0.5f) - new Vector2(size*0.5f); - spriteBatch.Draw(GetTexture(spriteBatch), position + offset, null, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0); + var scale = Vector2.One * size; + var offset = new Vector2(0.5f) - new Vector2(size * 0.5f); + spriteBatch.Draw(GetTexture(spriteBatch), position + offset, null, color, 0f, Vector2.Zero, scale, SpriteEffects.None, layerDepth); } /// - /// Draw a circle from a shape + /// Draw a circle from a shape /// /// The destination drawing surface /// The circle shape to draw /// The number of sides to generate /// The color of the circle /// The thickness of the lines used - public static void DrawCircle(this SpriteBatch spriteBatch, CircleF circle, int sides, Color color, - float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawCircle(this SpriteBatch spriteBatch, CircleF circle, int sides, Color color, float thickness = 1f, int layerDepth = 0) { - DrawCircle(spriteBatch, circle.Center, circle.Radius, sides, color, thickness); + DrawCircle(spriteBatch, circle.Center, circle.Radius, sides, color, thickness, layerDepth); } /// - /// Draw a circle + /// Draw a circle /// /// The destination drawing surface /// The center of the circle @@ -254,14 +261,14 @@ namespace MonoGame.Extended /// The number of sides to generate /// The color of the circle /// The thickness of the lines used - public static void DrawCircle(this SpriteBatch spriteBatch, Vector2 center, float radius, int sides, Color color, - float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawCircle(this SpriteBatch spriteBatch, Vector2 center, float radius, int sides, Color color, float thickness = 1f, int layerDepth = 0) { - DrawPolygon(spriteBatch, center, CreateCircle(radius, sides), color, thickness); + DrawPolygon(spriteBatch, center, CreateCircle(radius, sides), color, thickness, layerDepth); } /// - /// Draw a circle + /// Draw a circle /// /// The destination drawing surface /// The center X of the circle @@ -270,26 +277,56 @@ namespace MonoGame.Extended /// The number of sides to generate /// The color of the circle /// The thickness of the line - public static void DrawCircle(this SpriteBatch spriteBatch, float x, float y, float radius, int sides, - Color color, float thickness = 1f) + /// The depth of the layer of this shape + public static void DrawCircle(this SpriteBatch spriteBatch, float x, float y, float radius, int sides, Color color, float thickness = 1f, int layerDepth = 0) { - DrawPolygon(spriteBatch, new Vector2(x, y), CreateCircle(radius, sides), color, thickness); + DrawPolygon(spriteBatch, new Vector2(x, y), CreateCircle(radius, sides), color, thickness, layerDepth); + } + + /// + /// Draw an ellipse. + /// + /// The destination drawing surface + /// Center of the ellipse + /// Radius of the ellipse + /// The number of sides to generate. + /// The color of the ellipse. + /// The thickness of the line around the ellipse. + /// The depth of the layer of this shape + public static void DrawEllipse(this SpriteBatch spriteBatch, Vector2 center, Vector2 radius, int sides, Color color, float thickness = 1f, int layerDepth = 0) + { + DrawPolygon(spriteBatch, center, CreateEllipse(radius.X, radius.Y, sides), color, thickness, layerDepth); } private static Vector2[] CreateCircle(double radius, int sides) { - const double max = 2.0*Math.PI; + const double max = 2.0 * Math.PI; var points = new Vector2[sides]; - var step = max/sides; + var step = max / sides; var theta = 0.0; for (var i = 0; i < sides; i++) { - points[i] = new Vector2((float) (radius*Math.Cos(theta)), (float) (radius*Math.Sin(theta))); + points[i] = new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta))); theta += step; } return points; } + + private static Vector2[] CreateEllipse(float rx, float ry, int sides) + { + var vertices = new Vector2[sides]; + + var t = 0.0; + var dt = 2.0 * Math.PI / sides; + for (var i = 0; i < sides; i++, t += dt) + { + var x = (float)(rx * Math.Cos(t)); + var y = (float)(ry * Math.Sin(t)); + vertices[i] = new Vector2(x, y); + } + return vertices; + } } } \ No newline at end of file diff --git a/Source/MonoGame.Extended/MonoGame.Extended.csproj b/Source/MonoGame.Extended/MonoGame.Extended.csproj index 43869a01..da2097ab 100644 --- a/Source/MonoGame.Extended/MonoGame.Extended.csproj +++ b/Source/MonoGame.Extended/MonoGame.Extended.csproj @@ -9,7 +9,6 @@ monogame extended pipeline bmfont tiled texture atlas input viewport fps shapes sprite https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended - https://github.com/craftworkgames/MonoGame.Extended/blob/master/LICENSE https://raw.githubusercontent.com/craftworkgames/MonoGame.Extended/master/Logos/logo-nuget-128.png diff --git a/Source/MonoGame.Extended/Serialization/JsonContentTypeReader.cs b/Source/MonoGame.Extended/Serialization/JsonContentTypeReader.cs new file mode 100644 index 00000000..c97829b9 --- /dev/null +++ b/Source/MonoGame.Extended/Serialization/JsonContentTypeReader.cs @@ -0,0 +1,121 @@ +using System; +using System.IO; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using MonoGame.Extended.Content; +using MonoGame.Extended.TextureAtlases; +using Newtonsoft.Json; + +namespace MonoGame.Extended.Serialization +{ + public class JsonContentTypeReader : ContentTypeReader + { + protected override T Read(ContentReader reader, T existingInstance) + { + var json = reader.ReadString(); + + using (var stringReader = new StringReader(json)) + using (var jsonReader = new JsonTextReader(stringReader)) + { + var serializer = new JsonSerializer(); + return serializer.Deserialize(jsonReader); + } + } + } + + public class TextureAtlasJsonContentTypeReader : JsonContentTypeReader + { + private TexturePackerFile Load(ContentReader reader) + { + var json = reader.ReadString(); + + using (var stringReader = new StringReader(json)) + using (var jsonReader = new JsonTextReader(stringReader)) + { + var serializer = new JsonSerializer(); + return serializer.Deserialize(jsonReader); + } + } + + protected override TextureAtlas Read(ContentReader reader, TextureAtlas existingInstance) + { + var texturePackerFile = Load(reader); + var assetName = reader.GetRelativeAssetName(texturePackerFile.Metadata.Image); + var texture = reader.ContentManager.Load(assetName); + var atlas = new TextureAtlas(assetName, texture); + + var regionCount = texturePackerFile.Regions.Count; + + for (var i = 0; i < regionCount; i++) + { + atlas.CreateRegion( + ContentReaderExtensions.RemoveExtension(texturePackerFile.Regions[i].Filename), + texturePackerFile.Regions[i].Frame.X, + texturePackerFile.Regions[i].Frame.Y, + texturePackerFile.Regions[i].Frame.Width, + texturePackerFile.Regions[i].Frame.Height); + } + + return atlas; + } + } + + //public abstract class JsonContentTypeReader : ContentTypeReader + //{ + // protected abstract TOutput OnDeserialize(ContentReader reader, TInput texturePackerFile); + + // protected override TOutput Read(ContentReader reader, TOutput existingInstance) + // { + // var json = reader.ReadString(); + + // using (var stringReader = new StringReader(json)) + // using (var jsonReader = new JsonTextReader(stringReader)) + // { + // var serializer = new JsonSerializer(); + // var input = serializer.Deserialize(jsonReader); + // return OnDeserialize(reader, input); + // } + // } + //} + + //public class JsonContentTypeReader : ContentTypeReader + //{ + // public JsonContentTypeReader(string blah) : base(typeof(object)) + // { + // } + + // protected override void Initialize(ContentTypeReaderManager manager) + // { + // base.Initialize(manager); + // } + + // protected override object Read(ContentReader input, object existingInstance) + // { + // return null; + // } + //} + + //public class TexturePackerJsonContentTypeReader : JsonContentTypeReader + //{ + // protected override TextureAtlas OnDeserialize(ContentReader reader, TexturePackerFile texturePackerFile) + // { + // var assetName = reader.GetRelativeAssetName(texturePackerFile.Metadata.Image); + // var texture = reader.ContentManager.Load(assetName); + // var atlas = new TextureAtlas(assetName, texture); + + // var regionCount = texturePackerFile.Regions.Count; + + // for (var i = 0; i < regionCount; i++) + // { + // atlas.CreateRegion( + // ContentReaderExtensions.RemoveExtension(texturePackerFile.Regions[i].Filename), + // texturePackerFile.Regions[i].Frame.X, + // texturePackerFile.Regions[i].Frame.Y, + // texturePackerFile.Regions[i].Frame.Width, + // texturePackerFile.Regions[i].Frame.Height); + // } + + // return atlas; + // } + //} +} \ No newline at end of file diff --git a/Source/MonoGame.Extended/TextureAtlases/TexturePackerFile.cs b/Source/MonoGame.Extended/TextureAtlases/TexturePackerFile.cs index 72b80f3a..69935842 100644 --- a/Source/MonoGame.Extended/TextureAtlases/TexturePackerFile.cs +++ b/Source/MonoGame.Extended/TextureAtlases/TexturePackerFile.cs @@ -11,20 +11,4 @@ namespace MonoGame.Extended.TextureAtlases [JsonProperty("meta")] public TexturePackerMeta Metadata { get; set; } } - - //public class TexturePackerToTextureAtlasConverter - //{ - // public TextureAtlas Convert(TexturePackerFile texturePackerFile) - // { - // var name = texturePackerFile.Metadata.Image; - // var textureAtlas = new TextureAtlas(name, texture); - - // foreach (var region in texturePackerFile.Regions) - // { - // textureAtlas.CreateRegion(region.Filename, region.Frame.X, region.Frame.Y, region.Frame.Width, region.Frame.Height); - // } - - // return textureAtlas; - // } - //} } \ No newline at end of file diff --git a/Source/MonoGame.Extended/TextureAtlases/TexturePackerRegion.cs b/Source/MonoGame.Extended/TextureAtlases/TexturePackerRegion.cs index 4d12c8d1..b38d4ebb 100644 --- a/Source/MonoGame.Extended/TextureAtlases/TexturePackerRegion.cs +++ b/Source/MonoGame.Extended/TextureAtlases/TexturePackerRegion.cs @@ -27,7 +27,7 @@ namespace MonoGame.Extended.TextureAtlases public override string ToString() { - return string.Format("{0} {1}", Filename, Frame); + return $"{Filename} {Frame}"; } } } \ No newline at end of file diff --git a/Source/MonoGame.Extended/Transform.cs b/Source/MonoGame.Extended/Transform.cs index c178883a..53e81848 100644 --- a/Source/MonoGame.Extended/Transform.cs +++ b/Source/MonoGame.Extended/Transform.cs @@ -323,4 +323,134 @@ namespace MonoGame.Extended return $"Position: {Position}, Rotation: {Rotation}, Scale: {Scale}"; } } + + + /// + /// Represents the position, rotation, and scale of a three-dimensional game object. + /// + /// + /// + /// + /// Every game object has a transform which is used to store and manipulate the position, rotation and scale + /// of the object. Every transform can have a parent, which allows to apply position, rotation and scale to game + /// objects hierarchically. + /// + /// + class Transform3 : BaseTransform { + private Vector3 _position; + private Quaternion _rotation; + private Vector3 _scale = Vector3.One; + + public Transform3(Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null) { + Position = position ?? Vector3.Zero; + Rotation = rotation ?? Quaternion.Identity; + Scale = scale ?? Vector3.One; + } + + /// + /// Gets the world position. + /// + /// + /// The world position. + /// + public Vector3 WorldPosition => WorldMatrix.Translation; + + /// + /// Gets the world scale. + /// + /// + /// The world scale. + /// + public Vector3 WorldScale { + get { + Vector3 scale = Vector3.Zero; + Quaternion rotation = Quaternion.Identity; + Vector3 translation = Vector3.Zero; + WorldMatrix.Decompose(out scale, out rotation, out translation); + return scale; + } + } + + + /// + /// Gets the world rotation quaternion in radians. + /// + /// + /// The world rotation quaternion in radians. + /// + public Quaternion WorldRotation { + get { + Vector3 scale = Vector3.Zero; + Quaternion rotation = Quaternion.Identity; + Vector3 translation = Vector3.Zero; + WorldMatrix.Decompose(out scale, out rotation, out translation); + return rotation; + } + } + + /// + /// Gets or sets the local position. + /// + /// + /// The local position. + /// + public Vector3 Position { + get { return _position; } + set { + _position = value; + LocalMatrixBecameDirty(); + WorldMatrixBecameDirty(); + } + } + + /// + /// Gets or sets the local rotation quaternion in radians. + /// + /// + /// The local rotation quaternion in radians. + /// + public Quaternion Rotation { + get { return _rotation; } + set { + _rotation = value; + LocalMatrixBecameDirty(); + WorldMatrixBecameDirty(); + } + } + + /// + /// Gets or sets the local scale. + /// + /// + /// The local scale. + /// + public Vector3 Scale { + get { return _scale; } + set { + _scale = value; + LocalMatrixBecameDirty(); + WorldMatrixBecameDirty(); + } + } + + protected internal override void RecalculateWorldMatrix(ref Matrix localMatrix, out Matrix matrix) { + if (Parent != null) { + Parent.GetWorldMatrix(out matrix); + Matrix.Multiply(ref localMatrix, ref matrix, out matrix); + } + else { + matrix = localMatrix; + } + } + + protected internal override void RecalculateLocalMatrix(out Matrix matrix) { + matrix = Matrix.CreateScale(_scale) * + Matrix.CreateFromQuaternion(_rotation) * + Matrix.CreateTranslation(_position); + } + + public override string ToString() { + return $"Position: {Position}, Rotation: {Rotation}, Scale: {Scale}"; + } + } } \ No newline at end of file diff --git a/Source/MonoGame.Extended/ViewportAdapters/BoxingViewportAdapter.cs b/Source/MonoGame.Extended/ViewportAdapters/BoxingViewportAdapter.cs index 233bd644..ea80a5d5 100644 --- a/Source/MonoGame.Extended/ViewportAdapters/BoxingViewportAdapter.cs +++ b/Source/MonoGame.Extended/ViewportAdapters/BoxingViewportAdapter.cs @@ -15,60 +15,26 @@ namespace MonoGame.Extended.ViewportAdapters public class BoxingViewportAdapter : ScalingViewportAdapter { - private readonly GraphicsDeviceManager _graphicsDeviceManager; private readonly GameWindow _window; + private readonly GraphicsDevice _graphicsDevice; /// - /// Initializes a new instance of the . - /// Note: If you're using DirectX please use the other constructor due to a bug in MonoGame. - /// https://github.com/mono/MonoGame/issues/4018 + /// Initializes a new instance of the . /// - public BoxingViewportAdapter(GameWindow window, GraphicsDevice graphicsDevice, int virtualWidth, - int virtualHeight, int horizontalBleed, int verticalBleed) + public BoxingViewportAdapter(GameWindow window, GraphicsDevice graphicsDevice, int virtualWidth, int virtualHeight, int horizontalBleed = 0, int verticalBleed = 0) : base(graphicsDevice, virtualWidth, virtualHeight) { _window = window; + _graphicsDevice = graphicsDevice; window.ClientSizeChanged += OnClientSizeChanged; HorizontalBleed = horizontalBleed; VerticalBleed = verticalBleed; } - /// - /// Initializes a new instance of the . - /// Note: If you're using DirectX please use the other constructor due to a bug in MonoGame. - /// https://github.com/mono/MonoGame/issues/4018 - /// - public BoxingViewportAdapter(GameWindow window, GraphicsDevice graphicsDevice, int virtualWidth, - int virtualHeight) - : this(window, graphicsDevice, virtualWidth, virtualHeight, 0, 0) - { - } - - /// - /// Initializes a new instance of the . - /// Use this constructor only if you're using DirectX due to a bug in MonoGame. - /// https://github.com/mono/MonoGame/issues/4018 - /// This constructor will be made obsolete and eventually removed once the bug has been fixed. - /// - public BoxingViewportAdapter(GameWindow window, GraphicsDeviceManager graphicsDeviceManager, int virtualWidth, - int virtualHeight, int horizontalBleed, int verticalBleed) - : this( - window, graphicsDeviceManager.GraphicsDevice, virtualWidth, virtualHeight, horizontalBleed, - verticalBleed) - { - _graphicsDeviceManager = graphicsDeviceManager; - } - - /// - /// Initializes a new instance of the . - /// Use this constructor only if you're using DirectX due to a bug in MonoGame. - /// https://github.com/mono/MonoGame/issues/4018 - /// This constructor will be made obsolete and eventually removed once the bug has been fixed. - /// - public BoxingViewportAdapter(GameWindow window, GraphicsDeviceManager graphicsDeviceManager, int virtualWidth, - int virtualHeight) - : this(window, graphicsDeviceManager, virtualWidth, virtualHeight, 0, 0) + public override void Dispose() { + _window.ClientSizeChanged -= OnClientSizeChanged; + base.Dispose(); } /// @@ -85,45 +51,34 @@ namespace MonoGame.Extended.ViewportAdapters private void OnClientSizeChanged(object sender, EventArgs eventArgs) { - var viewport = GraphicsDevice.Viewport; + var clientBounds = _window.ClientBounds; - var worldScaleX = (float) viewport.Width/VirtualWidth; - var worldScaleY = (float) viewport.Height/VirtualHeight; + var worldScaleX = (float)clientBounds.Width / VirtualWidth; + var worldScaleY = (float)clientBounds.Height / VirtualHeight; - var safeScaleX = (float) viewport.Width/(VirtualWidth - HorizontalBleed); - var safeScaleY = (float) viewport.Height/(VirtualHeight - VerticalBleed); + var safeScaleX = (float)clientBounds.Width / (VirtualWidth - HorizontalBleed); + var safeScaleY = (float)clientBounds.Height / (VirtualHeight - VerticalBleed); var worldScale = MathHelper.Max(worldScaleX, worldScaleY); var safeScale = MathHelper.Min(safeScaleX, safeScaleY); var scale = MathHelper.Min(worldScale, safeScale); - var width = (int) (scale*VirtualWidth + 0.5f); - var height = (int) (scale*VirtualHeight + 0.5f); + var width = (int)(scale * VirtualWidth + 0.5f); + var height = (int)(scale * VirtualHeight + 0.5f); - if ((height >= viewport.Height) && (width < viewport.Width)) + if (height >= clientBounds.Height && width < clientBounds.Width) BoxingMode = BoxingMode.Pillarbox; else { - if ((width >= viewport.Height) && (height < viewport.Height)) + if (width >= clientBounds.Height && height <= clientBounds.Height) BoxingMode = BoxingMode.Letterbox; - else + else BoxingMode = BoxingMode.None; } - var x = viewport.Width/2 - width/2; - var y = viewport.Height/2 - height/2; + var x = clientBounds.Width / 2 - width / 2; + var y = clientBounds.Height / 2 - height / 2; GraphicsDevice.Viewport = new Viewport(x, y, width, height); - - // Needed for a DirectX bug in MonoGame 3.4. Hopefully it will be fixed in future versions - // see http://gamedev.stackexchange.com/questions/68914/issue-with-monogame-resizing - if ((_graphicsDeviceManager != null) && - ((_graphicsDeviceManager.PreferredBackBufferWidth != _window.ClientBounds.Width) || - (_graphicsDeviceManager.PreferredBackBufferHeight != _window.ClientBounds.Height))) - { - _graphicsDeviceManager.PreferredBackBufferWidth = _window.ClientBounds.Width; - _graphicsDeviceManager.PreferredBackBufferHeight = _window.ClientBounds.Height; - _graphicsDeviceManager.ApplyChanges(); - } } public override void Reset() diff --git a/Source/MonoGame.Extended/ViewportAdapters/ScalingViewportAdapter.cs b/Source/MonoGame.Extended/ViewportAdapters/ScalingViewportAdapter.cs index bbfac1a7..674a62ef 100644 --- a/Source/MonoGame.Extended/ViewportAdapters/ScalingViewportAdapter.cs +++ b/Source/MonoGame.Extended/ViewportAdapters/ScalingViewportAdapter.cs @@ -1,8 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -// ReSharper disable once CheckNamespace - namespace MonoGame.Extended.ViewportAdapters { public class ScalingViewportAdapter : ViewportAdapter diff --git a/Source/MonoGame.Extended/ViewportAdapters/ViewportAdapter.cs b/Source/MonoGame.Extended/ViewportAdapters/ViewportAdapter.cs index d46263d3..eb0491ee 100644 --- a/Source/MonoGame.Extended/ViewportAdapters/ViewportAdapter.cs +++ b/Source/MonoGame.Extended/ViewportAdapters/ViewportAdapter.cs @@ -1,17 +1,20 @@ +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -// ReSharper disable once CheckNamespace - namespace MonoGame.Extended.ViewportAdapters { - public abstract class ViewportAdapter + public abstract class ViewportAdapter : IDisposable { protected ViewportAdapter(GraphicsDevice graphicsDevice) { GraphicsDevice = graphicsDevice; } + public virtual void Dispose() + { + } + public GraphicsDevice GraphicsDevice { get; } public Viewport Viewport => GraphicsDevice.Viewport;