-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCludoGame.cs
143 lines (122 loc) · 4.81 KB
/
CludoGame.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#region
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using CludoEngine.Graphics;
using Microsoft.Xna.Framework.Content;
#endregion
namespace CludoEngine {
public class CludoGame : Game {
public GraphicsDeviceManager Graphics;
public SpriteBatch SpriteBatch;
public static CludoGame CurrentGame;
public CludoGame() {
CludoGame.CurrentGame = this;
Graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
SceneTypes = new Dictionary<string, Type>();
LoadedScenes = new Dictionary<string, Scene>();
Graphics.PreparingDeviceSettings += Graphics_PreparingDeviceSettings;
}
public static Scene CurrentScene { get; set; }
public Dictionary<string, Scene> LoadedScenes { get; set; }
private Dictionary<string, Type> SceneTypes { get; set; }
private void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) {
e.GraphicsDeviceInformation.PresentationParameters.PresentationInterval = PresentInterval.Two;
}
/// <summary>
/// Adds a Scene Type. This is then used with LoadScene to load a Scene and then SetScene to set the current Scene.
/// </summary>
/// <param name="scene"></param>
/// <param name="name"></param>
public void AddScene(Type scene, string name) {
SceneTypes.Add(name, scene);
}
/// <summary>
/// Adds a Scene Type. This is then used with LoadScene to load a Scene and then SetScene to set the current Scene.
/// </summary>
/// <param name="scene"></param>
/// <param name="name"></param>
public void AddScene(Scene scene, string name) {
SceneTypes.Add(name, typeof(Scene));
}
/// <summary>
/// Disposes of a Scene.
/// </summary>
/// <param name="name"></param>
public void DisposeScene(string name) {
if (CurrentScene == LoadedScenes[name]) {
CurrentScene = null;
}
LoadedScenes[name].Dispose();
LoadedScenes.Remove(name);
}
/// <summary>
/// Loads a Scene from Scene Types. Use Set scene for already Loaded Scenes.
/// </summary>
public Scene LoadScene(string sceneTypeName, string newSceneName) {
var a =
(Scene)
Activator.CreateInstance(SceneTypes[sceneTypeName], SpriteBatch, Graphics, GraphicsDevice, Window,
Content, 1080, 720);
LoadedScenes.Add(newSceneName, a);
return a;
}
/// <summary>
/// Loads a Scene from Scene Types. Use Set scene for already Loaded Scenes.
/// </summary>
/// <param name="name"></param>
public Scene LoadScene(string name) {
return LoadScene(name, name);
}
/// <summary>
/// Sets the current Scene. Must be a already loaded Scene.
/// </summary>
/// <param name="loadedSceneName"></param>
public void SetScene(string loadedSceneName) {
CurrentScene = LoadedScenes[loadedSceneName];
}
/// <summary>
/// Loads and sets a Scene from Scene Types. Use Set scene for already Loaded Scenes.
/// </summary>
public Scene LoadAndSetScene(string sceneTypeName, string newSceneName) {
var a =
(Scene)
Activator.CreateInstance(SceneTypes[sceneTypeName], SpriteBatch, Graphics, GraphicsDevice, Window,
Content, 1080,720);
LoadedScenes.Add(newSceneName, a);
SetScene(newSceneName);
return a;
}
/// <summary>
/// Loads and sets a Scene from Scene Types. Use Set scene for already Loaded Scenes.
/// </summary>
public Scene LoadAndSetScene(string sceneTypeName) {
var a =
LoadAndSetScene(sceneTypeName, sceneTypeName);
return a;
}
public virtual void StartGame() {
}
protected override void Draw(GameTime gameTime) {
base.Draw(gameTime);
if (CurrentScene != null) {
CurrentScene.DrawSystem.Draw(SpriteBatch);
}
}
protected override void Initialize() {
base.Initialize();
}
protected override void LoadContent() {
SpriteBatch = new SpriteBatch(GraphicsDevice);
StartGame();
}
protected override void Update(GameTime gameTime) {
base.Update(gameTime);
if (CurrentScene != null) {
CurrentScene.Update(gameTime);
}
}
}
}