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 | |
---|
21 | MultiSelectWindow menu = new MultiSelectWindow("TESTMODE", "Developer tools", "Start this thing", "Get me out of here"); |
---|
22 | menu.DefaultCancel = 2; |
---|
23 | menu.AddItemHandler(0, delegate() { MessageDisplay.Add("Starting game..."); StartGame(); DeveloperCommand(); }); |
---|
24 | menu.AddItemHandler(1, StartGame); |
---|
25 | menu.AddItemHandler(2, Exit); |
---|
26 | Add(menu); |
---|
27 | } |
---|
28 | |
---|
29 | private void DeveloperCommand() |
---|
30 | { |
---|
31 | IsPaused = true; |
---|
32 | InputWindow prompt = new InputWindow(""); |
---|
33 | prompt.TextEntered += delegate(InputWindow p) |
---|
34 | { |
---|
35 | if (p.InputBox.Text.Length == 0) { IsPaused = false; return; } |
---|
36 | string[] commands = p.InputBox.Text.Split(' '); |
---|
37 | |
---|
38 | if (commands[0] == "money") |
---|
39 | { |
---|
40 | if (commands[1] == "add") |
---|
41 | { |
---|
42 | MessageDisplay.Add("+$" + int.Parse(commands[2])); |
---|
43 | } |
---|
44 | else if (commands[1] == "reduce") |
---|
45 | { |
---|
46 | MessageDisplay.Add("-$" + int.Parse(commands[2])); |
---|
47 | } |
---|
48 | } |
---|
49 | else if (commands[0] == "score") |
---|
50 | { |
---|
51 | if (commands[1] == "add") |
---|
52 | { |
---|
53 | MessageDisplay.Add("+" + int.Parse(commands[2])); |
---|
54 | Score(int.Parse(commands[2])); |
---|
55 | } |
---|
56 | else if (commands[1] == "reduce") |
---|
57 | { |
---|
58 | MessageDisplay.Add("-" + int.Parse(commands[2])); |
---|
59 | Score(int.Parse(commands[2])); |
---|
60 | } |
---|
61 | } |
---|
62 | else if (commands[0] == "level") |
---|
63 | { |
---|
64 | if (commands[1] == "up") |
---|
65 | { |
---|
66 | MessageDisplay.Add("+" + int.Parse(commands[2]) + " levels"); |
---|
67 | } |
---|
68 | else if (commands[1] == "down") |
---|
69 | { |
---|
70 | MessageDisplay.Add("-" + int.Parse(commands[2]) + " levels"); |
---|
71 | } |
---|
72 | } |
---|
73 | else if (commands[0] == "item") |
---|
74 | { |
---|
75 | if (player.GiveWeapon(commands[1])) |
---|
76 | { |
---|
77 | MessageDisplay.Add("You got " + commands[1] + "!"); |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | MessageDisplay.Add("What " + commands[1] + "?"); |
---|
82 | } |
---|
83 | } |
---|
84 | else if (commands[0] == "powerup") |
---|
85 | { |
---|
86 | if (player.PowerUp(commands[1], double.Parse(commands[2]))) |
---|
87 | MessageDisplay.Add("Activated " + commands[1] + " powerup"); |
---|
88 | else |
---|
89 | MessageDisplay.Add("No such powerup"); |
---|
90 | } |
---|
91 | else if (commands[0] == "spawn") |
---|
92 | { |
---|
93 | if (commands[1] == "zombie") |
---|
94 | { |
---|
95 | if (commands.Length > 2) |
---|
96 | { |
---|
97 | for (int i = 0; i < int.Parse(commands[2]); i++) |
---|
98 | SpawnZombie(); |
---|
99 | } else { SpawnZombie(); } |
---|
100 | } |
---|
101 | } |
---|
102 | else if (commands[0] == "kill") |
---|
103 | { |
---|
104 | if (commands[1] == "enemies") |
---|
105 | { |
---|
106 | KillAllEnemies(); |
---|
107 | MessageDisplay.Add("All enemies killed"); |
---|
108 | } |
---|
109 | } |
---|
110 | else if (commands[0] == "exit") |
---|
111 | { |
---|
112 | Exit(); |
---|
113 | } |
---|
114 | else { MessageDisplay.Add("Unknow command!"); } |
---|
115 | |
---|
116 | DeveloperCommand(); |
---|
117 | }; |
---|
118 | Add(prompt); |
---|
119 | } |
---|
120 | |
---|
121 | private void StartGame() |
---|
122 | { |
---|
123 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, delegate() { PauseMenu(); }, null); |
---|
124 | Keyboard.Listen(Key.Tab, ButtonState.Pressed, DeveloperCommand, null); |
---|
125 | AddScoreMeter(); |
---|
126 | |
---|
127 | player = new Player(50, 50, 1, true); |
---|
128 | Add(player); |
---|
129 | SpawnZombie(); |
---|
130 | } |
---|
131 | |
---|
132 | public void Score(int changeValue) |
---|
133 | { |
---|
134 | scoreboard.Value += changeValue; |
---|
135 | } |
---|
136 | |
---|
137 | private void SpawnZombie() |
---|
138 | { |
---|
139 | Zombie zombie = new Zombie(50, 50, RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top), 100); |
---|
140 | enemies.Add(zombie); |
---|
141 | Add(zombie); |
---|
142 | } |
---|
143 | |
---|
144 | private void KillAllEnemies() |
---|
145 | { |
---|
146 | foreach (Zombie enemy in enemies) |
---|
147 | { |
---|
148 | enemy.Destroy(); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | private void AddScoreMeter() |
---|
153 | { |
---|
154 | scoreboard = new IntMeter(0); |
---|
155 | Label ScoreScreen = new Label(); |
---|
156 | ScoreScreen.X = 0; |
---|
157 | ScoreScreen.Y = Screen.Bottom + 100; |
---|
158 | ScoreScreen.TextColor = Color.Black; |
---|
159 | ScoreScreen.Color = Color.White; |
---|
160 | ScoreScreen.BindTo(scoreboard); |
---|
161 | Add(ScoreScreen); |
---|
162 | } |
---|
163 | |
---|
164 | private void SaveAndBackToMenu() //ToDo: Save |
---|
165 | { |
---|
166 | ClearAll(); |
---|
167 | MessageDisplay.Add("Saved!"); |
---|
168 | Begin(); |
---|
169 | } |
---|
170 | |
---|
171 | public void PauseMenu() |
---|
172 | { |
---|
173 | MultiSelectWindow menu = new MultiSelectWindow("Pause Menu", "Resume Game", "Back to Menu", "Exit Game"); |
---|
174 | menu.DefaultCancel = 0; |
---|
175 | menu.AddItemHandler(0, delegate { IsPaused = false; }); |
---|
176 | menu.AddItemHandler(1, SaveAndBackToMenu); |
---|
177 | menu.AddItemHandler(2, Exit); |
---|
178 | Add(menu); |
---|
179 | IsPaused = true; |
---|
180 | } |
---|
181 | } |
---|