-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlatformerGame.cs
194 lines (150 loc) · 4.31 KB
/
PlatformerGame.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using FNAEngine2D;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Platformer.Levels;
using Platformer.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Platformer
{
/// <summary>
/// Game de Platformer
/// </summary>
public class PlatformerGame : GameObject, IUpdate
{
/// <summary>
/// Curent level
/// </summary>
public LevelScene Level;
/// <summary>
/// Camera for the UI
/// </summary>
public Camera UICamera;
/// <summary>
/// Camera for the Minimap
/// </summary>
public Camera MinimapCamera;
/// <summary>
/// Current Player
/// </summary>
public Player Player;
/// <summary>
/// Current room
/// </summary>
public string CurrentRoom { get; private set; } = "level1";
/// <summary>
/// Previous room
/// </summary>
public string PreviousRoom { get; private set; } = "start";
/// <summary>
/// Constructeur
/// </summary>
public PlatformerGame()
{
}
/// <summary>
/// Restart le level...
/// </summary>
public void ReloadRoom()
{
//Clearup de scene...
RemoveAll();
//Add the level...
Level = Add(new LevelScene(this.CurrentRoom));
//UI!
Add(new UI.HUD());
this.Mouse.HideMouse();
}
/// <summary>
/// Restart le level...
/// </summary>
public void Continue()
{
Remove(typeof(UI.EscapeMenu));
Level.PausedSelf = false;
this.Mouse.HideMouse();
}
/// <summary>
/// On a gagné!
/// </summary>
public void Win()
{
Level.PausedSelf = true;
if (Find<UI.Win>() == null)
Add(new UI.Win());
}
/// <summary>
/// GameOver
/// </summary>
public void GameOver()
{
Level.PausedSelf = true;
if(this.Player != null)
this.Player.Destroy();
if(Find<UI.GameOver>() == null)
Add(new UI.GameOver());
}
/// <summary>
/// Load a room
/// </summary>
public void LoadRoom(string room)
{
PreviousRoom = CurrentRoom;
CurrentRoom = room;
ReloadRoom();
}
/// <summary>
/// Chargement du contenu
/// </summary>
protected override void Load()
{
SetupCamera();
ReloadRoom();
}
/// <summary>
/// Update of PlatformerGame
/// </summary>
public void Update()
{
if (Input.IsKeyPressed(Keys.Escape))
{
if (Find<UI.EscapeMenu>() == null)
{
Level.PausedSelf = true;
Add(new UI.EscapeMenu());
}
else
{
Continue();
}
}
}
/// <summary>
/// Setup cameras
/// </summary>
private void SetupCamera()
{
this.Game.ResetCameras();
//Main camera that follow the player...
this.Game.MainCamera.LayerMask = Layers.Layer1;
//UI camera...
Camera uiCamera = new Camera(this.Game.Width, this.Game.Height);
uiCamera.LayerMask = Layers.Layer2;
this.Game.AddCamera(uiCamera);
this.UICamera = uiCamera;
//For the minimap...
//int minimapSize = 100;
//Camera cameraMinimap = new Camera();
//cameraMinimap.LayerMask = Layers.Layer1;
//GameHost.ExtraCameras.Add(cameraMinimap);
//cameraMinimap.ViewLocation = new Point(GameHost.Width - (minimapSize + 10), 10);
//cameraMinimap.Size = new Point(minimapSize, minimapSize);
////cameraMinimap.Zoom = ((float)minimapSize / GameHost.Height);
//cameraMinimap.Zoom = 0.2f;
}
}
}