1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | public class G : PhysicsGame |
---|
10 | { |
---|
11 | public static G game; |
---|
12 | private IntMeter scoreboard; |
---|
13 | public Player player { get; private set; } |
---|
14 | private List<Zombie> enemies = new List<Zombie>(); |
---|
15 | |
---|
16 | public override void Begin() |
---|
17 | { |
---|
18 | game = this; |
---|
19 | Mouse.IsCursorVisible = true; |
---|
20 | MainMenu(); |
---|
21 | } |
---|
22 | |
---|
23 | public void MainMenu() |
---|
24 | { |
---|
25 | MultiSelectWindow menu = new MultiSelectWindow("TESTMODE", "Developer tools", "Start this thing", "Perks", "Get me out of here"); |
---|
26 | menu.DefaultCancel = -0; |
---|
27 | menu.AddItemHandler(0, delegate() { MessageDisplay.Add("Starting game..."); StartGame(); DeveloperCommand(); }); |
---|
28 | menu.AddItemHandler(1, CharacterMenu); |
---|
29 | menu.AddItemHandler(2, PerkMenu); |
---|
30 | menu.AddItemHandler(3, Exit); |
---|
31 | Add(menu); |
---|
32 | |
---|
33 | } |
---|
34 | |
---|
35 | private void DeveloperCommand() |
---|
36 | { |
---|
37 | IsPaused = true; |
---|
38 | InputWindow prompt = new InputWindow(""); |
---|
39 | prompt.TextEntered += delegate(InputWindow p) |
---|
40 | { |
---|
41 | if (p.InputBox.Text.Length == 0) { IsPaused = false; return; } |
---|
42 | string[] commands = p.InputBox.Text.Split(' '); |
---|
43 | |
---|
44 | if (commands[0] == "money") |
---|
45 | { |
---|
46 | if (commands[1] == "add") |
---|
47 | { |
---|
48 | MessageDisplay.Add("+$" + int.Parse(commands[2])); |
---|
49 | } |
---|
50 | else if (commands[1] == "reduce") |
---|
51 | { |
---|
52 | MessageDisplay.Add("-$" + int.Parse(commands[2])); |
---|
53 | } |
---|
54 | } |
---|
55 | else if (commands[0] == "score") |
---|
56 | { |
---|
57 | if (commands[1] == "add") |
---|
58 | { |
---|
59 | MessageDisplay.Add("+" + int.Parse(commands[2])); |
---|
60 | Score(int.Parse(commands[2])); |
---|
61 | } |
---|
62 | else if (commands[1] == "reduce") |
---|
63 | { |
---|
64 | MessageDisplay.Add("-" + int.Parse(commands[2])); |
---|
65 | Score(int.Parse(commands[2])); |
---|
66 | } |
---|
67 | } |
---|
68 | else if (commands[0] == "level") |
---|
69 | { |
---|
70 | if (commands[1] == "up") |
---|
71 | { |
---|
72 | MessageDisplay.Add("+" + int.Parse(commands[2]) + " levels"); |
---|
73 | } |
---|
74 | else if (commands[1] == "down") |
---|
75 | { |
---|
76 | MessageDisplay.Add("-" + int.Parse(commands[2]) + " levels"); |
---|
77 | } |
---|
78 | } |
---|
79 | else if (commands[0] == "item") |
---|
80 | { |
---|
81 | if (player.GiveWeapon(commands[1])) |
---|
82 | { |
---|
83 | MessageDisplay.Add("You got " + commands[1] + "!"); |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | MessageDisplay.Add("What " + commands[1] + "?"); |
---|
88 | } |
---|
89 | } |
---|
90 | else if (commands[0] == "powerup") |
---|
91 | { |
---|
92 | if (player.PowerUp(commands[1], double.Parse(commands[2]))) |
---|
93 | MessageDisplay.Add("Activated " + commands[1] + " powerup"); |
---|
94 | else |
---|
95 | MessageDisplay.Add("No such powerup"); |
---|
96 | } |
---|
97 | else if (commands[0] == "spawn") |
---|
98 | { |
---|
99 | if (commands[1] == "zombie") |
---|
100 | { |
---|
101 | if (commands.Length > 2) |
---|
102 | { |
---|
103 | for (int i = 0; i < int.Parse(commands[2]); i++) |
---|
104 | SpawnZombie(); |
---|
105 | } else { SpawnZombie(); } |
---|
106 | } |
---|
107 | } |
---|
108 | else if (commands[0] == "kill") |
---|
109 | { |
---|
110 | if (commands[1] == "enemies") |
---|
111 | { |
---|
112 | KillAllEnemies(); |
---|
113 | MessageDisplay.Add("All enemies killed"); |
---|
114 | } |
---|
115 | } |
---|
116 | else if (commands[0] == "health") |
---|
117 | { |
---|
118 | if (commands[1] == "add") |
---|
119 | { |
---|
120 | player.health.Value += int.Parse(commands[2]); |
---|
121 | MessageDisplay.Add("+" + commands[2] + " health"); |
---|
122 | } |
---|
123 | else if (commands[1] == "reduce") |
---|
124 | { |
---|
125 | player.health.Value -= int.Parse(commands[2]); |
---|
126 | MessageDisplay.Add("-" + commands[2] + " health"); |
---|
127 | } |
---|
128 | } |
---|
129 | else if (commands[0] == "enemies") |
---|
130 | { |
---|
131 | if (commands[1] == "count") |
---|
132 | { |
---|
133 | MessageDisplay.Add("Enemies spawned: " + enemies.Count); |
---|
134 | } |
---|
135 | } |
---|
136 | else if (commands[0] == "die") |
---|
137 | { |
---|
138 | UI.GameOver(); |
---|
139 | } |
---|
140 | else if (commands[0] == "exit") |
---|
141 | { |
---|
142 | Exit(); |
---|
143 | } |
---|
144 | else { MessageDisplay.Add("Unknow command!"); } |
---|
145 | |
---|
146 | DeveloperCommand(); |
---|
147 | }; |
---|
148 | Add(prompt); |
---|
149 | } |
---|
150 | |
---|
151 | private void StartGame() |
---|
152 | { |
---|
153 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, delegate() { PauseMenu(); }, null); |
---|
154 | Keyboard.Listen(Key.E, ButtonState.Pressed, delegate() { Inventory(); }, null); |
---|
155 | Keyboard.Listen(Key.Tab, ButtonState.Pressed, DeveloperCommand, null); |
---|
156 | AddScoreMeter(); |
---|
157 | |
---|
158 | player = new Player(50, 50, 10, true); |
---|
159 | Camera.Follow(player); |
---|
160 | Add(player); |
---|
161 | SpawnZombie(); |
---|
162 | CreateLifeMeter(); |
---|
163 | |
---|
164 | Timer t = new Timer(); |
---|
165 | t.Interval = 1; |
---|
166 | t.Timeout += delegate() { SpawnZombie(); }; |
---|
167 | t.Start(); |
---|
168 | } |
---|
169 | |
---|
170 | public void Score(int changeValue) |
---|
171 | { |
---|
172 | scoreboard.Value += changeValue; |
---|
173 | } |
---|
174 | |
---|
175 | private void SpawnZombie() |
---|
176 | { |
---|
177 | double i = RandomGen.NextDouble(100, 1000); |
---|
178 | Double x = 0; |
---|
179 | Double y = 0; |
---|
180 | |
---|
181 | if (RandomGen.NextBool()) |
---|
182 | { |
---|
183 | x = RandomGen.SelectOne(Screen.Left-i, Screen.Right+i); |
---|
184 | y = RandomGen.NextDouble(Screen.Bottom-i, Screen.Top+i); |
---|
185 | } |
---|
186 | else |
---|
187 | { |
---|
188 | x = RandomGen.NextDouble(Screen.Left-i, Screen.Right+i); |
---|
189 | y = RandomGen.SelectOne(Screen.Bottom-i, Screen.Top+i); |
---|
190 | } |
---|
191 | Zombie zombie = new Zombie(50, 50, x+player.X, y+player.Y, 100); |
---|
192 | enemies.Add(zombie); |
---|
193 | Add(zombie); |
---|
194 | } |
---|
195 | |
---|
196 | private void KillAllEnemies() |
---|
197 | { |
---|
198 | foreach (Zombie enemy in enemies) |
---|
199 | { |
---|
200 | enemy.Destroy(); |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | private void AddScoreMeter() |
---|
205 | { |
---|
206 | scoreboard = new IntMeter(0); |
---|
207 | Label ScoreScreen = new Label(); |
---|
208 | ScoreScreen.X = 0; |
---|
209 | ScoreScreen.Y = Screen.Bottom + 100; |
---|
210 | ScoreScreen.TextColor = Color.Black; |
---|
211 | ScoreScreen.Color = Color.White; |
---|
212 | ScoreScreen.BindTo(scoreboard); |
---|
213 | Add(ScoreScreen); |
---|
214 | } |
---|
215 | |
---|
216 | private void SaveAndBackToMenu() //ToDo: Save |
---|
217 | { |
---|
218 | ClearAll(); |
---|
219 | MessageDisplay.Add("Saved!"); |
---|
220 | MainMenu(); |
---|
221 | } |
---|
222 | |
---|
223 | public void PauseMenu() |
---|
224 | { |
---|
225 | MultiSelectWindow menu = new MultiSelectWindow("Pause Menu", "Resume Game", "Back to Menu", "Exit Game"); |
---|
226 | menu.DefaultCancel = 0; |
---|
227 | menu.AddItemHandler(0, delegate { IsPaused = false; }); |
---|
228 | menu.AddItemHandler(1, SaveAndBackToMenu); |
---|
229 | menu.AddItemHandler(2, Exit); |
---|
230 | Add(menu); |
---|
231 | IsPaused = true; |
---|
232 | } |
---|
233 | |
---|
234 | public void Inventory() //ToDo Inventory and funktionality |
---|
235 | { |
---|
236 | MultiSelectWindow menu = new MultiSelectWindow("Inventory", "Back to Game"); |
---|
237 | menu.DefaultCancel = 0; |
---|
238 | menu.AddItemHandler(0, delegate { IsPaused = false; }); |
---|
239 | Add(menu); |
---|
240 | IsPaused = true; |
---|
241 | } |
---|
242 | |
---|
243 | public void CharacterMenu() //ToDo Character variations |
---|
244 | { |
---|
245 | MultiSelectWindow menu = new MultiSelectWindow("Select Character", "Char NRO1", "Char NRO2", "Char NRO3", "Char NRO4", "Back to Main Menu"); |
---|
246 | menu.DefaultCancel = 0; |
---|
247 | menu.AddItemHandler(0, StartGame); |
---|
248 | menu.AddItemHandler(1, StartGame); |
---|
249 | menu.AddItemHandler(2, StartGame); |
---|
250 | menu.AddItemHandler(3, StartGame); |
---|
251 | menu.AddItemHandler(4, MainMenu); |
---|
252 | Add(menu); |
---|
253 | } |
---|
254 | |
---|
255 | public void PerkMenu() //ToDo Perks, Perk selecting system, Save system, and return to main menu button. |
---|
256 | { |
---|
257 | MultiSelectWindow menu = new MultiSelectWindow("Select Perks", "Perk NRO1", "Perk NRO2", "Perk NRO3", "Perk NRO4", "Back to Main Menu"); |
---|
258 | menu.DefaultCancel = 0; |
---|
259 | menu.AddItemHandler(0, MainMenu); |
---|
260 | menu.AddItemHandler(1, MainMenu); |
---|
261 | menu.AddItemHandler(2, MainMenu); |
---|
262 | menu.AddItemHandler(3, MainMenu); |
---|
263 | menu.AddItemHandler(4, MainMenu); |
---|
264 | Add(menu); |
---|
265 | } |
---|
266 | |
---|
267 | void CreateLifeMeter() |
---|
268 | { |
---|
269 | ProgressBar LifeBar = new ProgressBar(150, 20); |
---|
270 | LifeBar.X = Screen.Right - LifeBar.Width / 2 - 10; |
---|
271 | LifeBar.Y = Screen.Bottom + LifeBar.Height / 2 + 10; |
---|
272 | LifeBar.BorderColor = Color.Black; |
---|
273 | LifeBar.BindTo(player.health); |
---|
274 | Add(LifeBar); |
---|
275 | } |
---|
276 | } |
---|