mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
68 lines
No EOL
2.4 KiB
C#
68 lines
No EOL
2.4 KiB
C#
using Coroutine;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using MLEM.Input;
|
|
using MonoGame.Extended;
|
|
|
|
namespace MLEM.Startup {
|
|
public class MlemGame : Game {
|
|
|
|
private static MlemGame instance;
|
|
public static InputHandler Input => instance.InputHandler;
|
|
|
|
public readonly GraphicsDeviceManager GraphicsDeviceManager;
|
|
public SpriteBatch SpriteBatch { get; protected set; }
|
|
public InputHandler InputHandler { get; protected set; }
|
|
|
|
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);
|
|
this.InputHandler = new InputHandler();
|
|
}
|
|
|
|
protected override void Initialize() {
|
|
base.Initialize();
|
|
this.OnWindowSizeChange(this.GraphicsDevice.Viewport);
|
|
}
|
|
|
|
protected override void Update(GameTime gameTime) {
|
|
base.Update(gameTime);
|
|
|
|
if (this.InputHandler != null)
|
|
this.InputHandler.Update();
|
|
|
|
CoroutineHandler.Tick(gameTime.GetElapsedSeconds());
|
|
CoroutineHandler.RaiseEvent(CoroutineEvents.Update);
|
|
}
|
|
|
|
protected override void Draw(GameTime gameTime) {
|
|
base.Draw(gameTime);
|
|
CoroutineHandler.RaiseEvent(CoroutineEvents.Draw);
|
|
}
|
|
|
|
public static T LoadContent<T>(string name) {
|
|
return instance.Content.Load<T>(name);
|
|
}
|
|
|
|
}
|
|
} |