diff --git a/Content/Content.mgcb b/Content/Content.mgcb index 27c43d96ff430cd15af4f1b954ec21ed397acea7..38323b39a96a44db6f210c690314a1273f8b9929 100644 --- a/Content/Content.mgcb +++ b/Content/Content.mgcb @@ -32,3 +32,39 @@ /processorParam:TextureFormat=Compressed /build:Fonts/debugFont.spritefont +#begin TileMap/tilemap.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:TileMap/tilemap.png + +#begin TileMap/tiles1.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:TileMap/tiles1.png + +#begin TileMap/tiles2.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:TileMap/tiles2.png + diff --git a/Content/TileMap/tilemap.png b/Content/TileMap/tilemap.png new file mode 100644 index 0000000000000000000000000000000000000000..dfb654d65a67b5c10606e5214cb8c00314fb3938 Binary files /dev/null and b/Content/TileMap/tilemap.png differ diff --git a/Content/TileMap/tiles1.png b/Content/TileMap/tiles1.png new file mode 100644 index 0000000000000000000000000000000000000000..d16cdb468801c7dc57b3483ef2622a63b0d127c8 Binary files /dev/null and b/Content/TileMap/tiles1.png differ diff --git a/Content/TileMap/tiles2.png b/Content/TileMap/tiles2.png new file mode 100644 index 0000000000000000000000000000000000000000..cee234dbcda80f432a531baaa1eec91b19d4c458 Binary files /dev/null and b/Content/TileMap/tiles2.png differ diff --git a/Content/bin/DesktopGL/Content/TileMap/tilemap.xnb b/Content/bin/DesktopGL/Content/TileMap/tilemap.xnb new file mode 100644 index 0000000000000000000000000000000000000000..250fd441e01e65acc63a00dbace1988302f9ef48 Binary files /dev/null and b/Content/bin/DesktopGL/Content/TileMap/tilemap.xnb differ diff --git a/Content/bin/DesktopGL/Content/TileMap/tiles1.xnb b/Content/bin/DesktopGL/Content/TileMap/tiles1.xnb new file mode 100644 index 0000000000000000000000000000000000000000..0fffbe33ab8fd72efacaf25226c361dc657bcc0f Binary files /dev/null and b/Content/bin/DesktopGL/Content/TileMap/tiles1.xnb differ diff --git a/Content/bin/DesktopGL/Content/TileMap/tiles2.xnb b/Content/bin/DesktopGL/Content/TileMap/tiles2.xnb new file mode 100644 index 0000000000000000000000000000000000000000..d28f5239d497d938a2e00287220a241403c94966 Binary files /dev/null and b/Content/bin/DesktopGL/Content/TileMap/tiles2.xnb differ diff --git a/Content/bin/DesktopGL/TileMap/tilemap.xnb b/Content/bin/DesktopGL/TileMap/tilemap.xnb new file mode 100644 index 0000000000000000000000000000000000000000..250fd441e01e65acc63a00dbace1988302f9ef48 Binary files /dev/null and b/Content/bin/DesktopGL/TileMap/tilemap.xnb differ diff --git a/Content/bin/DesktopGL/TileMap/tiles1.xnb b/Content/bin/DesktopGL/TileMap/tiles1.xnb new file mode 100644 index 0000000000000000000000000000000000000000..0fffbe33ab8fd72efacaf25226c361dc657bcc0f Binary files /dev/null and b/Content/bin/DesktopGL/TileMap/tiles1.xnb differ diff --git a/Content/bin/DesktopGL/TileMap/tiles2.xnb b/Content/bin/DesktopGL/TileMap/tiles2.xnb new file mode 100644 index 0000000000000000000000000000000000000000..d28f5239d497d938a2e00287220a241403c94966 Binary files /dev/null and b/Content/bin/DesktopGL/TileMap/tiles2.xnb differ diff --git a/Content/obj/DesktopGL/.mgcontent b/Content/obj/DesktopGL/.mgcontent index f867b454e0a8eafa23f2f81c1dd7966249c9889f..cb6076b912cd76a9a04928802626400ac190e972 100644 --- a/Content/obj/DesktopGL/.mgcontent +++ b/Content/obj/DesktopGL/.mgcontent @@ -4,10 +4,15 @@ DesktopGL + D:/C# Project/full-leaf-framework/Content/TileMap/tilemap.png + D:/C# Project/full-leaf-framework/Content/TileMap/tiles1.png + D:/C# Project/full-leaf-framework/Content/TileMap/tiles2.png D:/C# Project/full-leaf-framework/Content/Characters/test.png D:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefont + + \ No newline at end of file diff --git a/Content/obj/DesktopGL/.mgstats b/Content/obj/DesktopGL/.mgstats index 56ee9331f046c46a6c9f76a6b1b49acfe60f5899..f735bcb5f1d1f5d3073aa8d26a5b7f43bd08fcd1 100644 --- a/Content/obj/DesktopGL/.mgstats +++ b/Content/obj/DesktopGL/.mgstats @@ -1,3 +1,6 @@ Source File,Dest File,Processor Type,Content Type,Source File Size,Dest File Size,Build Seconds "D:/C# Project/full-leaf-framework/Content/Characters/test.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Characters/test.xnb","TextureProcessor","Texture2DContent",396,40085,1.0594867 "D:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefont","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Fonts/debugFont.xnb","FontDescriptionProcessor","SpriteFontContent",2008,21538,0.9292899 +"D:/C# Project/full-leaf-framework/Content/TileMap/tilemap.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/TileMap/tilemap.xnb","TextureProcessor","Texture2DContent",608,32853,1.0064871 +"D:/C# Project/full-leaf-framework/Content/TileMap/tiles1.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/TileMap/tiles1.xnb","TextureProcessor","Texture2DContent",291,16469,0.1422165 +"D:/C# Project/full-leaf-framework/Content/TileMap/tiles2.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/TileMap/tiles2.xnb","TextureProcessor","Texture2DContent",296,16469,0.0336637 diff --git a/Content/obj/DesktopGL/TileMap/tilemap.mgcontent b/Content/obj/DesktopGL/TileMap/tilemap.mgcontent new file mode 100644 index 0000000000000000000000000000000000000000..6f51032c53f4380176abfcf2d7e05f84c268ea2b --- /dev/null +++ b/Content/obj/DesktopGL/TileMap/tilemap.mgcontent @@ -0,0 +1,42 @@ + + + D:/C# Project/full-leaf-framework/Content/TileMap/tilemap.png + 2023-11-05T10:24:28.7022456+08:00 + D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/TileMap/tilemap.xnb + 2023-11-05T10:26:35.5066498+08:00 + TextureImporter + 2020-08-11T00:17:54+08:00 + TextureProcessor + 2020-08-11T00:17:54+08:00 + + ColorKeyColor + 255,0,255,255 + + + ColorKeyEnabled + True + + + GenerateMipmaps + False + + + PremultiplyAlpha + True + + + ResizeToPowerOfTwo + False + + + MakeSquare + False + + + TextureFormat + Color + + + + + \ No newline at end of file diff --git a/Content/obj/DesktopGL/TileMap/tiles1.mgcontent b/Content/obj/DesktopGL/TileMap/tiles1.mgcontent new file mode 100644 index 0000000000000000000000000000000000000000..aa56648562058e2163fbf7e2067608ee8a2b339d --- /dev/null +++ b/Content/obj/DesktopGL/TileMap/tiles1.mgcontent @@ -0,0 +1,42 @@ + + + D:/C# Project/full-leaf-framework/Content/TileMap/tiles1.png + 2023-11-05T10:12:58.7660035+08:00 + D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/TileMap/tiles1.xnb + 2023-11-05T10:26:35.6966983+08:00 + TextureImporter + 2020-08-11T00:17:54+08:00 + TextureProcessor + 2020-08-11T00:17:54+08:00 + + ColorKeyColor + 255,0,255,255 + + + ColorKeyEnabled + True + + + GenerateMipmaps + False + + + PremultiplyAlpha + True + + + ResizeToPowerOfTwo + False + + + MakeSquare + False + + + TextureFormat + Color + + + + + \ No newline at end of file diff --git a/Content/obj/DesktopGL/TileMap/tiles2.mgcontent b/Content/obj/DesktopGL/TileMap/tiles2.mgcontent new file mode 100644 index 0000000000000000000000000000000000000000..69327abb0ac5a857ddd9212be9bdc771f5b3a286 --- /dev/null +++ b/Content/obj/DesktopGL/TileMap/tiles2.mgcontent @@ -0,0 +1,42 @@ + + + D:/C# Project/full-leaf-framework/Content/TileMap/tiles2.png + 2023-11-05T10:13:21.6739764+08:00 + D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/TileMap/tiles2.xnb + 2023-11-05T10:26:35.7357089+08:00 + TextureImporter + 2020-08-11T00:17:54+08:00 + TextureProcessor + 2020-08-11T00:17:54+08:00 + + ColorKeyColor + 255,0,255,255 + + + ColorKeyEnabled + True + + + GenerateMipmaps + False + + + PremultiplyAlpha + True + + + ResizeToPowerOfTwo + False + + + MakeSquare + False + + + TextureFormat + Color + + + + + \ No newline at end of file diff --git a/Content/obj/DesktopGL/net6.0/Content/.mgcontent b/Content/obj/DesktopGL/net6.0/Content/.mgcontent index e7c2155ebec629692a4cd1144051a77e51447833..17f86e5824fb9da4cf2cb032682592baa9a0fa80 100644 --- a/Content/obj/DesktopGL/net6.0/Content/.mgcontent +++ b/Content/obj/DesktopGL/net6.0/Content/.mgcontent @@ -1 +1 @@ -ReachDesktopGLD:/C# Project/full-leaf-framework/Content/Characters/test.pngD:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefont \ No newline at end of file +ReachDesktopGLD:/C# Project/full-leaf-framework/Content/Characters/test.pngD:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefontD:/C# Project/full-leaf-framework/Content/TileMap/tilemap.pngD:/C# Project/full-leaf-framework/Content/TileMap/tiles1.pngD:/C# Project/full-leaf-framework/Content/TileMap/tiles2.png \ No newline at end of file diff --git a/Content/obj/DesktopGL/net6.0/Content/.mgstats b/Content/obj/DesktopGL/net6.0/Content/.mgstats index 1d147bbbb7bc6cb424ac4f936587baaaf61e526d..a75924f42527708c1617cb9a27849f120546e3fd 100644 --- a/Content/obj/DesktopGL/net6.0/Content/.mgstats +++ b/Content/obj/DesktopGL/net6.0/Content/.mgstats @@ -1,3 +1,6 @@ Source File,Dest File,Processor Type,Content Type,Source File Size,Dest File Size,Build Seconds -"D:/C# Project/full-leaf-framework/Content/Characters/test.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Characters/test.xnb","TextureProcessor","Texture2DContent",405,40085,1.9842547 -"D:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefont","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Fonts/debugFont.xnb","FontDescriptionProcessor","SpriteFontContent",2008,21535,6.9613028 +"D:/C# Project/full-leaf-framework/Content/Characters/test.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Characters/test.xnb","TextureProcessor","Texture2DContent",405,40085,4.4511166 +"D:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefont","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Fonts/debugFont.xnb","FontDescriptionProcessor","SpriteFontContent",2068,21535,5.9572797 +"D:/C# Project/full-leaf-framework/Content/TileMap/tilemap.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/TileMap/tilemap.xnb","TextureProcessor","Texture2DContent",608,32853,3.6673605 +"D:/C# Project/full-leaf-framework/Content/TileMap/tiles1.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/TileMap/tiles1.xnb","TextureProcessor","Texture2DContent",291,16469,0.1150186 +"D:/C# Project/full-leaf-framework/Content/TileMap/tiles2.png","D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/TileMap/tiles2.xnb","TextureProcessor","Texture2DContent",296,16469,0.05327 diff --git a/Content/obj/DesktopGL/net6.0/Content/Characters/test.mgcontent b/Content/obj/DesktopGL/net6.0/Content/Characters/test.mgcontent index 64cb5b4ea9ad328941184f56b2e1b31140917a23..ae28c7f611a8cc164082808f1232299bc0d9f3aa 100644 --- a/Content/obj/DesktopGL/net6.0/Content/Characters/test.mgcontent +++ b/Content/obj/DesktopGL/net6.0/Content/Characters/test.mgcontent @@ -1 +1 @@ -D:/C# Project/full-leaf-framework/Content/Characters/test.png2023-09-24T10:30:57.1230794+08:00D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Characters/test.xnb2023-09-24T10:31:34.6111421+08:00TextureImporter2022-07-26T19:44:56+08:00TextureProcessor2022-07-26T19:44:56+08:00ColorKeyColor255,0,255,255ColorKeyEnabledTrueGenerateMipmapsFalsePremultiplyAlphaTrueResizeToPowerOfTwoFalseMakeSquareFalseTextureFormatColor \ No newline at end of file +D:/C# Project/full-leaf-framework/Content/Characters/test.png2023-10-15T09:42:06.318867+08:00D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Characters/test.xnb2023-10-28T22:43:27.2384193+08:00TextureImporter2022-07-26T19:44:56+08:00TextureProcessor2022-07-26T19:44:56+08:00ColorKeyColor255,0,255,255ColorKeyEnabledTrueGenerateMipmapsFalsePremultiplyAlphaTrueResizeToPowerOfTwoFalseMakeSquareFalseTextureFormatColor \ No newline at end of file diff --git a/Content/obj/DesktopGL/net6.0/Content/Fonts/debugFont.mgcontent b/Content/obj/DesktopGL/net6.0/Content/Fonts/debugFont.mgcontent index c12a2995843173621975430e396202e954f311c1..3e16b4b5dd2f8aa0b64cb07298b826fa94f45295 100644 --- a/Content/obj/DesktopGL/net6.0/Content/Fonts/debugFont.mgcontent +++ b/Content/obj/DesktopGL/net6.0/Content/Fonts/debugFont.mgcontent @@ -1 +1 @@ -D:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefont2023-09-10T22:37:44.4429575+08:00D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Fonts/debugFont.xnb2023-09-10T22:44:16.5671397+08:00FontDescriptionImporter2022-07-26T19:44:56+08:00FontDescriptionProcessor2022-07-26T19:44:56+08:00PremultiplyAlphaTrueTextureFormatCompressed \ No newline at end of file +D:/C# Project/full-leaf-framework/Content/Fonts/debugFont.spritefont2023-10-15T09:42:06.3508748+08:00D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/Fonts/debugFont.xnb2023-10-28T22:43:33.3039591+08:00FontDescriptionImporter2022-07-26T19:44:56+08:00FontDescriptionProcessor2022-07-26T19:44:56+08:00PremultiplyAlphaTrueTextureFormatCompressed \ No newline at end of file diff --git a/Content/obj/DesktopGL/net6.0/Content/TileMap/tilemap.mgcontent b/Content/obj/DesktopGL/net6.0/Content/TileMap/tilemap.mgcontent new file mode 100644 index 0000000000000000000000000000000000000000..ee63b06cee92e09def31139be1541edb9ecd7e18 --- /dev/null +++ b/Content/obj/DesktopGL/net6.0/Content/TileMap/tilemap.mgcontent @@ -0,0 +1 @@ +D:/C# Project/full-leaf-framework/Content/TileMap/tilemap.png2023-11-05T10:24:28.7022456+08:00D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/TileMap/tilemap.xnb2023-11-05T10:33:15.4890815+08:00TextureImporter2022-07-26T19:44:56+08:00TextureProcessor2022-07-26T19:44:56+08:00ColorKeyColor255,0,255,255ColorKeyEnabledTrueGenerateMipmapsFalsePremultiplyAlphaTrueResizeToPowerOfTwoFalseMakeSquareFalseTextureFormatColor \ No newline at end of file diff --git a/Content/obj/DesktopGL/net6.0/Content/TileMap/tiles1.mgcontent b/Content/obj/DesktopGL/net6.0/Content/TileMap/tiles1.mgcontent new file mode 100644 index 0000000000000000000000000000000000000000..56f88d41b4a9557a5ed069d1fce445607354e2f1 --- /dev/null +++ b/Content/obj/DesktopGL/net6.0/Content/TileMap/tiles1.mgcontent @@ -0,0 +1 @@ +D:/C# Project/full-leaf-framework/Content/TileMap/tiles1.png2023-11-05T10:12:58.7660035+08:00D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/TileMap/tiles1.xnb2023-11-05T10:33:15.6751278+08:00TextureImporter2022-07-26T19:44:56+08:00TextureProcessor2022-07-26T19:44:56+08:00ColorKeyColor255,0,255,255ColorKeyEnabledTrueGenerateMipmapsFalsePremultiplyAlphaTrueResizeToPowerOfTwoFalseMakeSquareFalseTextureFormatColor \ No newline at end of file diff --git a/Content/obj/DesktopGL/net6.0/Content/TileMap/tiles2.mgcontent b/Content/obj/DesktopGL/net6.0/Content/TileMap/tiles2.mgcontent new file mode 100644 index 0000000000000000000000000000000000000000..f497adc598909d282cd74fe5377d4442f84dbe0e --- /dev/null +++ b/Content/obj/DesktopGL/net6.0/Content/TileMap/tiles2.mgcontent @@ -0,0 +1 @@ +D:/C# Project/full-leaf-framework/Content/TileMap/tiles2.png2023-11-05T10:13:21.6739764+08:00D:/C# Project/full-leaf-framework/Content/bin/DesktopGL/Content/TileMap/tiles2.xnb2023-11-05T10:33:15.7281419+08:00TextureImporter2022-07-26T19:44:56+08:00TextureProcessor2022-07-26T19:44:56+08:00ColorKeyColor255,0,255,255ColorKeyEnabledTrueGenerateMipmapsFalsePremultiplyAlphaTrueResizeToPowerOfTwoFalseMakeSquareFalseTextureFormatColor \ No newline at end of file diff --git a/MainGame.cs b/MainGame.cs index 81972144f1d6bb5032a98be85bcfa02b037f2bee..29e67774b62cdf79682ef9815bacf82fd91b471c 100644 --- a/MainGame.cs +++ b/MainGame.cs @@ -4,6 +4,7 @@ using Microsoft.Xna.Framework.Input; using full_leaf_framework.Input; using full_leaf_framework.Visual; using full_leaf_framework.Physics; +using full_leaf_framework.Scene; using System; @@ -21,6 +22,8 @@ public class MainGame : Game public static InputManager inputManager; public static Camera camera; + public TileMap tileMap; + public Drawable test; public Drawable test2; @@ -56,7 +59,7 @@ public class MainGame : Game new Vector2(0, 50), 1); test2 = new Drawable(new AnimatedSprite(Content.Load("Characters/test")), new Vector2(100, 0), new Vector2(0, -50), 1); - + tileMap = new TileMap("utils/Scene/test_map.json", Content); // TODO: use this.Content to load your game content here } @@ -91,111 +94,16 @@ public class MainGame : Game test.angle += MathF.PI / 24; } if (inputManager.GetTrackingKey(Keys.E).fired) { - // TestCase,启动! - float time = (float)gameTime.ElapsedGameTime.TotalSeconds; - /* - // 1.直线不相交 - Line line1 = new Line(new Vector2(0, 0), new Vector2(1, 2)); - Line line2 = new Line(new Vector2(1, 1), new Vector2(2, 0)); - Line line3 = new Line(new Vector2(0, 3), new Vector2(2, 3)); - Console.WriteLine(line1.IsCollision(line2)); // f - Console.WriteLine(line1.IsCollision(line3)); // f - // 2.直线平行或重合 - line1 = new Line(new Vector2(0, 0), new Vector2(1, 2)); - line2 = new Line(new Vector2(1, 0), new Vector2(2, 2)); - line3 = new Line(new Vector2(0.5f, 1), new Vector2(1.5f, 3)); - Line line4 = new Line(new Vector2(1.5f, 3), new Vector2(2.5f, 5)); - Console.WriteLine(line1.IsCollision(line2)); // f - Console.WriteLine(line1.IsCollision(line3)); // t - Console.WriteLine(line1.IsCollision(line4)); // f - // 3.直线相交 - line1 = new Line(new Vector2(-1, -2), new Vector2(1, 2)); - line2 = new Line(new Vector2(0.5f, 0), new Vector2(0.75f, 3)); - line3 = new Line(new Vector2(-0.5f, -3), new Vector2(-0.5f, 3)); - Console.WriteLine(line1.IsCollision(line2)); // t - Console.WriteLine(line1.IsCollision(line3)); // t - */ - /* - // 4.线段和圆 - Line line1 = new Line(new Vector2(0, 0), new Vector2(2, 2)); - Circle circle1 = new Circle(new Vector2(2, 0), 1.2f); - Circle circle2 = new Circle(new Vector2(2, 0), 1.5f); - Console.WriteLine(line1.IsCollision(circle1)); // f - Console.WriteLine(line1.IsCollision(circle2)); // t - Line line2 = new Line(new Vector2(3, 1), new Vector2(3, -1)); - circle1 = new Circle(new Vector2(2, 2), 1.2f); - circle2 = new Circle(new Vector2(2, 2), 1.7f); - Console.WriteLine(line2.IsCollision(circle1)); // f - Console.WriteLine(line2.IsCollision(circle2)); // t - // 5.圆和圆 - circle1 = new Circle(new Vector2(0, 0), 3f); - circle2 = new Circle(new Vector2(4, 0), 2f); - Console.WriteLine(circle1.IsCollision(circle2)); // t - circle2 = new Circle(new Vector2(5, 1), 2f); - Console.WriteLine(circle2.IsCollision(circle1)); // f - */ - /* - // 6.多边形和线段 - Polygon polygon1 = new Polygon(new Vector2[4] {new Vector2(1, 1), new Vector2(3, 1), - new Vector2(4, 3), new Vector2(3, 3) }); - Line line1 = new Line(new Vector2(1, 3), new Vector2(2, 3)); - Line line2 = new Line(new Vector2(0, 1), new Vector2(1, 3)); - Line line3 = new Line(new Vector2(2, 0), new Vector2(5, 2)); - Line line4 = new Line(new Vector2(4, 1), new Vector2(3, 3)); - Console.WriteLine(polygon1.IsCollision(line1)); // f - Console.WriteLine(polygon1.IsCollision(line2)); // f - Console.WriteLine(polygon1.IsCollision(line3)); // f - Console.WriteLine(polygon1.IsCollision(line4)); // t - polygon1 = new Polygon(new Vector2[5] {new Vector2(1, 4), new Vector2(1, -1), - new Vector2(4, 2), new Vector2(3, 5), new Vector2(2, 5) }); - line1 = new Line(new Vector2(3, 0), new Vector2(4, 1)); - line2 = new Line(new Vector2(4, 5), new Vector2(5, 5)); - line3 = new Line(new Vector2(1, 7), new Vector2(5, 4)); - line4 = new Line(new Vector2(0.5f, 3), new Vector2(0.5f, 5)); - Line line5 = new Line(new Vector2(1, 5), new Vector2(2, 4.5f)); - Line line6 = new Line(new Vector2(0, 0), new Vector2(4, 4)); - Console.WriteLine(polygon1.IsCollision(line1)); // f - Console.WriteLine(polygon1.IsCollision(line2)); // f - Console.WriteLine(polygon1.IsCollision(line3)); // f - Console.WriteLine(polygon1.IsCollision(line4)); // f - Console.WriteLine(polygon1.IsCollision(line5)); // t - Console.WriteLine(polygon1.IsCollision(line6)); // t - */ - /* - // 7.多边形之间 - Polygon polygon1 = new Polygon(new Vector2[3] {new Vector2(1, 1), new Vector2(4, 1), - new Vector2(3, 3)}); - Polygon polygon2 = new Polygon(new Vector2[4] {new Vector2(0, 1), new Vector2(2.5f, 2), - new Vector2(2.5f, 4), new Vector2(0, 3)}); - Polygon polygon3 = new Polygon(new Vector2[5] {new Vector2(2, 3.5f), new Vector2(4, 3), - new Vector2(4, 5), new Vector2(3, 5.5f), new Vector2(2, 4)}); - Polygon polygon4 = new Polygon(new Rectangle(-1, 3, 3, 2)); - Console.WriteLine(polygon1.IsCollision(polygon2)); // t - Console.WriteLine(polygon1.IsCollision(polygon3)); // f - Console.WriteLine(polygon2.IsCollision(polygon3)); // t - Console.WriteLine(polygon4.IsCollision(polygon2)); // t - Console.WriteLine(polygon4.IsCollision(polygon1)); // f - */ - /* - // 8.多边形和圆 - Polygon polygon1 = new Polygon(new Vector2[5] {new Vector2(1, 4), new Vector2(1, -1), - new Vector2(4, 2), new Vector2(3, 5), new Vector2(2, 5) }); - Circle circle1 = new Circle(new Vector2(4, 0), 1.3f); - Circle circle2 = new Circle(new Vector2(5, 1), 1.2f); - Circle circle3 = new Circle(new Vector2(5, 5), 1f); - Circle circle4 = new Circle(new Vector2(2, 6), 1.5f); - Circle circle5 = new Circle(new Vector2(1, 5), 0.9f); - Console.WriteLine(polygon1.IsCollision(circle1)); // f - Console.WriteLine(polygon1.IsCollision(circle2)); // f - Console.WriteLine(polygon1.IsCollision(circle3)); // f - Console.WriteLine(polygon1.IsCollision(circle4)); // t - Console.WriteLine(polygon1.IsCollision(circle5)); // t - */ + float time = (float)gameTime.TotalGameTime.TotalSeconds; + tileMap = new TileMap("utils/Scene/test_map.json", Content); + Console.WriteLine((float)gameTime.TotalGameTime.TotalSeconds - time); } // 添加绘制物体 - camera.insertObject(test); - camera.insertObject(test2); + // camera.insertObject(test); + // camera.insertObject(test2); // TODO: Add your update logic here + tileMap.Update(gameTime); + tileMap.Draw(camera); base.Update(gameTime); } diff --git a/bin/Debug/net6.0/Content/TileMap/tilemap.xnb b/bin/Debug/net6.0/Content/TileMap/tilemap.xnb new file mode 100644 index 0000000000000000000000000000000000000000..250fd441e01e65acc63a00dbace1988302f9ef48 Binary files /dev/null and b/bin/Debug/net6.0/Content/TileMap/tilemap.xnb differ diff --git a/bin/Debug/net6.0/Content/TileMap/tiles1.xnb b/bin/Debug/net6.0/Content/TileMap/tiles1.xnb new file mode 100644 index 0000000000000000000000000000000000000000..0fffbe33ab8fd72efacaf25226c361dc657bcc0f Binary files /dev/null and b/bin/Debug/net6.0/Content/TileMap/tiles1.xnb differ diff --git a/bin/Debug/net6.0/Content/TileMap/tiles2.xnb b/bin/Debug/net6.0/Content/TileMap/tiles2.xnb new file mode 100644 index 0000000000000000000000000000000000000000..d28f5239d497d938a2e00287220a241403c94966 Binary files /dev/null and b/bin/Debug/net6.0/Content/TileMap/tiles2.xnb differ diff --git a/bin/Debug/net6.0/Newtonsoft.Json.dll b/bin/Debug/net6.0/Newtonsoft.Json.dll new file mode 100644 index 0000000000000000000000000000000000000000..d035c38b4edec5c10d4bc421a2dce19f5f998677 Binary files /dev/null and b/bin/Debug/net6.0/Newtonsoft.Json.dll differ diff --git a/bin/Debug/net6.0/full-leaf-framework.deps.json b/bin/Debug/net6.0/full-leaf-framework.deps.json index 1ca78498b9667d3900ac891f4d24ed8e5e246b7d..33ff52f717bd7f9459bc104f45a7c32eb6bc5abb 100644 --- a/bin/Debug/net6.0/full-leaf-framework.deps.json +++ b/bin/Debug/net6.0/full-leaf-framework.deps.json @@ -9,7 +9,8 @@ "full-leaf-framework/1.0.0": { "dependencies": { "MonoGame.Content.Builder.Task": "3.8.1.303", - "MonoGame.Framework.DesktopGL": "3.8.1.303" + "MonoGame.Framework.DesktopGL": "3.8.1.303", + "Newtonsoft.Json": "13.0.3" }, "runtime": { "full-leaf-framework.dll": {} @@ -65,6 +66,14 @@ "fileVersion": "0.0.0.0" } } + }, + "Newtonsoft.Json/13.0.3": { + "runtime": { + "lib/net6.0/Newtonsoft.Json.dll": { + "assemblyVersion": "13.0.0.0", + "fileVersion": "13.0.3.27908" + } + } } } }, @@ -87,6 +96,13 @@ "sha512": "sha512-eGYhqn0n1olk8MNYeE9EuBmoNNECN1T18rPMaQpkzsEQ0H3nVyFPXC+uCo78v5pi5juQpJ3PSFnSkjzZJ1U58A==", "path": "monogame.framework.desktopgl/3.8.1.303", "hashPath": "monogame.framework.desktopgl.3.8.1.303.nupkg.sha512" + }, + "Newtonsoft.Json/13.0.3": { + "type": "package", + "serviceable": true, + "sha512": "sha512-HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==", + "path": "newtonsoft.json/13.0.3", + "hashPath": "newtonsoft.json.13.0.3.nupkg.sha512" } } } \ No newline at end of file diff --git a/bin/Debug/net6.0/full-leaf-framework.dll b/bin/Debug/net6.0/full-leaf-framework.dll index 1e796aa61c6c5f07f8eabc8f8e075b9bb100bad6..2390f81803cb3821314aae8c2fed89d129727aae 100644 Binary files a/bin/Debug/net6.0/full-leaf-framework.dll and b/bin/Debug/net6.0/full-leaf-framework.dll differ diff --git a/bin/Debug/net6.0/full-leaf-framework.pdb b/bin/Debug/net6.0/full-leaf-framework.pdb index aacd36bcbbe8a1ab898756a5cc48bcef2f3f8c9d..764d15918ec9857ff75b1de7c51ab9b967edaad3 100644 Binary files a/bin/Debug/net6.0/full-leaf-framework.pdb and b/bin/Debug/net6.0/full-leaf-framework.pdb differ diff --git a/full-leaf-framework.csproj b/full-leaf-framework.csproj index a7fb71dd8a8c6eda1eaefc72333f8bcc478b50fd..f37dbb9c91633a79880a413306811312823fdf44 100644 --- a/full-leaf-framework.csproj +++ b/full-leaf-framework.csproj @@ -21,6 +21,7 @@ + diff --git a/obj/Debug/net6.0/full-leaf-framework.GeneratedMSBuildEditorConfig.editorconfig b/obj/Debug/net6.0/full-leaf-framework.GeneratedMSBuildEditorConfig.editorconfig index 94697ae4a1fb181f15031e81b924a0ae91e19c67..c5fbdd54616197f198731d5c08154ea3c38efb1a 100644 --- a/obj/Debug/net6.0/full-leaf-framework.GeneratedMSBuildEditorConfig.editorconfig +++ b/obj/Debug/net6.0/full-leaf-framework.GeneratedMSBuildEditorConfig.editorconfig @@ -8,4 +8,4 @@ build_property.PlatformNeutralAssembly = build_property.EnforceExtendedAnalyzerRules = build_property._SupportedPlatformList = Linux,macOS,Windows build_property.RootNamespace = full-leaf-framework -build_property.ProjectDir = d:\C# Project\full-leaf-framework\ +build_property.ProjectDir = D:\C# Project\full-leaf-framework\ diff --git a/obj/Debug/net6.0/full-leaf-framework.assets.cache b/obj/Debug/net6.0/full-leaf-framework.assets.cache index 24d9eba26f9025744f7b236e73d81308c0d954b0..6ac920ab66d1b34c87eb9423bda93b0b85715736 100644 Binary files a/obj/Debug/net6.0/full-leaf-framework.assets.cache and b/obj/Debug/net6.0/full-leaf-framework.assets.cache differ diff --git a/obj/Debug/net6.0/full-leaf-framework.csproj.AssemblyReference.cache b/obj/Debug/net6.0/full-leaf-framework.csproj.AssemblyReference.cache index 5d8a146fd8eb2f497a5db88515d3e33cf8ce55d1..6f20a5abaf2b14cc5ef531378f3dd3fa76b7117f 100644 Binary files a/obj/Debug/net6.0/full-leaf-framework.csproj.AssemblyReference.cache and b/obj/Debug/net6.0/full-leaf-framework.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/net6.0/full-leaf-framework.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/full-leaf-framework.csproj.CoreCompileInputs.cache index 0c53e02528872ce135443241a37c31ccbdbcf296..a1138996ac93e3b26d1baebafa9e5a20d8b06304 100644 --- a/obj/Debug/net6.0/full-leaf-framework.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net6.0/full-leaf-framework.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -16e9a58c7588e0d7710fb5896473015351817b7f +7bb7f5014117e6928dfc4db123b6fc74dd7f5d5e diff --git a/obj/Debug/net6.0/full-leaf-framework.csproj.FileListAbsolute.txt b/obj/Debug/net6.0/full-leaf-framework.csproj.FileListAbsolute.txt index 0db82d8f5ea464f3e643f6b19dff69fe8056d853..6a38deefd6a9394bc313114af8c5ec926478659e 100644 --- a/obj/Debug/net6.0/full-leaf-framework.csproj.FileListAbsolute.txt +++ b/obj/Debug/net6.0/full-leaf-framework.csproj.FileListAbsolute.txt @@ -25,3 +25,7 @@ D:\C# Project\full-leaf-framework\obj\Debug\net6.0\full-leaf-framework.genruntim D:\C# Project\full-leaf-framework\obj\Debug\net6.0\ref\full-leaf-framework.dll D:\C# Project\full-leaf-framework\bin\Debug\net6.0\Content\Fonts\debugFont.xnb D:\C# Project\full-leaf-framework\bin\Debug\net6.0\Content\Characters\test.xnb +D:\C# Project\full-leaf-framework\bin\Debug\net6.0\Newtonsoft.Json.dll +D:\C# Project\full-leaf-framework\bin\Debug\net6.0\Content\TileMap\tilemap.xnb +D:\C# Project\full-leaf-framework\bin\Debug\net6.0\Content\TileMap\tiles1.xnb +D:\C# Project\full-leaf-framework\bin\Debug\net6.0\Content\TileMap\tiles2.xnb diff --git a/obj/Debug/net6.0/full-leaf-framework.dll b/obj/Debug/net6.0/full-leaf-framework.dll index 1e796aa61c6c5f07f8eabc8f8e075b9bb100bad6..2390f81803cb3821314aae8c2fed89d129727aae 100644 Binary files a/obj/Debug/net6.0/full-leaf-framework.dll and b/obj/Debug/net6.0/full-leaf-framework.dll differ diff --git a/obj/Debug/net6.0/full-leaf-framework.pdb b/obj/Debug/net6.0/full-leaf-framework.pdb index aacd36bcbbe8a1ab898756a5cc48bcef2f3f8c9d..764d15918ec9857ff75b1de7c51ab9b967edaad3 100644 Binary files a/obj/Debug/net6.0/full-leaf-framework.pdb and b/obj/Debug/net6.0/full-leaf-framework.pdb differ diff --git a/obj/Debug/net6.0/ref/full-leaf-framework.dll b/obj/Debug/net6.0/ref/full-leaf-framework.dll index f07adc766cac20953a95bb6c879bc1ce8c544095..9283470003e337c945e44b43c7b4c4b2502a7627 100644 Binary files a/obj/Debug/net6.0/ref/full-leaf-framework.dll and b/obj/Debug/net6.0/ref/full-leaf-framework.dll differ diff --git a/obj/Debug/net6.0/refint/full-leaf-framework.dll b/obj/Debug/net6.0/refint/full-leaf-framework.dll index f07adc766cac20953a95bb6c879bc1ce8c544095..9283470003e337c945e44b43c7b4c4b2502a7627 100644 Binary files a/obj/Debug/net6.0/refint/full-leaf-framework.dll and b/obj/Debug/net6.0/refint/full-leaf-framework.dll differ diff --git a/obj/full-leaf-framework.csproj.nuget.dgspec.json b/obj/full-leaf-framework.csproj.nuget.dgspec.json index 2310ea13459a0aa03b17a8a3ae83f28ebafb0f35..1c92839ca9ab08ea616c8e4fd0ed842fb4f5a94e 100644 --- a/obj/full-leaf-framework.csproj.nuget.dgspec.json +++ b/obj/full-leaf-framework.csproj.nuget.dgspec.json @@ -45,6 +45,10 @@ "MonoGame.Framework.DesktopGL": { "target": "Package", "version": "[3.8.1.303, )" + }, + "Newtonsoft.Json": { + "target": "Package", + "version": "[13.0.3, )" } }, "imports": [ diff --git a/obj/project.assets.json b/obj/project.assets.json index 351257d506e6e8c6ac623d9a2d5b7b8fdf55a787..a4f9bd83bf8b17f39ccfd556ddd663f8616f3786 100644 --- a/obj/project.assets.json +++ b/obj/project.assets.json @@ -54,6 +54,19 @@ "rid": "win-x86" } } + }, + "Newtonsoft.Json/13.0.3": { + "type": "package", + "compile": { + "lib/net6.0/Newtonsoft.Json.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net6.0/Newtonsoft.Json.dll": { + "related": ".xml" + } + } } } }, @@ -93,12 +106,43 @@ "runtimes/win-x86/native/SDL2.dll", "runtimes/win-x86/native/soft_oal.dll" ] + }, + "Newtonsoft.Json/13.0.3": { + "sha512": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==", + "type": "package", + "path": "newtonsoft.json/13.0.3", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "LICENSE.md", + "README.md", + "lib/net20/Newtonsoft.Json.dll", + "lib/net20/Newtonsoft.Json.xml", + "lib/net35/Newtonsoft.Json.dll", + "lib/net35/Newtonsoft.Json.xml", + "lib/net40/Newtonsoft.Json.dll", + "lib/net40/Newtonsoft.Json.xml", + "lib/net45/Newtonsoft.Json.dll", + "lib/net45/Newtonsoft.Json.xml", + "lib/net6.0/Newtonsoft.Json.dll", + "lib/net6.0/Newtonsoft.Json.xml", + "lib/netstandard1.0/Newtonsoft.Json.dll", + "lib/netstandard1.0/Newtonsoft.Json.xml", + "lib/netstandard1.3/Newtonsoft.Json.dll", + "lib/netstandard1.3/Newtonsoft.Json.xml", + "lib/netstandard2.0/Newtonsoft.Json.dll", + "lib/netstandard2.0/Newtonsoft.Json.xml", + "newtonsoft.json.13.0.3.nupkg.sha512", + "newtonsoft.json.nuspec", + "packageIcon.png" + ] } }, "projectFileDependencyGroups": { "net6.0": [ "MonoGame.Content.Builder.Task >= 3.8.1.303", - "MonoGame.Framework.DesktopGL >= 3.8.1.303" + "MonoGame.Framework.DesktopGL >= 3.8.1.303", + "Newtonsoft.Json >= 13.0.3" ] }, "packageFolders": { @@ -145,6 +189,10 @@ "MonoGame.Framework.DesktopGL": { "target": "Package", "version": "[3.8.1.303, )" + }, + "Newtonsoft.Json": { + "target": "Package", + "version": "[13.0.3, )" } }, "imports": [ diff --git a/obj/project.nuget.cache b/obj/project.nuget.cache index ee3966b006fd46a2c6972dd82b08d0a0b54d0065..6e92fe7f445c40209f01af9588b1959f1140b75e 100644 --- a/obj/project.nuget.cache +++ b/obj/project.nuget.cache @@ -1,15 +1,16 @@ { "version": 2, - "dgSpecHash": "PiKVHTg2jKul7Mb+I9/RVd0e+on+ak2hN/kvW89f8HGkH7uz2tRVcbYswfGZeJf0GD9tJ207tDFMhnSJBodPkw==", + "dgSpecHash": "fHrp/md+kf9m1Y6qWmEgfWNND8Aq/DpGkjj5MtU/kWpjFkn+IKPMaHb73YCR8/gCWC1s1OwGwTxUZSnHAmEGHw==", "success": true, "projectFilePath": "D:\\C# Project\\full-leaf-framework\\full-leaf-framework.csproj", "expectedPackageFiles": [ "C:\\Users\\dell\\.nuget\\packages\\monogame.content.builder.task\\3.8.1.303\\monogame.content.builder.task.3.8.1.303.nupkg.sha512", "C:\\Users\\dell\\.nuget\\packages\\monogame.framework.desktopgl\\3.8.1.303\\monogame.framework.desktopgl.3.8.1.303.nupkg.sha512", - "C:\\Users\\dell\\.nuget\\packages\\microsoft.netcore.app.ref\\6.0.21\\microsoft.netcore.app.ref.6.0.21.nupkg.sha512", - "C:\\Users\\dell\\.nuget\\packages\\microsoft.windowsdesktop.app.ref\\6.0.21\\microsoft.windowsdesktop.app.ref.6.0.21.nupkg.sha512", + "C:\\Users\\dell\\.nuget\\packages\\newtonsoft.json\\13.0.3\\newtonsoft.json.13.0.3.nupkg.sha512", "C:\\Users\\dell\\.nuget\\packages\\microsoft.aspnetcore.app.ref\\6.0.21\\microsoft.aspnetcore.app.ref.6.0.21.nupkg.sha512", - "C:\\Users\\dell\\.nuget\\packages\\microsoft.netcore.app.host.win-x64\\6.0.21\\microsoft.netcore.app.host.win-x64.6.0.21.nupkg.sha512" + "C:\\Users\\dell\\.nuget\\packages\\microsoft.netcore.app.host.win-x64\\6.0.21\\microsoft.netcore.app.host.win-x64.6.0.21.nupkg.sha512", + "C:\\Users\\dell\\.nuget\\packages\\microsoft.netcore.app.ref\\6.0.21\\microsoft.netcore.app.ref.6.0.21.nupkg.sha512", + "C:\\Users\\dell\\.nuget\\packages\\microsoft.windowsdesktop.app.ref\\6.0.21\\microsoft.windowsdesktop.app.ref.6.0.21.nupkg.sha512" ], "logs": [] } \ No newline at end of file diff --git a/utils/Scene/Building.cs b/utils/Scene/Building.cs new file mode 100644 index 0000000000000000000000000000000000000000..04b3ecaa047856cfb4956d091d0313a557f64673 --- /dev/null +++ b/utils/Scene/Building.cs @@ -0,0 +1,45 @@ +/* +Building 地图中的建筑物 +这里只提供一个建筑物基类,包含场景中建筑物的一些关键信息 +可以写继承类,让其发挥一些其他效果 +*/ + +using full_leaf_framework.Visual; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace full_leaf_framework.Scene; + +/// +/// 建筑物 +/// +public class Building +{ + + /// + /// 向外展现的可绘制对象 + /// + public Drawable drawable; + + /// + /// 填充一个建筑物 + /// + public void StartBuilding(AnimatedSprite currentAnimation, + Vector2 pos, + Vector2 anchorPoint, + float sizeScale, + float angle = 0, + SpriteEffects effects = SpriteEffects.None, + int layer = 0) { + drawable = new Drawable(currentAnimation, pos, anchorPoint, sizeScale, + angle, effects, layer); + } + + /// + /// 更新建筑物,基类的更新仅包含动画 + /// + public virtual void Update(GameTime gameTime) { + drawable.currentAnimation.Update(gameTime); + } + +} \ No newline at end of file diff --git a/utils/Scene/Tile.cs b/utils/Scene/Tile.cs new file mode 100644 index 0000000000000000000000000000000000000000..3e4c9469260433c173df41d97cb352d68cfb67df --- /dev/null +++ b/utils/Scene/Tile.cs @@ -0,0 +1,87 @@ +/* +Tile 就是瓦片地图中的瓦片 +实际上就是单个的地块 +现在提供一个Tile基类,可以储存一个地块的一些基本信息 +可以写继承类,然后创建具有专门功能的地块,在地图中发挥作用 +*/ + +using full_leaf_framework.Visual; +using Microsoft.Xna.Framework; + +namespace full_leaf_framework.Scene; + +/// +/// 瓦片 +/// +public class Tile { + + /// + /// 向外展现的可绘制对象 + /// + public Drawable drawable; + + /// + /// 使用的图集 + /// + protected AnimatedSprite usedSprite; + /// + /// 使用帧(开始) + /// + protected int usedFrameL; + /// + /// 使用帧(结尾) + /// + protected int usedFrameR; + /// + /// 当前帧 + /// + protected int currentFrame; + /// + /// 帧之间的延迟时间 + /// + protected float frameDelay; + /// + /// 当前延迟时间计数器 + /// + protected float currentDelay; + + public AnimatedSprite UsedSprite { get => usedSprite; set => usedSprite = value; } + public int UsedFrameL { get => usedFrameL; set => usedFrameL = value; } + public int UsedFrameR { get => usedFrameR; set => usedFrameR = value; } + public int CurrentFrame { get => currentFrame; set => currentFrame = value; } + public float FrameDelay { get => frameDelay; set => frameDelay = value; } + public float CurrentDelay { get => currentDelay; set => currentDelay = value; } + + /// + /// 填充瓦片基本内容 + /// + /// 使用的图集 + /// 使用帧(开始) + /// 使用帧(结尾) + /// 当前帧 + /// 帧之间的延迟时间 + public void BeginTile(AnimatedSprite usedSprite, int usedFrameL, int usedFrameR, int currentFrame, float frameDelay) { + this.UsedSprite = usedSprite; + this.UsedFrameL = usedFrameL; + this.UsedFrameR = usedFrameR; + this.CurrentFrame = currentFrame; + this.FrameDelay = frameDelay; + CurrentDelay = frameDelay; + } + + /// + /// 更新瓦片,基类的更新仅包含动画 + /// + public virtual void Update(GameTime gameTime) { + CurrentDelay -= (float)gameTime.ElapsedGameTime.TotalSeconds; + if (CurrentDelay <= 0f) { + // 更新帧 + CurrentFrame++; + if (CurrentFrame > UsedFrameR) { + CurrentFrame = UsedFrameL; + } + CurrentDelay = FrameDelay; + } + } + +} diff --git a/utils/Scene/TileMap.cs b/utils/Scene/TileMap.cs new file mode 100644 index 0000000000000000000000000000000000000000..f2811e07d0e62fc786785520f4dfa2209140000a --- /dev/null +++ b/utils/Scene/TileMap.cs @@ -0,0 +1,185 @@ +/* +TileMap 瓦片地图 +一种常用的地图构建方法,将地图分割为整齐的地块, +并对每个地块的数据分别编辑。 +对于地图中重复元素较多的情况下,这种方式能够提升编辑效率 +*/ + +using full_leaf_framework.Visual; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System.Reflection; + +namespace full_leaf_framework.Scene; + +/// +/// 瓦片地图主体 +/// +public class TileMap { + + /// + /// 精灵图集信息 + /// + private SpriteInfo[] spriteInfos; + private int tileWidth; + /// + /// 瓦片的宽度 + /// + public int TileWidth { get => tileWidth; } + private int tileHeight; + /// + /// 瓦片的高度 + /// + public int TileHeight { get => tileHeight; } + private int mapWidth; + /// + /// 瓦片地图列数 + /// + public int MapWidth { get => mapWidth; } + private int mapHeight; + /// + /// 瓦片地图行数 + /// + public int MapHeight { get => mapHeight; } + + /// + /// 瓦片集合 + /// + public Tile[][] tiles; + // 注:认为瓦片地图的最左上角是(0, 0) + // 每个瓦片的左上角是其相对坐标的(0, 0) + // 瓦片的各项初始化要在读取数据后就完成 + + /// + /// 建筑物集合 + /// + public Building[] buildings; + + private ContentManager Content; + + /// + /// 初始化瓦片地图 + /// + /// 应当填入相对路径,从程序目录开始 + public TileMap(string location, ContentManager Content) { + TileMapInfo tileMapInfo = TileMapInfo.LoadTileMapInfo(location); + this.Content = Content; + // 以下是对数据的各项处理 + tileWidth = tileMapInfo.tileWidth; + tileHeight = tileMapInfo.tileHeight; + mapWidth = tileMapInfo.mapWidth; + mapHeight = tileMapInfo.mapHeight; + // 填充基本数据 + LoadSprites(tileMapInfo); + LoadTiles(tileMapInfo); + LoadBuildings(tileMapInfo); + // 读取相关资源 + } + + #region 读取资源 + + /// + /// 读取SpriteInfos + /// + private void LoadSprites(TileMapInfo tileMapInfo) { + spriteInfos = tileMapInfo.spriteInfos; + foreach (SpriteInfo spriteInfo in spriteInfos) { + spriteInfo.texture = new AnimatedSprite(Content.Load(spriteInfo.location), + spriteInfo.rows, spriteInfo.column); + } + } + + /// + /// 读取瓦片 + /// + private void LoadTiles(TileMapInfo tileMapInfo) { + // 用来参考的tile信息 + tiles = new Tile[mapHeight][]; + // 生成地图 + Assembly assembly = Assembly.GetExecutingAssembly(); + // 获取当前程序集(为了创建瓦片) + for (int i = 0; i < tileMapInfo.mapInfos.Length; i++) { + tiles[i] = new Tile[mapWidth]; + for (int j = 0; j < tileMapInfo.mapInfos[i].Length; j++) { + // 用tileMapInfo[i][j]表示第i+1行j+1列的瓦片 + // 从tileInfos里查找与字符相匹配的瓦片类型 + foreach (TileInfo tileInfo in tileMapInfo.tileInfos) { + if (tileInfo.tileName == tileMapInfo.mapInfos[i][j]) { + // 找到了,然后将对应的Tile按照类名初始化 + // 必须填写类的完全限定名,这点应当在Json中体现 + dynamic obj = assembly.CreateInstance(tileInfo.tileClass); + Tile tile = (Tile)obj; + foreach (SpriteInfo spriteInfo in spriteInfos) { + if (tileInfo.usedSprite == spriteInfo.unitName) { + // 找到图集,那么创建瓦片 + tile.BeginTile(spriteInfo.texture, tileInfo.usedFrameL, + tileInfo.usedFrameR, tileInfo.startFrame, tileInfo.frameDelay); + // 对每个Tile对象生成Drawable + tile.drawable = new Drawable(tile.UsedSprite, new Vector2(j * tileWidth, i * tileHeight), + new Vector2(-tile.UsedSprite.Width / 2, -tile.UsedSprite.Height / 2), + tileWidth / tile.UsedSprite.Width, 0, SpriteEffects.None, 0); + } + } + tiles[i][j] = tile; + } + } + } + } + } + + /// + /// 读取建筑物 + /// + private void LoadBuildings(TileMapInfo tileMapInfo) { + buildings = new Building[tileMapInfo.buildingInfos.Length]; + // 创建建筑列表 + Assembly assembly = Assembly.GetExecutingAssembly(); + // 获取当前程序集(为了创建建筑物) + for (int i = 0; i < tileMapInfo.buildingInfos.Length; i++) { + // 按照名称创建对应建筑 + dynamic obj = assembly.CreateInstance(tileMapInfo.buildingInfos[i].buildingClass); + Building building = (Building)obj; + BuildingInfo currentInfo = tileMapInfo.buildingInfos[i]; + building.StartBuilding(currentInfo.spriteInfo.ReturnAnimation(Content), + new Vector2(currentInfo.posX, currentInfo.posY), new Vector2(currentInfo.anchorPointX, currentInfo.anchorPointY), + currentInfo.sizeScale, currentInfo.angle, SpriteEffects.None, currentInfo.layer); + buildings[i] = building; + } + } + + #endregion + + /// + /// 更新瓦片地图 + /// + public void Update(GameTime gameTime) { + for (int i = 0; i < tiles.Length; i++) { + for (int j = 0; j < tiles[0].Length; j++) { + tiles[i][j].Update(gameTime); + } + } + foreach (Building building in buildings) { + building.Update(gameTime); + } + } + + /// + /// 绘制瓦片地图 + /// + public void Draw(Camera camera) { + // 向camera中添加相应的对象 + // 但是注意,对于每个Tile,它们共用一个AnimatedSprite,所以务必做好区分 + for (int i = 0; i < tiles.Length; i++) { + for (int j = 0; j < tiles[0].Length; j++) { + // 利用瓦片的Drawable对象 + tiles[i][j].drawable.settledFrame = tiles[i][j].CurrentFrame; + camera.insertObject(tiles[i][j].drawable); + } + } + foreach (Building building in buildings) { + camera.insertObject(building.drawable); + } + } + +} \ No newline at end of file diff --git a/utils/Scene/TileMapInfo.cs b/utils/Scene/TileMapInfo.cs new file mode 100644 index 0000000000000000000000000000000000000000..e2c4af05b0d9a2d44abb1e77abe84e69b97ba1ba --- /dev/null +++ b/utils/Scene/TileMapInfo.cs @@ -0,0 +1,192 @@ +/* +为了从一个包含有TileMap相关数据的Json文件中读取相关数据, +我写了这个类。 +*/ + +using Microsoft.Xna.Framework; +using full_leaf_framework.Visual; +using Newtonsoft.Json; +using System.IO; + +namespace full_leaf_framework.Scene; + +/// +/// 瓦片地图信息 +/// +public class TileMapInfo { + + /// + /// 精灵图集的信息 + /// + public SpriteInfo[] spriteInfos; + /// + /// 单个瓦片宽度 + /// + public int tileWidth; + /// + /// 单个瓦片高度 + /// + public int tileHeight; + /// + /// 瓦片地图列数 + /// + public int mapWidth; + /// + /// 瓦片地图行数 + /// + public int mapHeight; + /// + /// 瓦片地图信息 + /// + public string[][] mapInfos; + /// + /// 瓦片信息列表 + /// + public TileInfo[] tileInfos; + /// + /// 建筑信息列表 + /// + public BuildingInfo[] buildingInfos; + + /// + /// 创建一个TileMapInfo对象并且从指定路径读取数据 + /// + /// 应当填入相对路径,从程序目录开始 + public static TileMapInfo LoadTileMapInfo(string location) { + string jsonContent = File.ReadAllText(location); + TileMapInfo tileMapInfo = JsonConvert.DeserializeObject(jsonContent); + return tileMapInfo; + } + +} + +/// +/// 精灵图集信息 +/// +public class SpriteInfo { + + /// + /// 该图集的名称 + /// + public string unitName; + /// + /// 资源位置 + /// + public string location; + /// + /// 读取的图集资源 + /// + public AnimatedSprite texture; + /// + /// 图集的行数 + /// + public int rows; + /// + /// 图集的列数 + /// + public int column; + +} + +/// +/// 瓦片信息 +/// +public class TileInfo { + + /// + /// 瓦片对应要创建的对象名称 + /// + public string tileClass; + /// + /// 瓦片在图表中的符号表示 + /// + public string tileName; + /// + /// 使用的精灵图集名称 + /// + public string usedSprite; + /// + /// 使用帧(开始) + /// + public int usedFrameL; + /// + /// 使用帧(结尾) + /// + public int usedFrameR; + /// + /// 帧之间的延迟时间 + /// + public float frameDelay; + /// + /// 开始帧 + /// + public int startFrame; + +} + +/// +/// 向量信息 +/// +public class VectorInfo { + + /// + /// X值 + /// + public float X; + /// + /// Y值 + /// + public float Y; + + /// + /// 按照X与Y信息返回一个Vector2对象 + /// + public Vector2 GetVector2() { + return new Vector2(X, Y); + } + +} + +/// +/// 建筑物信息 +/// +public class BuildingInfo { + + /// + /// 建筑物对应要创建的对象名称 + /// + public string buildingClass; + /// + /// 动画信息 + /// + public AnimationInfo spriteInfo; + /// + /// 位置的X值 + /// + public float posX; + /// + /// 位置的Y值 + /// + public float posY; + /// + /// 锚点的X值 + /// + public float anchorPointX; + /// + /// 锚点的Y值 + /// + public float anchorPointY; + /// + /// 放缩大小比值 + /// + public float sizeScale; + /// + /// 旋转角度 + /// + public float angle; + /// + /// 绘制图层 + /// + public int layer; + +} \ No newline at end of file diff --git a/utils/Scene/sample_map.json b/utils/Scene/sample_map.json new file mode 100644 index 0000000000000000000000000000000000000000..4f219e5e66a7a8fa649e7db75eeb6ed532648a2f --- /dev/null +++ b/utils/Scene/sample_map.json @@ -0,0 +1,76 @@ +{ + "comments": "一个完整的地图Json应当包括如下的元素:精灵图集的信息,地图本身的地块,地图的大小", + "comments2": "地块对应的瓦片载入数据,单个瓦片的大小", + "comments3": "建筑物的列表和它们的数据描述.接下来是一个Sample:", + + "spriteInfos":[ + { + "unitName":"Set1", + "location":"Map/SampleFolder/SampleSprite", + "rows":2, + "column":2 + }, + { + "unitName":"Set2", + "location":"Map/SampleFolder/SampleSprite2", + "rows":2, + "column":2 + } + ], + "tileWidth":30, + "tileHeight":30, + "comments4":"请注意,这里的width和height表示的是在游戏地图上的地块大小", + + "mapWidth":10, + "mapHeight":5, + "mapInfos":[ + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"], + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"], + ["#", "#", "#", "#", "#", "#", ".", ".", "#", "#"], + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"], + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"] + ], + + "tileInfos":[ + { + "tileClass":"full_leaf_framework.Scene.Tile", + "comments6":"要初始化的瓦片对象名", + "tileName":"#", + "usedSprite":"Set1", + "usedFrameL":0, + "usedFrameR":0, + "frameDelay":0, + "startFrame":0 + }, + { + "tileClass":"full_leaf_framework.Scene.Tile", + "tileName":".", + "usedSprite":"Set2", + "usedFrameL":0, + "usedFrameR":0, + "frameDelay":0, + "startFrame":0, + "comments5":"认为瓦片中心为(0, 0),相对坐标啦" + } + ], + + "buildingInfos":[ + { + "buildingClass":"full_leaf_framework.Scene.Building", + "spriteInfo":{ + "location":"Map/SampleFolder/SampleSprite", + "rows":1, + "column":2, + "frameDelay":0.2, + "startFrame":0 + }, + "posX":50, + "posY":50, + "anchorPointX":0, + "anchorPointY":0, + "sizeScale":1, + "angle":0, + "layer":1 + } + ] +} \ No newline at end of file diff --git a/utils/Scene/test_map.json b/utils/Scene/test_map.json new file mode 100644 index 0000000000000000000000000000000000000000..b0e9de79fbf1f44eb4536c6bcc3ad47b60a31bd7 --- /dev/null +++ b/utils/Scene/test_map.json @@ -0,0 +1,69 @@ +{ + "spriteInfos":[ + { + "unitName":"coldColors", + "location":"TileMap/tiles1", + "rows":2, + "column":2 + }, + { + "unitName":"warmColors", + "location":"TileMap/tiles2", + "rows":2, + "column":2 + } + ], + "tileWidth":32, + "tileHeight":32, + + "mapWidth":10, + "mapHeight":5, + "mapInfos":[ + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"], + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"], + ["#", "#", ".", ".", "#", "#", ".", ".", "#", "#"], + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"], + ["#", "#", "#", "#", "#", "#", "#", "#", "#", "#"] + ], + + "tileInfos":[ + { + "tileClass":"full_leaf_framework.Scene.Tile", + "tileName":"#", + "usedSprite":"coldColors", + "usedFrameL":0, + "usedFrameR":3, + "frameDelay":0.5, + "startFrame":0 + }, + { + "tileClass":"full_leaf_framework.Scene.Tile", + "tileName":".", + "usedSprite":"warmColors", + "usedFrameL":0, + "usedFrameR":3, + "frameDelay":0.5, + "startFrame":1 + } + ], + + "buildingInfos":[ + { + "buildingClass":"full_leaf_framework.Scene.Building", + "spriteInfo":{ + "location":"TileMap/tilemap", + "rows":1, + "column":1, + "frameDelay":0, + "startFrame":0 + }, + "posX":0, + "posY":160, + "anchorPointX":-64, + "anchorPointY":-32, + "sizeScale":1, + "angle":0, + "layer":5 + } + ] +} \ No newline at end of file diff --git a/utils/Visual/AnimatedSprite.cs b/utils/Visual/AnimatedSprite.cs index 23f42a355ed9dae93fb0966205e795fd41b554ef..1ac8522829df1f02cca832d8bcdd593cb638b4a8 100644 --- a/utils/Visual/AnimatedSprite.cs +++ b/utils/Visual/AnimatedSprite.cs @@ -5,6 +5,7 @@ AnimatedSprite.cs */ using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace full_leaf_framework.Visual; @@ -30,6 +31,8 @@ public class AnimatedSprite { /// 当前对应帧 /// private int currentFrame; + public int CurrentFrame { get => currentFrame; + set => currentFrame = value; } /// /// 总帧数 /// @@ -123,6 +126,7 @@ public class AnimatedSprite { /// 锚点 /// 绘制附加效果 /// 旋转角度 + /// 缩放比值 public void Draw(SpriteBatch spriteBatch, Vector2 location, Vector2 anchorPoint, SpriteEffects effects = SpriteEffects.None, float angle = 0, float scale = 1) { int currentRow = currentFrame / columns; @@ -144,3 +148,39 @@ public class AnimatedSprite { } } + +/// +/// 动画信息对象 +/// +public class AnimationInfo { + + /// + /// 资源位置 + /// + public string location; + /// + /// 行数 + /// + public int rows; + /// + /// 列数 + /// + public int column; + /// + /// 帧间隔时间 + /// + public float frameDelay; + /// + /// 起始帧 + /// + public int startFrame; + + /// + /// 返回动画对象 + /// + public AnimatedSprite ReturnAnimation(ContentManager Content) { + return new AnimatedSprite(Content.Load(location), rows, + column, frameDelay, startFrame); + } + +} \ No newline at end of file diff --git a/utils/Visual/Camera.cs b/utils/Visual/Camera.cs index 54bdca7594fce567134d0788398b0e8e68405f95..62e84096a14ab19837b293d884753f319ef34480 100644 --- a/utils/Visual/Camera.cs +++ b/utils/Visual/Camera.cs @@ -185,9 +185,15 @@ public class Camera { changed_scale *= GetRangeRatio(); // 屏幕缩放的倍率 Vector2 draw_pos = ReturnScalePos(obj.pos); + // 当强制绘制时更改绘制帧 + int currentFrame = obj.currentAnimation.CurrentFrame; + if (obj.settledFrame != -1) { + obj.currentAnimation.CurrentFrame = obj.settledFrame; + } // 绘制的坐标(注:提前处理锚点,根据锚点更改绘制位置) obj.currentAnimation.Draw(spriteBatch, draw_pos, obj.anchorPoint, obj.effects, obj.angle, changed_scale); + obj.currentAnimation.CurrentFrame = currentFrame; } } \ No newline at end of file diff --git a/utils/Visual/Drawable.cs b/utils/Visual/Drawable.cs index 849584f30bff26e5eed8adf070c0158f8a3d1e20..3748a3c2315fa8763e4e1c1fce7383363cd747ed 100644 --- a/utils/Visual/Drawable.cs +++ b/utils/Visual/Drawable.cs @@ -47,6 +47,10 @@ public class Drawable { /// 绘制的优先级,越小越高,越容易绘制在底层 /// public int layer; + /// + /// 强制绘制动画的某一帧(-1时不强制,默认值) + /// + public int settledFrame = -1; /// /// 创建Drawable对象 @@ -59,7 +63,7 @@ public class Drawable { /// 动画在游戏内表现的实际大小的倍率 /// 绘制的优先级,越小越高,越容易绘制在底层 public Drawable(AnimatedSprite currentAnimation, Vector2 pos, Vector2 anchorPoint, float sizeScale, - float angle = 0f, SpriteEffects effects = SpriteEffects.None, int layer = 0) { + float angle = 0f, SpriteEffects effects = SpriteEffects.None, int layer = 10) { this.currentAnimation = currentAnimation; this.pos = pos; this.anchorPoint = anchorPoint;