Files
MonoGame.Extended/Source/Demos/Sandbox/GameMain.cs
T
2018-06-28 23:20:08 +10:00

62 lines
1.6 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended.BitmapFonts;
using MonoGame.Extended.Entities;
using Sandbox.Systems;
namespace Sandbox
{
public class MainGame : Game
{
// ReSharper disable once NotAccessedField.Local
private GraphicsDeviceManager _graphicsDeviceManager;
private SpriteBatch _spriteBatch;
private World _world;
public MainGame()
{
_graphicsDeviceManager = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void LoadContent()
{
var font = Content.Load<BitmapFont>("Sensation");
_spriteBatch = new SpriteBatch(GraphicsDevice);
_world = new WorldBuilder()
.AddSystem(new RainfallSystem())
.AddSystem(new ExpirySystem())
.AddSystem(new RenderSystem(GraphicsDevice))
.AddSystem(new HudSystem(GraphicsDevice, font))
.Build();
}
protected override void UnloadContent()
{
_spriteBatch.Dispose();
}
protected override void Update(GameTime gameTime)
{
var keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown(Keys.Escape))
Exit();
_world.Update(gameTime);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
_world.Draw(gameTime);
base.Draw(gameTime);
}
}
}