/
LevelStoryState.cs
275 lines (230 loc) · 9.55 KB
/
LevelStoryState.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
using System;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using Engine;
using OpenTK.Input;
using System.Drawing;
// XML parser
using System.Xml;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
using System.Timers;
using QuickFont;
namespace U5Designs
{
class LevelStoryState : GameState
{
internal GameEngine eng;
protected Vector3 eye, lookat;
Obstacle background;
PlayState _ps;
Texture _p1, _p2, _p3, _p4;
double curFrame;
bool escapedown;
internal int cur_page;
// Fonts
internal QFont button, credit;
double cnt;
Texture bg;
int _cur_butn = 0;
private int numOfButtons = 2;
int lvl;
OpenTK.Input.KeyboardState _old_state;
public bool enterdown;
String level_1 = "With the defeat of the Zoo Keeper our hero finally escapes the Zoo. He now finds himself in a mysterious Jungle. With no going back he pushes onward into the unknown...";
String credits = "Game Finished\nThanks For Playing\n\n\nDylan Riddle - Game Designer\nKendal Gifford - Game Designer\nSeth Walsh - Game Designer\nStephen Lu - Game Designer\nKacy Shearer - Artist\nRae Montilla - Artist\n\n(Press Enter to return to Main Menu)";
// End Fonts
public LevelStoryState(GameEngine engine, int lvl_being_loaded)
{
cur_page = 0;
eng = engine;
// _ps = ps;
lookat = new Vector3(0, 0, 2);
eye = new Vector3(0, 0, 5);
lvl = lvl_being_loaded;
// QFont
//Assembly assembly = Assembly.GetExecutingAssembly();
//eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png"));
//bg = eng.StateTextureManager.GetTexture("menu");
credit = QFont.FromQFontFile("Fonts/myStoryWhite.qfont", new QFontLoaderConfiguration(true, false));
credit.Options.DropShadowActive = false;
button = QFont.FromQFontFile("Fonts/myStoryBright.qfont", new QFontLoaderConfiguration(true, false));
button.Options.DropShadowActive = true;
// Set the current image to be displayed at 0 which is the first in the sequence
curFrame = 0.0;
}
public override void MakeActive()
{
GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Fonts
GL.Disable(EnableCap.Lighting);
GL.Disable(EnableCap.Light0);
// Fonts
GL.MatrixMode(MatrixMode.Projection);
Matrix4d projection = Matrix4d.CreateOrthographic(1280, 720, 1.0f, 6400.0f);
GL.LoadMatrix(ref projection);
if (eng.Keyboard[Key.Escape])
{
escapedown = true;
}
}
public override void Update(FrameEventArgs e)
{
// Deal with user input from either the keyboard or the mouse
cnt += e.Time; // Fonts
DealWithInput();
}
public override void Draw(FrameEventArgs e)
{
GL.Clear(ClearBufferMask.AccumBufferBit | ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
GL.ClearColor(0.1f, 0.1f, 0.1f, 0.1f);
Matrix4 modelview = Matrix4.LookAt(eye, lookat, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);
curFrame = (curFrame + e.Time * 2) % 4;
// Fonts
GL.Disable(EnableCap.DepthTest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);
//bg.Draw2DTexture();
drawButtons();
// Fonts
GL.Enable(EnableCap.DepthTest);
}
/// <summary>
/// Called by mouse or keyboard handlers when the user picked a button (by clicking or hitting enter)
/// </summary>
internal void handleButtonPress()
{
if (lvl == eng.max_level)
{
MainMenuState ms = new MainMenuState(eng);
eng.ChangeState(ms);
}
else
{
// Go to next level
MainMenuState ms = new MainMenuState(eng);
PlayState ps = new PlayState(eng, ms, lvl);
LoadScreenState ls = new LoadScreenState(eng, ps, lvl);
eng.ChangeState(ls);
}
}
// Draw stuff
public void drawButtons()
{
GL.PushMatrix();
GL.Translate(new Vector3(0, 350, 0));
GL.Scale(1, -1, 1);
float yOffset = 0;
// Credits
if (lvl == 2)
{
PrintWithBounds(credit, credits, new RectangleF(-0, 10, 1280, 300), QFontAlignment.Centre, ref yOffset);
}
else
{
yOffset = 720 / (button.Measure("S").Height + 10);
// Draw non highlighted string
button.Options.DropShadowActive = true;
PrintWithBounds(button, level_1, new RectangleF(-530, 10, 1060, 300), QFontAlignment.Left, ref yOffset);
}
yOffset += yOffset;
GL.PopMatrix();
}
private void PrintWithBounds(QFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset)
{
GL.Disable(EnableCap.Texture2D);
GL.Color4(1.0f, 0f, 0f, 1.0f);
float maxWidth = bounds.Width;
float height = font.Measure(text, maxWidth, alignment).Height;
GL.Begin(BeginMode.LineLoop);
GL.Vertex3(bounds.X, bounds.Y, 0f);
GL.Vertex3(bounds.X + bounds.Width, bounds.Y, 0f);
GL.Vertex3(bounds.X + bounds.Width, bounds.Y + height, 0f);
GL.Vertex3(bounds.X, bounds.Y + height, 0f);
GL.End();
font.Print(text, maxWidth, alignment, new Vector2(bounds.X, bounds.Y));
// Print ENTER
string s = "[ Press Enter ]";
font.Print(s, maxWidth, alignment, new Vector2(-bounds.X - (font.Measure(s).Width + 10), bounds.Height + 2 * font.Measure(text).Height));
//font.Print(s, maxWidth, QFontAlignment.Right, new Vector2(bounds.X + bounds.Width - font.Measure(s).Height, bounds.Y + bounds.Height - font.Measure(s).Height));
yOffset += height;
}
private void DealWithInput()
{
// Fonts
// Testing buttons
OpenTK.Input.KeyboardState _new_state = OpenTK.Input.Keyboard.GetState();
if ((_new_state.IsKeyDown(Key.Down) && !_old_state.IsKeyDown(Key.Down)) ||
(_new_state.IsKeyDown(Key.S) && !_old_state.IsKeyDown(Key.S)))
{
// Down key was just pressed
if (_cur_butn < numOfButtons)
{
// Increment the current button index so you draw the highlighted button of the next button
_cur_butn += 1;
eng.selectSound.Play();
}
else if (_cur_butn >= numOfButtons)
{
// Were on the last button in the list so reset to the top of the button list
_cur_butn = 0;
eng.selectSound.Play();
}
}
if ((_new_state.IsKeyDown(Key.Up) && !_old_state.IsKeyDown(Key.Up)) ||
(_new_state.IsKeyDown(Key.W) && !_old_state.IsKeyDown(Key.W)))
{
// Down key was just pressed
if (_cur_butn > 0)
{
// Increment the current button index so you draw the highlighted button of the next button
_cur_butn -= 1;
eng.selectSound.Play();
}
else if (_cur_butn <= 0)
{
// Were on the last button in the list so reset to the top of the button list
_cur_butn = numOfButtons;
eng.selectSound.Play();
}
}
_old_state = _new_state;
if (eng.Keyboard[Key.Escape] && !escapedown)
{
eng.Exit();
}
else if (!eng.Keyboard[Key.Escape])
{
escapedown = false;
}
//********************** enter
if (eng.Keyboard[Key.Enter] && !enterdown)
{
enterdown = true;
handleButtonPress();
// Move to next page
if (cur_page < 3)
cur_page++;
}
else if (!eng.Keyboard[Key.Enter])
{
enterdown = false;
}
//Minus - Toggle fullscreen
if (eng.Keyboard[Key.Minus])
{
eng.toggleFullScreen();
}
}
}
}