forked from thoth-tech/Asteroids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
179 lines (146 loc) · 5.8 KB
/
Program.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
using System;
using SplashKitSDK;
namespace AsteroidsGame
{
public class Program
{
private static bool _GameStarted, _GameExit;
public static double gameScale;
public static void Main()
{
game_setup setup = new game_setup();
Window gameWindow = setup.gameWindow;
//Window gameWindow = new Window("Asteroids", 1600, 900);
//gameWindow.ToggleBorder();
Game Game = null;
Menu Menu = new Menu(gameWindow);
Controls controls = new Controls();
FrameTickLog ftl = new FrameTickLog(gameWindow, "pricedown_bl", 50);
ftl.Start();
_GameStarted = false;
while (!_GameExit)
{
ftl.Reset();
SplashKit.ProcessEvents();
gameWindow.Clear(Color.Black); // reset screen
if (SplashKit.KeyTyped(Controls.Keylookup("Esc"))) _GameExit = true;
if (gameWindow.CloseRequested) _GameExit = true;
if (!Menu.GameStarted)
{
Menu.DrawMenu();
Menu.Selection();
if (Menu.quit == true) _GameExit = true; //if player selects quite close window
if (Menu.GameStarted)
Game = new Game(gameWindow, Menu.players, Menu.p1Ship, Menu.p2Ship); // create new game instance
}
else
{
Game.Draw();
Game.HandleInput();
Game.Updates();
if (!Game.GameStarted) Menu.ReSetup(); // re initialize menu
}
//ftl.draw();
gameWindow.Refresh(90); // draw frame to window
ftl.update();
}
gameWindow.Close();
}
public class game_setup
{
public Window gameWindow;
public game_setup()
{
//default config options
const int screen_width = 1600;
const int screen_height = 900;
const bool fullscreen = false;
const bool no_boarder = false;
const bool nomouse = true;
const double gameScaleDefault = 1;
const string game_bundles = "gamebundle_full_size.txt";
Json config_json = SplashKit.JsonFromFile("Game_Config.json");
if (!config_json.HasKey("Asteroids_game_config"))
{
Json temp_config_json = SplashKit.CreateJson();
temp_config_json.AddString("Asteroids_game_config", "");
temp_config_json.AddNumber("screen_width", screen_width);
temp_config_json.AddNumber("screen_height", screen_height);
temp_config_json.AddBool("fullscreen", fullscreen);
temp_config_json.AddBool("no_boarder", no_boarder);
temp_config_json.AddNumber("gameScale", gameScaleDefault);
temp_config_json.AddString("game_bundles", game_bundles);
temp_config_json.AddBool("nomouse", nomouse);
config_json = temp_config_json;
SplashKit.JsonToFile(config_json, "Game_Config.json");
}
if (config_json.HasKey("screen_width") & config_json.HasKey("screen_height"))
{
gameWindow = new Window("Asteroids", config_json.ReadInteger("screen_width"), config_json.ReadInteger("screen_height"));
}
else
{
gameWindow = new Window("Asteroids", screen_width, screen_height);
}
if (config_json.HasKey("fullscreen"))
{
if (config_json.ReadBool("fullscreen"))
{
gameWindow.ToggleFullscreen();
}
}
if (config_json.HasKey("no_boarder"))
{
if (config_json.ReadBool("no_boarder"))
{
gameWindow.ToggleBorder();
}
}
if (config_json.HasKey("game_bundles"))
{
SplashKit.LoadResourceBundle("MainGameBundle", config_json.ReadString("game_bundles"));
}
else
{
SplashKit.LoadResourceBundle("MainGameBundle", game_bundles);
}
if (config_json.HasKey("gameScale"))
{
gameScale = config_json.ReadNumber("gameScale");
}
else
{
gameScale = gameScaleDefault;
}
if (config_json.HasKey("nomouse"))
{
if (config_json.ReadBool("nomouse"))
{
SplashKit.HideMouse();
}
}
else
{
SplashKit.HideMouse();
}
}
}
public class Controls
{
private static Json _controls_json;
public Controls()
{
_controls_json = SplashKit.JsonFromFile("Controls.json");
}
public static KeyCode Keylookup(string key)
{
if (!_controls_json.HasKey(key)) return KeyCode.UnknownKey;
if (Enum.IsDefined(typeof(KeyCode), _controls_json.ReadString(key)))
{
return Enum.Parse<KeyCode>(_controls_json.ReadString(key));
}
return KeyCode.UnknownKey;
}
}
}
}