-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainGame.cs
More file actions
88 lines (66 loc) · 2.44 KB
/
MainGame.cs
File metadata and controls
88 lines (66 loc) · 2.44 KB
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
using System;
using Adofai.Misc;
using Adofai.Render;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Adofai;
public class MainGame : Game {
public const float BpsC = 1f / 60f;
public static MainGame Game;
public delegate void UpdateEventD();
public static UpdateEventD StaticUpdateEvent;
public static UpdateEventD UpdateEvent;
public static UpdateEventD StaticDrawEvent;
public static UpdateEventD DrawEvent;
public static UpdateEventD StaticDrawHudEvent;
public static UpdateEventD DrawHudEvent;
public static GraphicsDeviceManager Graphics;
public static SpriteBatch SpriteBatch;
public static Color BackgroundColor;
private FPSCounter fpsCounter;
public MainGame() {
Game = this;
Graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
TargetElapsedTime = TimeSpan.FromSeconds(1f / 60f);
IsFixedTimeStep = false;
}
protected override void Initialize() {
fpsCounter = new FPSCounter();
ARender.Init();
StaticUpdateEvent += Keyboard.Update;
StaticUpdateEvent += Mouse.Update;
StaticUpdateEvent += fpsCounter.Update;
StaticDrawHudEvent += fpsCounter.Draw;
base.Initialize();
}
protected override void LoadContent() {
SpriteBatch = new SpriteBatch(GraphicsDevice);
for (int i = 0; i < ARender.Fonts.Length; i++) {
ARender.Fonts[i] = Content.Load<SpriteFont>("Fonts/Font" + i);
}
SceneLoader.LoadScene(new LoadingScene());
}
protected override void Update(GameTime gameTime) {
GTime.FromGameTime(gameTime);
StaticUpdateEvent?.Invoke();
UpdateEvent?.Invoke();
Camera.UpdateCamera(GraphicsDevice.Viewport);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(BackgroundColor);
ARender.DrawPre();
SpriteBatch.Begin(sortMode:SpriteSortMode.FrontToBack, transformMatrix:Camera.Transform);
DrawEvent?.Invoke();
StaticDrawEvent?.Invoke();
SpriteBatch.End();
ARender.DrawPre();
SpriteBatch.Begin(sortMode:SpriteSortMode.FrontToBack);
DrawHudEvent?.Invoke();
StaticDrawHudEvent?.Invoke();
SpriteBatch.End();
base.Draw(gameTime);
}
}