/
Xasteroids.cs
133 lines (107 loc) · 2.83 KB
/
Xasteroids.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
using System;
using System.Drawing;
using System.Windows.Forms;
using GorgonLibrary;
using GorgonLibrary.InputDevices;
namespace Xasteroids
{
public partial class Xasteroids : Form
{
private Input _input;
private Keyboard _keyboard;
private GameMain _gameMain;
public Xasteroids()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
try
{
Gorgon.Initialize(true, false);
VideoMode videoMode;
bool fullScreen;
using (Configuration configuration = new Configuration())
{
configuration.FillResolutionList();
configuration.ShowDialog(this);
if (configuration.DialogResult != DialogResult.OK)
{
Close();
return;
}
videoMode = configuration.VideoMode;
fullScreen = configuration.FullScreen;
}
Gorgon.SetMode(this, videoMode.Width, videoMode.Height, BackBufferFormats.BufferRGB888, !fullScreen);
Gorgon.Idle += Gorgon_Idle;
//Gorgon.FrameStatsVisible = true;
_input = Input.LoadInputPlugIn(Environment.CurrentDirectory + @"\GorgonInput.DLL", "Gorgon.RawInput");
_input.Bind(this);
_keyboard = _input.Keyboard;
_keyboard.Enabled = true;
_keyboard.Exclusive = true;
_keyboard.KeyDown += KeyboardOnKeyDown;
_gameMain = new GameMain();
string reason;
if (!_gameMain.Initialize(Gorgon.Screen.Width, Gorgon.Screen.Height, this, out reason))
{
MessageBox.Show(string.Format("Error loading game resources, error message: {0}", reason));
Close();
return;
}
Gorgon.Go();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
Close();
}
}
private void KeyboardOnKeyDown(object sender, KeyboardInputEventArgs e)
{
if (e.Alt && e.Key == KeyboardKeys.Enter)
{
Gorgon.Screen.Windowed = !Gorgon.Screen.Windowed;
}
_gameMain.KeyDown(e);
}
void Gorgon_Idle(object sender, GorgonLibrary.Graphics.FrameEventArgs e)
{
Gorgon.Screen.Clear(Color.Black);
Gorgon.Screen.BeginDrawing();
_gameMain.ProcessGame(e.FrameDeltaTime);
Gorgon.Screen.EndDrawing();
}
private void BeyondBeyaan_MouseDown(object sender, MouseEventArgs e)
{
_gameMain.MouseDown(e);
}
private void BeyondBeyaan_MouseUp(object sender, MouseEventArgs e)
{
_gameMain.MouseUp(e);
}
private void BeyondBeyaan_MouseMove(object sender, MouseEventArgs e)
{
_gameMain.MousePos.X = e.X;
_gameMain.MousePos.Y = e.Y;
}
void BeyondBeyaan_MouseWheel(object sender, MouseEventArgs e)
{
_gameMain.MouseScroll(e.Delta);
}
private void BeyondBeyaan_MouseLeave(object sender, EventArgs e)
{
Cursor.Show();
}
private void BeyondBeyaan_MouseEnter(object sender, EventArgs e)
{
Cursor.Hide();
}
public bool IsKeyDown(KeyboardKeys whichKey)
{
return _keyboard.KeyStates[whichKey] == KeyState.Down;
}
}
}