From 28e758400670f4f9ae116a820dd8ed18312ffec7 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 6 Aug 2019 16:33:49 +0200 Subject: [PATCH] added mlem.startup --- MLEM.Extended/MLEM.Extended.csproj | 4 ++ MLEM.Startup/MLEM.Startup.csproj | 30 ++++++++++++++ MLEM.Startup/MlemGame.cs | 64 ++++++++++++++++++++++++++++++ MLEM.sln | 6 +++ 4 files changed, 104 insertions(+) create mode 100644 MLEM.Startup/MLEM.Startup.csproj create mode 100644 MLEM.Startup/MlemGame.cs diff --git a/MLEM.Extended/MLEM.Extended.csproj b/MLEM.Extended/MLEM.Extended.csproj index 9bee67f..93d1c41 100644 --- a/MLEM.Extended/MLEM.Extended.csproj +++ b/MLEM.Extended/MLEM.Extended.csproj @@ -21,4 +21,8 @@ all + + + + \ No newline at end of file diff --git a/MLEM.Startup/MLEM.Startup.csproj b/MLEM.Startup/MLEM.Startup.csproj new file mode 100644 index 0000000..ee2e808 --- /dev/null +++ b/MLEM.Startup/MLEM.Startup.csproj @@ -0,0 +1,30 @@ + + + + netstandard2.0 + + + + Ellpeck + A startup GameImpl class that uses (M)LEM (L)ibrary by (E)llpeck for (M)onoGame as well as some other useful stuff + monogame ellpeck mlem utility extensions + https://github.com/Ellpeck/MLEM + https://github.com/Ellpeck/MLEM + https://github.com/Ellpeck/MLEM/blob/master/LICENSE + 1.0.0 + + + + + + + + all + + + + + + + + diff --git a/MLEM.Startup/MlemGame.cs b/MLEM.Startup/MlemGame.cs new file mode 100644 index 0000000..cba95a9 --- /dev/null +++ b/MLEM.Startup/MlemGame.cs @@ -0,0 +1,64 @@ +using Coroutine; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using MonoGame.Extended; +using MonoGame.Extended.Input; + +namespace MLEM.Startup { + public class MlemGame : Game { + + private static MlemGame instance; + public static KeyboardStateExtended Keyboard => instance.keyboardState; + public static MouseStateExtended Mouse => instance.mouseState; + + public readonly GraphicsDeviceManager GraphicsDeviceManager; + public SpriteBatch SpriteBatch { get; private set; } + + private KeyboardStateExtended keyboardState; + private MouseStateExtended mouseState; + + public MlemGame(int windowWidth = 1280, int windowHeight = 720, bool vsync = false, bool allowResizing = true, string contentDir = "Content") { + instance = this; + this.GraphicsDeviceManager = new GraphicsDeviceManager(this) { + PreferredBackBufferWidth = windowWidth, + PreferredBackBufferHeight = windowHeight, + SynchronizeWithVerticalRetrace = vsync + }; + this.Content.RootDirectory = contentDir; + + this.Window.AllowUserResizing = allowResizing; + this.Window.ClientSizeChanged += (win, args) => this.OnWindowSizeChange(this.GraphicsDevice.Viewport); + this.Window.TextInput += (win, args) => this.OnTextInput(args.Key, args.Character); + } + + public virtual void OnWindowSizeChange(Viewport viewport) { + } + + public virtual void OnTextInput(Keys key, char character) { + } + + protected override void LoadContent() { + this.SpriteBatch = new SpriteBatch(this.GraphicsDevice); + } + + protected override void Initialize() { + base.Initialize(); + this.OnWindowSizeChange(this.GraphicsDevice.Viewport); + } + + protected override void Update(GameTime gameTime) { + base.Update(gameTime); + + CoroutineHandler.Tick(gameTime.GetElapsedSeconds()); + + this.keyboardState = KeyboardExtended.GetState(); + this.mouseState = MouseExtended.GetState(); + } + + public static T LoadContent(string name) { + return instance.Content.Load(name); + } + + } +} \ No newline at end of file diff --git a/MLEM.sln b/MLEM.sln index 9b803e2..b0d646a 100644 --- a/MLEM.sln +++ b/MLEM.sln @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM", "MLEM\MLEM.csproj", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Extended", "MLEM.Extended\MLEM.Extended.csproj", "{232A6513-A28C-4D7F-BA5A-89281BFC1538}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Startup", "MLEM.Startup\MLEM.Startup.csproj", "{997F4739-7BEC-4621-B9CA-68DEB2D74412}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +20,9 @@ Global {232A6513-A28C-4D7F-BA5A-89281BFC1538}.Debug|Any CPU.Build.0 = Debug|Any CPU {232A6513-A28C-4D7F-BA5A-89281BFC1538}.Release|Any CPU.ActiveCfg = Release|Any CPU {232A6513-A28C-4D7F-BA5A-89281BFC1538}.Release|Any CPU.Build.0 = Release|Any CPU + {997F4739-7BEC-4621-B9CA-68DEB2D74412}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {997F4739-7BEC-4621-B9CA-68DEB2D74412}.Debug|Any CPU.Build.0 = Debug|Any CPU + {997F4739-7BEC-4621-B9CA-68DEB2D74412}.Release|Any CPU.ActiveCfg = Release|Any CPU + {997F4739-7BEC-4621-B9CA-68DEB2D74412}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal