summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--DungeonSlime.slnx1
-rw-r--r--DungeonSlime/DungeonSlime.csproj3
-rw-r--r--MonoGameLibrary/Core.cs48
-rw-r--r--MonoGameLibrary/Game1.cs51
4 files changed, 52 insertions, 51 deletions
diff --git a/DungeonSlime.slnx b/DungeonSlime.slnx
index a9dd5e2..8fb9d3c 100644
--- a/DungeonSlime.slnx
+++ b/DungeonSlime.slnx
@@ -1,3 +1,4 @@
<Solution>
<Project Path="DungeonSlime/DungeonSlime.csproj" />
+ <Project Path="MonoGameLibrary/MonoGameLibrary.csproj" />
</Solution>
diff --git a/DungeonSlime/DungeonSlime.csproj b/DungeonSlime/DungeonSlime.csproj
index 8f1c2ed..28956cb 100644
--- a/DungeonSlime/DungeonSlime.csproj
+++ b/DungeonSlime/DungeonSlime.csproj
@@ -26,4 +26,7 @@
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.*" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.*" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\MonoGameLibrary\MonoGameLibrary.csproj" />
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/MonoGameLibrary/Core.cs b/MonoGameLibrary/Core.cs
new file mode 100644
index 0000000..9e4c9e3
--- /dev/null
+++ b/MonoGameLibrary/Core.cs
@@ -0,0 +1,48 @@
+using System;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace MonoGameLibrary;
+
+public class Core : Game {
+ internal static Core s_instance;
+
+ public static Core Instance => s_instance;
+
+ public static GraphicsDeviceManager Graphics { get; set; }
+ public static new GraphicsDevice GraphicsDevice { get; private set; }
+ public static SpriteBatch SpriteBatch { get; private set; }
+ public static new ContentManager Content { get; private set; }
+
+ public Core(string title, int width, int height, bool fullscreen) {
+ if (s_instance != null) {
+ throw new InvalidOperationException($"Only a single Core instance can be created");
+ }
+
+ s_instance = this;
+
+ Graphics = new GraphicsDeviceManager(this);
+
+ Graphics.PreferredBackBufferWidth = width;
+ Graphics.PreferredBackBufferHeight = height;
+ Graphics.IsFullScreen = fullscreen;
+
+ Graphics.ApplyChanges();
+
+ Window.Title = title;
+
+ Content = base.Content;
+
+ Content.RootDirectory = "Content";
+
+ IsMouseVisible = true;
+ }
+
+ protected override void Initialize() {
+ base.Initialize();
+
+ GraphicsDevice = base.GraphicsDevice;
+ SpriteBatch = new SpriteBatch(GraphicsDevice);
+ }
+}
diff --git a/MonoGameLibrary/Game1.cs b/MonoGameLibrary/Game1.cs
deleted file mode 100644
index 49937ae..0000000
--- a/MonoGameLibrary/Game1.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-using Microsoft.Xna.Framework.Input;
-
-namespace MonoGameLibrary;
-
-public class Game1 : Game
-{
- private GraphicsDeviceManager _graphics;
- private SpriteBatch _spriteBatch;
-
- public Game1()
- {
- _graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- IsMouseVisible = true;
- }
-
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
-
- base.Initialize();
- }
-
- protected override void LoadContent()
- {
- _spriteBatch = new SpriteBatch(GraphicsDevice);
-
- // TODO: use this.Content to load your game content here
- }
-
- protected override void Update(GameTime gameTime)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
-
- // TODO: Add your update logic here
-
- base.Update(gameTime);
- }
-
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
-
- // TODO: Add your drawing code here
-
- base.Draw(gameTime);
- }
-}