-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainGame.cs
93 lines (80 loc) · 3.36 KB
/
MainGame.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Swing.Engine;
using System;
using Microsoft.Xna.Framework.Audio;
using tainicom.Aether.Physics2D.Diagnostics;
using tainicom.Aether.Physics2D.Dynamics;
using Swing.Engine.StateManagement;
using Swing.Screens;
using Microsoft.Xna.Framework.Media;
namespace Swing
{
public class MainGame : Microsoft.Xna.Framework.Game
{
public static MainGame Instance { get; private set; }
public SpriteBatch SpriteBatch { get; private set; }
public int DisplayWidth => _graphics.PreferredBackBufferWidth;
public int DisplayHeight => _graphics.PreferredBackBufferHeight;
public World World { get; private set; }
public Matrix PhysicsProjectionMatrix { get; private set; }
public Matrix ViewMatrix { get; private set; }
public Matrix StandardTransformMatrix { get; private set; }
public DebugView DebugView { get; private set; }
public ScreenManager ScreenManager { get; private set; }
public int Deaths { get; set; }
public TimeSpan RunTime { get; set; }
/// <summary>
/// Pixels are 1 / PhysicsScale meters
/// </summary>
public static readonly float PhysicsScale = 10;
private GraphicsDeviceManager _graphics;
public MainGame()
{
_graphics = new GraphicsDeviceManager(this);
_graphics.PreferredBackBufferWidth = 1920;
_graphics.PreferredBackBufferHeight = 1080;
_graphics.IsFullScreen = true;
//Window.IsBorderless = true;
Content.RootDirectory = "Content";
IsMouseVisible = true;
Window.Title = "Swing";
SoundEffect.MasterVolume = 0.5f;
MediaPlayer.Volume = 0.5f;
Instance = this;
}
protected override void Initialize()
{
World = new World(Vector2.UnitY * -10 * PhysicsScale);
DebugView = new DebugView(World);
DebugView.DefaultShapeColor = Color.White;
DebugView.SleepingShapeColor = Color.LightGray;
DebugView.LoadContent(GraphicsDevice, Content);
if (Debug.DISPLAY_COLLIDERS)
{
DebugView.AppendFlags(DebugViewFlags.DebugPanel);
}
ScreenManager = new ScreenManager(this, new GameScreen[] { new Background(), new MainMenu() });
Components.Add(ScreenManager);
PhysicsProjectionMatrix = Matrix.CreateOrthographicOffCenter(0, DisplayWidth, DisplayHeight, 0, 0, -100) *
Matrix.CreateScale(PhysicsScale, -PhysicsScale, 1) *
Matrix.CreateTranslation(PhysicsScale, PhysicsScale, 0);
StandardTransformMatrix = Matrix.CreateTranslation(DisplayWidth / 2, -DisplayHeight / 2, 0) * Matrix.CreateScale(1, -1f, 1);
ViewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);
base.Initialize();
}
protected override void LoadContent()
{
SpriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
}
}
}