diff options
| author | BoredGuy <osome3717@gmail.com> | 2026-02-08 09:39:24 +0300 |
|---|---|---|
| committer | BoredGuy <osome3717@gmail.com> | 2026-02-08 09:39:24 +0300 |
| commit | b6b40402db89b407365e70a0f0562a52b1667def (patch) | |
| tree | 8ffab05ff1d32fd2737cac08df7af0e096b67f1a | |
| parent | 26e3456fa560a90638da0c4d35d6a19d6b88a4a3 (diff) | |
| -rw-r--r-- | Assets/atlas.png | bin | 0 -> 590 bytes | |||
| -rw-r--r-- | DungeonSlime/Content/atlas-definition.xml | 8 | ||||
| -rw-r--r-- | DungeonSlime/DungeonSlime.sln | 24 | ||||
| -rw-r--r-- | MonoGameLibrary/Graphics/TextureAtlas.cs | 89 | ||||
| -rw-r--r-- | MonoGameLibrary/Graphics/TextureRegion.cs | 75 | ||||
| -rw-r--r-- | MonoGameLibrary/MonoGameLibrary.sln | 24 | ||||
| -rw-r--r-- | debug.log | 6 |
7 files changed, 226 insertions, 0 deletions
diff --git a/Assets/atlas.png b/Assets/atlas.png Binary files differnew file mode 100644 index 0000000..7238c84 --- /dev/null +++ b/Assets/atlas.png diff --git a/DungeonSlime/Content/atlas-definition.xml b/DungeonSlime/Content/atlas-definition.xml new file mode 100644 index 0000000..f01b22b --- /dev/null +++ b/DungeonSlime/Content/atlas-definition.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?>
+<TextureAtlas>
+ <Texture>images/atlas</Texture>
+ <Regions>
+ <Region name="slime" x="0" y="0" width="20" height="20" />
+ <Region name="bat" x="20" y="20" width="20" height="20" />
+ </Regions>
+</TextureAtlas>
diff --git a/DungeonSlime/DungeonSlime.sln b/DungeonSlime/DungeonSlime.sln new file mode 100644 index 0000000..889cfa5 --- /dev/null +++ b/DungeonSlime/DungeonSlime.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.2.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DungeonSlime", "DungeonSlime.csproj", "{ED6B5FFA-0E1C-4BCE-D08B-69CC2DE9576F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {ED6B5FFA-0E1C-4BCE-D08B-69CC2DE9576F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {ED6B5FFA-0E1C-4BCE-D08B-69CC2DE9576F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {ED6B5FFA-0E1C-4BCE-D08B-69CC2DE9576F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {ED6B5FFA-0E1C-4BCE-D08B-69CC2DE9576F}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {42753E4D-C659-4169-8241-E80D6AD14A92}
+ EndGlobalSection
+EndGlobal
diff --git a/MonoGameLibrary/Graphics/TextureAtlas.cs b/MonoGameLibrary/Graphics/TextureAtlas.cs new file mode 100644 index 0000000..751c341 --- /dev/null +++ b/MonoGameLibrary/Graphics/TextureAtlas.cs @@ -0,0 +1,89 @@ +using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Xml;
+using System.Xml.Linq;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace MonoGameLibrary.Graphics;
+
+public class TextureAtlas
+{
+ private Dictionary<string, TextureRegion> _regions;
+ public Texture2D Texture { get; set; }
+
+ public TextureAtlas()
+ {
+ _regions = [];
+ }
+
+ public TextureAtlas(Texture2D texture)
+ {
+ Texture = texture;
+ _regions = [];
+ }
+
+ public void AddRegion(string name, int x, int y, int width, int height)
+ {
+ TextureRegion region = new TextureRegion(Texture, x, y, width, height);
+ _regions.Add(name, region);
+ }
+
+ public TextureRegion GetRegion(string name)
+ {
+ return _regions[name];
+ }
+
+ public bool RemoveRegion(string name)
+ {
+ return _regions.Remove(name);
+ }
+
+ public void Clear()
+ {
+ _regions.Clear();
+ }
+
+ public static TextureAtlas FromFile(ContentManager content, string fileName)
+ {
+ TextureAtlas atlas = new TextureAtlas();
+
+ string filePath = Path.Combine(content.RootDirectory, fileName);
+
+ using (Stream stream = TitleContainer.OpenStream(filePath))
+ {
+ using (XmlReader reader = XmlReader.Create(stream))
+ {
+ XDocument doc = XDocument.Load(reader);
+ XElement root = doc.Root;
+
+ string texturePath = root.Element("Texture").Value;
+ atlas.Texture = content.Load<Texture2D>(texturePath);
+
+ var regions = root.Element("Regions")?.Elements("Region");
+
+ if (regions != null)
+ {
+ foreach (var region in regions)
+ {
+ string name = region.Attribute("name")?.Value;
+ int x = int.Parse(region.Attribute("x")?.Value ?? "0");
+ int y = int.Parse(region.Attribute("y")?.Value ?? "0");
+ int width = int.Parse(region.Attribute("width")?.Value ?? "0");
+ int height = int.Parse(region.Attribute("height")?.Value ?? "0");
+
+ if (!string.IsNullOrEmpty(name))
+ {
+ atlas.AddRegion(name, x, y, width, height);
+ }
+ }
+ }
+ }
+ }
+
+ return atlas;
+ }
+}
\ No newline at end of file diff --git a/MonoGameLibrary/Graphics/TextureRegion.cs b/MonoGameLibrary/Graphics/TextureRegion.cs new file mode 100644 index 0000000..f03097c --- /dev/null +++ b/MonoGameLibrary/Graphics/TextureRegion.cs @@ -0,0 +1,75 @@ +using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace MonoGameLibrary.Graphics;
+
+///<summary>
+/// Represents a rectangular region within a texture
+///</summary>
+public class TextureRegion
+{
+ /// <summary>
+ /// Gets or Sets the source texture this texture region is part of
+ /// </summary>
+ public Texture2D Texture { get; set; }
+
+ /// <summary>
+ /// Gets or Sets the source rectangle boundary of this texture region within the source texture
+ /// </summary>
+ public Rectangle SourceRectangle { get; set; }
+
+ /// <summary>
+ /// Gets the width, in pixels, of this texture region
+ /// </summary>
+ public int Width => SourceRectangle.Width;
+
+ /// <summary>
+ /// Gets the height, in pixels, of this texture region/
+ /// </summary>
+ public int Height => SourceRectangle.Height;
+
+ /// <summary>
+ /// Creates a new texture region.
+ /// </summary>
+ public TextureRegion() { }
+
+ public TextureRegion(Texture2D texture, int x, int y, int width, int height)
+ {
+ Texture = texture;
+ SourceRectangle = new Rectangle(x, y, width, height);
+ }
+
+ public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color)
+ {
+ Draw(spriteBatch, position, color, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.0f);
+ }
+
+ public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
+ {
+ Draw(
+ spriteBatch,
+ position,
+ color,
+ rotation,
+ origin,
+ new Vector2(scale, scale),
+ effects,
+ layerDepth
+ );
+ }
+
+ public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
+ {
+ spriteBatch.Draw(
+ Texture,
+ position,
+ SourceRectangle,
+ color,
+ rotation,
+ origin,
+ scale,
+ effects,
+ layerDepth
+ );
+ }
+}
\ No newline at end of file diff --git a/MonoGameLibrary/MonoGameLibrary.sln b/MonoGameLibrary/MonoGameLibrary.sln new file mode 100644 index 0000000..108213b --- /dev/null +++ b/MonoGameLibrary/MonoGameLibrary.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.2.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGameLibrary", "MonoGameLibrary.csproj", "{0E52B038-7007-E89F-D8DA-A8C72068ADEB}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {0E52B038-7007-E89F-D8DA-A8C72068ADEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E52B038-7007-E89F-D8DA-A8C72068ADEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0E52B038-7007-E89F-D8DA-A8C72068ADEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0E52B038-7007-E89F-D8DA-A8C72068ADEB}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {0D147C50-ABFF-4D82-A12C-2AC364F5BC91}
+ EndGlobalSection
+EndGlobal
diff --git a/debug.log b/debug.log new file mode 100644 index 0000000..8153152 --- /dev/null +++ b/debug.log @@ -0,0 +1,6 @@ +[0203/214753.867:ERROR:third_party\crashpad\crashpad\util\win\registration_protocol_win.cc:108] CreateFile: The system cannot find the file specified. (0x2) +[0203/214754.500:ERROR:third_party\crashpad\crashpad\util\win\registration_protocol_win.cc:108] CreateFile: The system cannot find the file specified. (0x2) +[0206/093842.013:ERROR:third_party\crashpad\crashpad\util\win\registration_protocol_win.cc:108] CreateFile: The system cannot find the file specified. (0x2) +[0206/093842.415:ERROR:third_party\crashpad\crashpad\util\win\registration_protocol_win.cc:108] CreateFile: The system cannot find the file specified. (0x2) +[0206/093842.867:ERROR:third_party\crashpad\crashpad\util\win\registration_protocol_win.cc:108] CreateFile: The system cannot find the file specified. (0x2) +[0206/093843.336:ERROR:third_party\crashpad\crashpad\util\win\registration_protocol_win.cc:108] CreateFile: The system cannot find the file specified. (0x2) |
