1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.IO; |
---|
4 | using Jypeli; |
---|
5 | using Jypeli.Assets; |
---|
6 | using Jypeli.Controls; |
---|
7 | using Jypeli.Effects; |
---|
8 | using Jypeli.Widgets; |
---|
9 | using ALTK; |
---|
10 | using ALTK.GUI.Dialogs; |
---|
11 | |
---|
12 | public class YAG2DSS : PhysicsGame |
---|
13 | { |
---|
14 | ALTKHandler altkHandler; |
---|
15 | GameObject Kursori; |
---|
16 | |
---|
17 | List<PhysicsObject> Pelaaja = new List<PhysicsObject>(); |
---|
18 | List<PhysicsObject> Madonreika = new List<PhysicsObject>(); |
---|
19 | List<PhysicsObject> Minioni = new List<PhysicsObject>(); |
---|
20 | List<PhysicsObject> Asteroidi = new List<PhysicsObject>(); |
---|
21 | |
---|
22 | Timer MadonreikaAjastin; |
---|
23 | Timer Minioniajastin; |
---|
24 | Timer Minioninliikuttaja; |
---|
25 | Timer Automaattiammus; |
---|
26 | Timer MinioninAmmus; |
---|
27 | Timer Asteroidiajastin; |
---|
28 | Timer TuhoaAsteroidi; |
---|
29 | Timer EnergianLataaja; |
---|
30 | Timer Vaikeuttaja; |
---|
31 | Timer Konekivaari1; |
---|
32 | Timer Konekivaari2; |
---|
33 | Timer Triplefire1; |
---|
34 | Timer Triplefire2; |
---|
35 | |
---|
36 | ExplosionSystem PlayerHitES; |
---|
37 | ExplosionSystem PlayerDeathES; |
---|
38 | ExplosionSystem PlayerDeathESL; |
---|
39 | ExplosionSystem PlayerDeathES2; |
---|
40 | |
---|
41 | ExplosionSystem WormholeExplosionES; |
---|
42 | ExplosionSystem WormholeExplosionES2; |
---|
43 | |
---|
44 | ExplosionSystem MinionExplosionES; |
---|
45 | ExplosionSystem MinionExplosionES2; |
---|
46 | |
---|
47 | ExplosionSystem AsteroidExplosionES; |
---|
48 | ExplosionSystem AsteroidExplosionES2; |
---|
49 | |
---|
50 | double MadonreikaPosX = 0.0; |
---|
51 | double MadonreikaPosY = 0.0; |
---|
52 | |
---|
53 | int Pelaajan1Pisteet = 0; |
---|
54 | int Pelaajan2Pisteet = 0; |
---|
55 | |
---|
56 | public bool Initialized = false; |
---|
57 | public static bool SettingsConfirmed = false; |
---|
58 | |
---|
59 | double Pelaajan1Kerroin = 1.0; |
---|
60 | double Pelaajan2Kerroin = 1.0; |
---|
61 | |
---|
62 | public override void Begin() |
---|
63 | { |
---|
64 | if (!Initialized) |
---|
65 | { |
---|
66 | SetWindowSize(1024, 768, true); |
---|
67 | |
---|
68 | KeyboardEventInput.Initialize(this.Window); |
---|
69 | |
---|
70 | #region Cursor handling |
---|
71 | CreateCursor(); |
---|
72 | |
---|
73 | Initialized = true; |
---|
74 | #endregion |
---|
75 | } |
---|
76 | |
---|
77 | Level.BackgroundColor = Color.Black; |
---|
78 | |
---|
79 | Camera.ZoomToLevel(); |
---|
80 | |
---|
81 | if (SettingsConfirmed) |
---|
82 | { |
---|
83 | LuoKentta(); |
---|
84 | AsetaNappaimet(); |
---|
85 | LuoAjastin(); |
---|
86 | //LuoMadonreika(); |
---|
87 | //PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
88 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ShowExit, "Lopeta peli"); |
---|
89 | Explotions(); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | public void CreateCursor() |
---|
94 | { |
---|
95 | Kursori = new GameObject(32, 32); |
---|
96 | Kursori.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "cursor.png")); |
---|
97 | Kursori.IsVisible = false; |
---|
98 | AnalogHandler handler = new AnalogHandler(HandleCursor); |
---|
99 | Mouse.ListenMovement(0.1, handler, ""); |
---|
100 | Add(Kursori); |
---|
101 | } |
---|
102 | |
---|
103 | void Explotions() |
---|
104 | { |
---|
105 | PlayerHitES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 800); |
---|
106 | PlayerHitES.ScaleAmount = 0.0002; |
---|
107 | PlayerHitES.MaxRotationSpeed = 1000.0; |
---|
108 | PlayerHitES.BlendMode = BlendMode.Alpha; |
---|
109 | PlayerHitES.MinScale = 2.5; |
---|
110 | PlayerHitES.MaxScale = 5.0; |
---|
111 | PlayerHitES.Shape = Shape.Circle; |
---|
112 | PlayerHitES.MinRotationSpeed = 500.0; |
---|
113 | PlayerHitES.AlphaAmount = 1.0; |
---|
114 | PlayerHitES.MinAcceleration = 3.0; |
---|
115 | PlayerHitES.MaxAcceleration = 6.0; |
---|
116 | PlayerHitES.MinVelocity = 10.0; |
---|
117 | PlayerHitES.MaxVelocity = 20.0; |
---|
118 | PlayerHitES.MinLifetime = PlayerHitES.MinLifetime * 0.8; |
---|
119 | PlayerHitES.MaxLifetime = PlayerHitES.MaxLifetime * 0.8; |
---|
120 | Add(PlayerHitES); |
---|
121 | |
---|
122 | PlayerDeathES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 8000); |
---|
123 | PlayerDeathES.ScaleAmount = 0.0002; |
---|
124 | PlayerDeathES.MaxRotationSpeed = 1000.0; |
---|
125 | PlayerDeathES.BlendMode = BlendMode.Alpha; |
---|
126 | PlayerDeathES.MinScale = 2.0; |
---|
127 | PlayerDeathES.MaxScale = 4.0; |
---|
128 | PlayerDeathES.Shape = Shape.Circle; |
---|
129 | PlayerDeathES.MinRotationSpeed = 500.0; |
---|
130 | PlayerDeathES.AlphaAmount = 1.0; |
---|
131 | PlayerDeathES.MinAcceleration = 3.0; |
---|
132 | PlayerDeathES.MaxAcceleration = 6.0; |
---|
133 | PlayerDeathES.MaxVelocity = 100.0; |
---|
134 | PlayerDeathES.MinLifetime = 5.9; |
---|
135 | PlayerDeathES.MaxLifetime = 6.0; |
---|
136 | Add(PlayerDeathES); |
---|
137 | |
---|
138 | PlayerDeathESL = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 16000); |
---|
139 | PlayerDeathESL.ScaleAmount = 0.0002; |
---|
140 | PlayerDeathESL.MaxRotationSpeed = 1000.0; |
---|
141 | PlayerDeathESL.BlendMode = BlendMode.Alpha; |
---|
142 | PlayerDeathESL.MinScale = 1.5; |
---|
143 | PlayerDeathESL.MaxScale = 3.0; |
---|
144 | PlayerDeathESL.Shape = Shape.Circle; |
---|
145 | PlayerDeathESL.MinRotationSpeed = 500.0; |
---|
146 | PlayerDeathESL.AlphaAmount = 1.0; |
---|
147 | PlayerDeathESL.MinAcceleration = 1.5; |
---|
148 | PlayerDeathESL.MaxAcceleration = 3.0; |
---|
149 | PlayerDeathESL.MaxVelocity = 50.0; |
---|
150 | PlayerDeathESL.MinLifetime = 5.9; |
---|
151 | PlayerDeathESL.MaxLifetime = 6.0; |
---|
152 | Add(PlayerDeathESL); |
---|
153 | |
---|
154 | PlayerDeathES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 2800); |
---|
155 | PlayerDeathES2.ScaleAmount = 0.0002; |
---|
156 | PlayerDeathES2.MaxRotationSpeed = 1000.0; |
---|
157 | PlayerDeathES2.BlendMode = BlendMode.Alpha; |
---|
158 | PlayerDeathES2.MinScale = 64.0; |
---|
159 | PlayerDeathES2.MaxScale = 128.0; |
---|
160 | PlayerDeathES2.Shape = Shape.Circle; |
---|
161 | PlayerDeathES2.MinRotationSpeed = 500.0; |
---|
162 | PlayerDeathES2.AlphaAmount = 0.8; |
---|
163 | PlayerDeathES2.MinAcceleration = 0.75; |
---|
164 | PlayerDeathES2.MaxAcceleration = 0.75; |
---|
165 | PlayerDeathES2.MaxVelocity = 12.5; |
---|
166 | PlayerDeathES2.MinLifetime = 5.9; |
---|
167 | PlayerDeathES2.MaxLifetime = 6.0; |
---|
168 | Add(PlayerDeathES2); |
---|
169 | |
---|
170 | MinionExplosionES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion.png")), 5000); |
---|
171 | MinionExplosionES.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion_2.png")); |
---|
172 | MinionExplosionES.ScaleAmount = 0.0002; |
---|
173 | MinionExplosionES.MaxRotationSpeed = 1250.0; |
---|
174 | MinionExplosionES.BlendMode = BlendMode.Alpha; |
---|
175 | MinionExplosionES.MinScale = 2.0; |
---|
176 | MinionExplosionES.MaxScale = 4.0; |
---|
177 | MinionExplosionES.Shape = Shape.Circle; |
---|
178 | MinionExplosionES.MinRotationSpeed = 500.0; |
---|
179 | MinionExplosionES.MinAcceleration = 12.0; |
---|
180 | MinionExplosionES.MaxAcceleration = 24.0; |
---|
181 | MinionExplosionES.MinVelocity = 18.00; |
---|
182 | MinionExplosionES.MaxVelocity = 30.00; |
---|
183 | MinionExplosionES.MaxLifetime = MinionExplosionES.MaxLifetime * 1.00; |
---|
184 | MinionExplosionES.MinLifetime = MinionExplosionES.MinLifetime * 1.00; |
---|
185 | Add(MinionExplosionES); |
---|
186 | |
---|
187 | MinionExplosionES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion.png")), 500); |
---|
188 | MinionExplosionES2.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion_2.png")); |
---|
189 | MinionExplosionES2.ScaleAmount = 0.0002; |
---|
190 | MinionExplosionES2.MaxRotationSpeed = 800.0; |
---|
191 | MinionExplosionES2.BlendMode = BlendMode.Alpha; |
---|
192 | MinionExplosionES2.MinScale = 16.0; |
---|
193 | MinionExplosionES2.MaxScale = 32.0; |
---|
194 | MinionExplosionES2.Shape = Shape.Circle; |
---|
195 | MinionExplosionES2.MinRotationSpeed = 250.0; |
---|
196 | MinionExplosionES2.AlphaAmount = 0.8; |
---|
197 | MinionExplosionES2.MinAcceleration = 3.0; |
---|
198 | MinionExplosionES2.MaxAcceleration = 6.0; |
---|
199 | MinionExplosionES2.MaxVelocity = 18.75; |
---|
200 | MinionExplosionES2.MaxLifetime = MinionExplosionES2.MaxLifetime * 0.65; |
---|
201 | MinionExplosionES2.MinLifetime = MinionExplosionES2.MinLifetime * 0.65; |
---|
202 | Add(MinionExplosionES2); |
---|
203 | |
---|
204 | AsteroidExplosionES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "asteroid_explosion.png")), 2000); |
---|
205 | AsteroidExplosionES.ScaleAmount = 0.0002; |
---|
206 | AsteroidExplosionES.MaxRotationSpeed = 800.0; |
---|
207 | AsteroidExplosionES.BlendMode = BlendMode.Alpha; |
---|
208 | AsteroidExplosionES.MinScale = 4.0; |
---|
209 | AsteroidExplosionES.MaxScale = 8.0; |
---|
210 | AsteroidExplosionES.Shape = Shape.Circle; |
---|
211 | AsteroidExplosionES.MinRotationSpeed = 350.0; |
---|
212 | AsteroidExplosionES.AlphaAmount = 0.8; |
---|
213 | AsteroidExplosionES.MinAcceleration = 6.0; |
---|
214 | AsteroidExplosionES.MaxAcceleration = 12.0; |
---|
215 | AsteroidExplosionES.MinVelocity = 36.75; |
---|
216 | AsteroidExplosionES.MaxVelocity = 55.25; |
---|
217 | AsteroidExplosionES.MaxLifetime = AsteroidExplosionES.MaxLifetime * 0.425; |
---|
218 | AsteroidExplosionES.MinLifetime = AsteroidExplosionES.MinLifetime * 0.425; |
---|
219 | Add(AsteroidExplosionES); |
---|
220 | |
---|
221 | AsteroidExplosionES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "asteroid_explosion.png")), 800); |
---|
222 | AsteroidExplosionES2.ScaleAmount = 0.0002; |
---|
223 | AsteroidExplosionES2.MaxRotationSpeed = 800.0; |
---|
224 | AsteroidExplosionES2.BlendMode = BlendMode.Alpha; |
---|
225 | AsteroidExplosionES2.MinScale = 10.0; |
---|
226 | AsteroidExplosionES2.MaxScale = 18.0; |
---|
227 | AsteroidExplosionES2.Shape = Shape.Circle; |
---|
228 | AsteroidExplosionES2.MinRotationSpeed = 350.0; |
---|
229 | AsteroidExplosionES2.AlphaAmount = 0.8; |
---|
230 | AsteroidExplosionES2.MinAcceleration = 1.5; |
---|
231 | AsteroidExplosionES2.MaxAcceleration = 3.0; |
---|
232 | AsteroidExplosionES2.MinVelocity = 8.75; |
---|
233 | AsteroidExplosionES2.MaxVelocity = 20.25; |
---|
234 | AsteroidExplosionES2.MaxLifetime = AsteroidExplosionES2.MaxLifetime * 1.8; |
---|
235 | AsteroidExplosionES2.MinLifetime = AsteroidExplosionES2.MinLifetime * 1.8; |
---|
236 | Add(AsteroidExplosionES2); |
---|
237 | |
---|
238 | WormholeExplosionES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion.png")), 5000); |
---|
239 | WormholeExplosionES.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion_2.png")); |
---|
240 | WormholeExplosionES.ScaleAmount = 0.0002; |
---|
241 | WormholeExplosionES.MaxRotationSpeed = 1000.0; |
---|
242 | WormholeExplosionES.BlendMode = BlendMode.Alpha; |
---|
243 | WormholeExplosionES.MinScale = 1.5; |
---|
244 | WormholeExplosionES.MaxScale = 5.0; |
---|
245 | WormholeExplosionES.Shape = Shape.Circle; |
---|
246 | WormholeExplosionES.MinRotationSpeed = 500.0; |
---|
247 | WormholeExplosionES.AlphaAmount = 0.5; |
---|
248 | WormholeExplosionES.MinAcceleration = 6.0; |
---|
249 | WormholeExplosionES.MaxAcceleration = 12.0; |
---|
250 | WormholeExplosionES.MaxVelocity = 125.0; |
---|
251 | Add(WormholeExplosionES); |
---|
252 | |
---|
253 | WormholeExplosionES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion.png")), 5000); |
---|
254 | WormholeExplosionES2.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion_2.png")); |
---|
255 | WormholeExplosionES2.ScaleAmount = 0.0002; |
---|
256 | WormholeExplosionES2.MaxRotationSpeed = 1000.0; |
---|
257 | WormholeExplosionES2.BlendMode = BlendMode.Alpha; |
---|
258 | WormholeExplosionES2.MinScale = 16.0; |
---|
259 | WormholeExplosionES2.MaxScale = 32.0; |
---|
260 | WormholeExplosionES2.Shape = Shape.Circle; |
---|
261 | WormholeExplosionES2.MinRotationSpeed = 500.0; |
---|
262 | WormholeExplosionES2.AlphaAmount = 0.5; |
---|
263 | WormholeExplosionES2.MinAcceleration = 6.0; |
---|
264 | WormholeExplosionES2.MaxAcceleration = 12.0; |
---|
265 | WormholeExplosionES2.MaxVelocity = 85.0; |
---|
266 | Add(WormholeExplosionES2); |
---|
267 | } |
---|
268 | |
---|
269 | void LuoKentta() |
---|
270 | { |
---|
271 | PhysicsObject vasenReuna = Level.CreateLeftBorder(); |
---|
272 | vasenReuna.CollisionIgnoreGroup = 3; |
---|
273 | vasenReuna.IsVisible = false; |
---|
274 | PhysicsObject oikeaReuna = Level.CreateRightBorder(); |
---|
275 | oikeaReuna.IsVisible = false; |
---|
276 | oikeaReuna.CollisionIgnoreGroup = 3; |
---|
277 | PhysicsObject ylaReuna = Level.CreateTopBorder(); |
---|
278 | ylaReuna.IsVisible = false; |
---|
279 | ylaReuna.CollisionIgnoreGroup = 3; |
---|
280 | PhysicsObject alaReuna = Level.CreateBottomBorder(); |
---|
281 | alaReuna.IsVisible = false; |
---|
282 | alaReuna.CollisionIgnoreGroup = 3; |
---|
283 | |
---|
284 | LuoPelaaja(300); |
---|
285 | Pelaaja[0].Tag = 11; |
---|
286 | Pelaaja[0].CollisionIgnoreGroup = 1; |
---|
287 | LuoPelaaja(-300); |
---|
288 | Pelaaja[1].CollisionIgnoreGroup = 2; |
---|
289 | Pelaaja[1].Tag = 12; |
---|
290 | } |
---|
291 | |
---|
292 | void LuoPelaaja(double x) |
---|
293 | { |
---|
294 | PhysicsObject pelaaja = new PhysicsObject(20, 20); |
---|
295 | |
---|
296 | pelaaja.X = x; |
---|
297 | pelaaja.Y = -250; |
---|
298 | pelaaja.Restitution = 0.5; |
---|
299 | pelaaja.AngularDamping = 0.1; |
---|
300 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 90); |
---|
301 | pelaaja.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player.png")); |
---|
302 | Pelaaja.Add(pelaaja); |
---|
303 | Add(Pelaaja[Pelaaja.Count - 1]); |
---|
304 | } |
---|
305 | |
---|
306 | void LuoAjastin() |
---|
307 | { |
---|
308 | MadonreikaAjastin = new Timer(); |
---|
309 | MadonreikaAjastin.Interval = 5; |
---|
310 | MadonreikaAjastin.Timeout += new Action(NaytaAnimaatio); |
---|
311 | MadonreikaAjastin.Start(); |
---|
312 | |
---|
313 | Minioniajastin = new Timer(); |
---|
314 | Minioniajastin.Interval = 20; |
---|
315 | Minioniajastin.Timeout += new Action(Minioniajastin_Timeout); |
---|
316 | Minioniajastin.Start(); |
---|
317 | |
---|
318 | Minioninliikuttaja = new Timer(); |
---|
319 | Minioninliikuttaja.Interval = 0.1; // ei pienene |
---|
320 | Minioninliikuttaja.Timeout += new Action(Minioninliikuttaja_Timeout); |
---|
321 | Minioninliikuttaja.Start(); |
---|
322 | |
---|
323 | Automaattiammus = new Timer(); |
---|
324 | Automaattiammus.Interval = 0.2; // ei pienene |
---|
325 | Automaattiammus.Timeout += new Action(Automaattiammus_Timeout); |
---|
326 | Automaattiammus.Start(); |
---|
327 | |
---|
328 | MinioninAmmus = new Timer(); |
---|
329 | MinioninAmmus.Interval = 1.0; |
---|
330 | MinioninAmmus.Timeout += new Action(MinioninAmmus_Timeout); |
---|
331 | MinioninAmmus.Start(); |
---|
332 | |
---|
333 | Asteroidiajastin = new Timer(); |
---|
334 | Asteroidiajastin.Interval = RandomGen.NextDouble (5, 12); |
---|
335 | Asteroidiajastin.Timeout += new Action(Asteroidiajastin_Timeout); |
---|
336 | Asteroidiajastin.Start(); |
---|
337 | |
---|
338 | TuhoaAsteroidi = new Timer(); |
---|
339 | TuhoaAsteroidi.Interval = 30.0; |
---|
340 | TuhoaAsteroidi.Timeout += new Action(TuhoaAsteroidi_Timeout); |
---|
341 | TuhoaAsteroidi.Start(); |
---|
342 | |
---|
343 | Vaikeuttaja = new Timer(); |
---|
344 | Vaikeuttaja.Interval = 6.0; |
---|
345 | Vaikeuttaja.Timeout += new Action(Vaikeuttaja_Timeout); |
---|
346 | Vaikeuttaja.Start(); |
---|
347 | |
---|
348 | EnergianLataaja = new Timer(); |
---|
349 | EnergianLataaja.Interval = 5.0; |
---|
350 | EnergianLataaja.Timeout += new Action(EnergianLataaja_Timeout); |
---|
351 | EnergianLataaja.Start(); |
---|
352 | |
---|
353 | Konekivaari1 = new Timer(); |
---|
354 | Konekivaari1.Interval = 0.05; |
---|
355 | Konekivaari1.Timeout += new Action(Konekivaari1_Timeout); |
---|
356 | |
---|
357 | Konekivaari2 = new Timer(); |
---|
358 | Konekivaari2.Interval = 0.05; |
---|
359 | Konekivaari2.Timeout += new Action(Konekivaari2_Timeout); |
---|
360 | |
---|
361 | Triplefire1 = new Timer(); |
---|
362 | Triplefire1.Interval = 0.2; |
---|
363 | Triplefire1.Timeout += new Action(Triplefire1_Timeout); |
---|
364 | |
---|
365 | Triplefire2 = new Timer(); |
---|
366 | Triplefire2.Interval = 0.2; |
---|
367 | Triplefire2.Timeout += new Action(Triplefire2_Timeout); |
---|
368 | |
---|
369 | } |
---|
370 | |
---|
371 | void Triplefire2_Timeout() |
---|
372 | { |
---|
373 | if (Keyboard.GetKeyState(Key.LeftShift) == ButtonState.Down) |
---|
374 | { |
---|
375 | LuoPelaajanAmmus(1, Angle.FromDegrees(Pelaaja[1].Angle.Degrees + 20)); |
---|
376 | LuoPelaajanAmmus(1, Angle.FromDegrees(Pelaaja[1].Angle.Degrees - 20)); |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | void Triplefire1_Timeout() |
---|
381 | { |
---|
382 | if (Keyboard.GetKeyState(Key.RightShift) == ButtonState.Down) |
---|
383 | { |
---|
384 | LuoPelaajanAmmus(0, Angle.FromDegrees(Pelaaja[0].Angle.Degrees + 20)); |
---|
385 | LuoPelaajanAmmus(0, Angle.FromDegrees(Pelaaja[0].Angle.Degrees - 20)); |
---|
386 | |
---|
387 | } |
---|
388 | } |
---|
389 | |
---|
390 | void Konekivaari1_Timeout() |
---|
391 | { |
---|
392 | if (Keyboard.GetKeyState(Key.RightShift) == ButtonState.Down) |
---|
393 | LuoPelaajanAmmus(0, Pelaaja[0].Angle); |
---|
394 | } |
---|
395 | |
---|
396 | |
---|
397 | void Konekivaari2_Timeout() |
---|
398 | { |
---|
399 | if (Keyboard.GetKeyState(Key.LeftShift) == ButtonState.Down) |
---|
400 | LuoPelaajanAmmus(1, Pelaaja[1].Angle); |
---|
401 | } |
---|
402 | |
---|
403 | void Vaikeuttaja_Timeout() |
---|
404 | { |
---|
405 | MadonreikaAjastin.Interval = MadonreikaAjastin.Interval * 0.9; |
---|
406 | Minioniajastin.Interval = Minioniajastin.Interval * 0.9; |
---|
407 | Asteroidiajastin.Interval = Asteroidiajastin.Interval * 0.9; |
---|
408 | MinioninAmmus.Interval = MinioninAmmus.Interval * 0.95; |
---|
409 | Vaikeuttaja.Interval = Vaikeuttaja.Interval * 1.25; |
---|
410 | } |
---|
411 | |
---|
412 | void EnergianLataaja_Timeout() |
---|
413 | { |
---|
414 | if (ALTKHandler.HealthBars[0].Value < 100 && |
---|
415 | !Pelaaja[0].IsDestroyed) |
---|
416 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value + 1; |
---|
417 | |
---|
418 | if (ALTKHandler.HealthBars[1].Value < 100 && |
---|
419 | !Pelaaja[1].IsDestroyed) |
---|
420 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value + 1; |
---|
421 | } |
---|
422 | |
---|
423 | void TuhoaAsteroidi_Timeout() |
---|
424 | { |
---|
425 | Timer.SingleShot(0.0, AsteroidinTuhoaja); |
---|
426 | } |
---|
427 | |
---|
428 | void Asteroidiajastin_Timeout() |
---|
429 | { |
---|
430 | Timer.SingleShot(0.0, LuoAsteroidi); |
---|
431 | } |
---|
432 | |
---|
433 | void LuoPelaajanAmmus(int pelaajaID, Angle angle) |
---|
434 | { |
---|
435 | if (Pelaaja[pelaajaID].IsDestroyed) |
---|
436 | { |
---|
437 | return; |
---|
438 | } |
---|
439 | Projectile PelaajanAmmus = new Projectile(4.0, 4.0, Color.Green); |
---|
440 | |
---|
441 | PelaajanAmmus.Shape = Shape.Rectangle; |
---|
442 | |
---|
443 | PelaajanAmmus.Angle = angle; |
---|
444 | PelaajanAmmus.Width = 12; |
---|
445 | PelaajanAmmus.Height = 3; |
---|
446 | PelaajanAmmus.Position = Pelaaja[pelaajaID].Position; |
---|
447 | |
---|
448 | Vector jotain = Vector.FromLengthAndAngle(25.0, angle); |
---|
449 | PelaajanAmmus.Position = PelaajanAmmus.Position + jotain; |
---|
450 | PelaajanAmmus.Mass = 1; |
---|
451 | |
---|
452 | AddCollisionHandler(PelaajanAmmus, PelaajanAmmuksenTuhoaja); |
---|
453 | |
---|
454 | PelaajanAmmus.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "playerProjectile.png")); |
---|
455 | |
---|
456 | if (pelaajaID == 0) |
---|
457 | { |
---|
458 | PelaajanAmmus.Tag = 1; |
---|
459 | PelaajanAmmus.CollisionIgnoreGroup = 1; |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | PelaajanAmmus.Tag = 2; |
---|
464 | PelaajanAmmus.CollisionIgnoreGroup = 2; |
---|
465 | } |
---|
466 | PelaajanAmmus.CollisionIgnoreGroup = 100; |
---|
467 | Add(PelaajanAmmus); |
---|
468 | Vector Pelaajanammus = jotain * 40; |
---|
469 | PelaajanAmmus.Hit(Pelaajanammus); |
---|
470 | ALTKHandler.SoundPlayer.PlaySound(0); |
---|
471 | } |
---|
472 | |
---|
473 | void PelaajanAmmuksenTuhoaja(PhysicsObject PelaajanAmmus, PhysicsObject kohde) |
---|
474 | { |
---|
475 | PelaajanAmmus.Destroy(); |
---|
476 | |
---|
477 | try |
---|
478 | { |
---|
479 | int tagi = (int)kohde.Tag; |
---|
480 | int ammuksenTagi = (int)PelaajanAmmus.Tag; |
---|
481 | |
---|
482 | if (tagi == 5) |
---|
483 | { |
---|
484 | MinionExplosionES.AddEffect(kohde.Position, 800); |
---|
485 | MinionExplosionES2.AddEffect(kohde.Position, 100); |
---|
486 | ALTKHandler.StaticAnimHandler.AddStaticAnim(17, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
487 | ALTKHandler.StaticAnimHandler.AddStaticAnim(18, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
488 | ALTKHandler.SoundPlayer.PlaySound(10); |
---|
489 | kohde.Destroy(); |
---|
490 | if (ammuksenTagi == 1) |
---|
491 | { |
---|
492 | LisaaPisteita(0, Convert.ToInt32(10 * Pelaajan1Kerroin)); |
---|
493 | } |
---|
494 | else |
---|
495 | { |
---|
496 | LisaaPisteita(1, Convert.ToInt32(10 * Pelaajan2Kerroin)); |
---|
497 | } |
---|
498 | } |
---|
499 | else if (tagi == 1337) |
---|
500 | { |
---|
501 | kohde.MaxVelocity = kohde.MaxVelocity - 1.0; |
---|
502 | |
---|
503 | WormholeExplosionES.AddEffect(PelaajanAmmus.Position, 150); |
---|
504 | WormholeExplosionES2.AddEffect(PelaajanAmmus.Position, 5); |
---|
505 | ALTKHandler.SoundPlayer.PlaySound(9); |
---|
506 | |
---|
507 | if (ammuksenTagi == 1) |
---|
508 | { |
---|
509 | LisaaPisteita(0, Convert.ToInt32 (2 * Pelaajan1Kerroin)); |
---|
510 | } |
---|
511 | else |
---|
512 | { |
---|
513 | LisaaPisteita(1, Convert.ToInt32(2 * Pelaajan2Kerroin)); |
---|
514 | } |
---|
515 | |
---|
516 | if (kohde.MaxVelocity < 1) |
---|
517 | { |
---|
518 | WormholeExplosionES.AddEffect(kohde.Position, 500); |
---|
519 | WormholeExplosionES2.AddEffect(kohde.Position, 150); |
---|
520 | ALTKHandler.StaticAnimHandler.AddStaticAnim(15, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
521 | kohde.Destroy(); |
---|
522 | ALTKHandler.SoundPlayer.PlaySound(8); |
---|
523 | CreatePowerUp(kohde.Position); |
---|
524 | |
---|
525 | if (ammuksenTagi == 1) |
---|
526 | { |
---|
527 | LisaaPisteita(0, Convert.ToInt32(13 * Pelaajan1Kerroin)); |
---|
528 | } |
---|
529 | else |
---|
530 | { |
---|
531 | LisaaPisteita(1, Convert.ToInt32(13 * Pelaajan2Kerroin)); |
---|
532 | } |
---|
533 | } |
---|
534 | } |
---|
535 | else if (tagi == 123) |
---|
536 | { |
---|
537 | kohde.Mass = (Math.Abs((kohde.Left - kohde.Right) * (kohde.Top - kohde.Bottom))) / 20; |
---|
538 | kohde.Size = kohde.Size * 0.7; |
---|
539 | |
---|
540 | AsteroidHitEffect(PelaajanAmmus.Position); |
---|
541 | |
---|
542 | if (ammuksenTagi == 1) |
---|
543 | { |
---|
544 | LisaaPisteita(0, Convert.ToInt32((1 / kohde.Mass) * 5 * Pelaajan1Kerroin)); |
---|
545 | |
---|
546 | if (kohde.Mass < 40.0) |
---|
547 | { |
---|
548 | TuhoaAsteroidiEfekti(kohde.Position); |
---|
549 | kohde.Destroy(); |
---|
550 | LisaaKerrointa(0, 0.5); |
---|
551 | } |
---|
552 | } |
---|
553 | else |
---|
554 | { |
---|
555 | LisaaPisteita(1, Convert.ToInt32((1 / kohde.Mass) * 5 * Pelaajan2Kerroin)); |
---|
556 | |
---|
557 | if (kohde.Mass < 40.0) |
---|
558 | { |
---|
559 | TuhoaAsteroidiEfekti(kohde.Position); |
---|
560 | kohde.Destroy(); |
---|
561 | LisaaKerrointa(1, 0.5); |
---|
562 | } |
---|
563 | } |
---|
564 | } |
---|
565 | else if (tagi == 11) |
---|
566 | { |
---|
567 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 5; |
---|
568 | if (ALTKHandler.HealthBars[0].Value < 1) |
---|
569 | { |
---|
570 | PelaajanTuhoaja(); |
---|
571 | } |
---|
572 | } |
---|
573 | else if (tagi == 12) |
---|
574 | { |
---|
575 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 5; |
---|
576 | PelaajanTuhoaja(); |
---|
577 | |
---|
578 | } |
---|
579 | else if (tagi == 8) |
---|
580 | { |
---|
581 | MinionExplosionES.AddEffect(kohde.Position, 200); |
---|
582 | kohde.Destroy(); |
---|
583 | } |
---|
584 | |
---|
585 | } |
---|
586 | catch |
---|
587 | { |
---|
588 | } |
---|
589 | } |
---|
590 | |
---|
591 | void MinioninTuhoaja(PhysicsObject minioni, PhysicsObject kohde) |
---|
592 | { |
---|
593 | try |
---|
594 | { |
---|
595 | int tagi = (int)kohde.Tag; |
---|
596 | if (tagi == 11) |
---|
597 | { |
---|
598 | MinionExplosionES.AddEffect(kohde.Position, 800); |
---|
599 | MinionExplosionES2.AddEffect(kohde.Position, 100); |
---|
600 | ALTKHandler.StaticAnimHandler.AddStaticAnim(17, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
601 | ALTKHandler.StaticAnimHandler.AddStaticAnim(18, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
602 | ALTKHandler.SoundPlayer.PlaySound(10); |
---|
603 | |
---|
604 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
605 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 20; |
---|
606 | minioni.Destroy(); |
---|
607 | PelaajanTuhoaja(); |
---|
608 | LisaaPisteita(0, Convert.ToInt32 ( 10 * Pelaajan1Kerroin)); |
---|
609 | } |
---|
610 | |
---|
611 | if (tagi == 12) |
---|
612 | { |
---|
613 | MinionExplosionES.AddEffect(kohde.Position, 800); |
---|
614 | MinionExplosionES2.AddEffect(kohde.Position, 100); |
---|
615 | ALTKHandler.StaticAnimHandler.AddStaticAnim(17, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
616 | ALTKHandler.StaticAnimHandler.AddStaticAnim(18, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
617 | ALTKHandler.SoundPlayer.PlaySound(10); |
---|
618 | |
---|
619 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
620 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 20; |
---|
621 | minioni.Destroy(); |
---|
622 | PelaajanTuhoaja(); |
---|
623 | LisaaPisteita(1, Convert.ToInt32 ( 10 * Pelaajan2Kerroin)); |
---|
624 | } |
---|
625 | |
---|
626 | } |
---|
627 | catch |
---|
628 | { |
---|
629 | } |
---|
630 | } |
---|
631 | |
---|
632 | void AsteroidiTormaa(PhysicsObject asteroidi, PhysicsObject kohde) |
---|
633 | { |
---|
634 | try |
---|
635 | { |
---|
636 | int tagi = (int)kohde.Tag; |
---|
637 | if (tagi == 1) |
---|
638 | { |
---|
639 | kohde.Destroy(); |
---|
640 | AsteroidHitEffect(asteroidi.Position); |
---|
641 | asteroidi.Mass = (Math.Abs((asteroidi.Left - asteroidi.Right) * (asteroidi.Top - asteroidi.Bottom))) / 20; |
---|
642 | asteroidi.Size = asteroidi.Size * 0.7; |
---|
643 | LisaaPisteita(0, Convert.ToInt32((1 / asteroidi.Mass) * 5 * Pelaajan1Kerroin)); |
---|
644 | if (asteroidi.Mass < 40) |
---|
645 | { |
---|
646 | TuhoaAsteroidiEfekti(asteroidi.Position); |
---|
647 | asteroidi.Destroy(); |
---|
648 | LisaaKerrointa(0, 0.5); |
---|
649 | } |
---|
650 | } |
---|
651 | else if (tagi == 2) |
---|
652 | { |
---|
653 | kohde.Destroy(); |
---|
654 | AsteroidHitEffect(asteroidi.Position); |
---|
655 | asteroidi.Mass = (Math.Abs((asteroidi.Left - asteroidi.Right) * (asteroidi.Top - asteroidi.Bottom))) / 20; |
---|
656 | asteroidi.Size = asteroidi.Size * 0.7; |
---|
657 | LisaaPisteita(1, Convert.ToInt32((1 / asteroidi.Mass) * 5 * Pelaajan2Kerroin)); |
---|
658 | if (asteroidi.Mass < 40) |
---|
659 | { |
---|
660 | TuhoaAsteroidiEfekti(asteroidi.Position); |
---|
661 | asteroidi.Destroy(); |
---|
662 | LisaaKerrointa(1, 0.5); |
---|
663 | } |
---|
664 | |
---|
665 | } |
---|
666 | |
---|
667 | else if (tagi == 11) |
---|
668 | { |
---|
669 | ALTKHandler.HealthBars[0].Value = Convert.ToInt32(Convert.ToDouble(ALTKHandler.HealthBars[0].Value) * (1 - ((asteroidi.Mass / 360.0)))); |
---|
670 | ALTKHandler.SoundPlayer.PlaySound(6); |
---|
671 | PelaajanTuhoaja(); |
---|
672 | } |
---|
673 | else if (tagi == 12) |
---|
674 | { |
---|
675 | ALTKHandler.HealthBars[1].Value = Convert.ToInt32(Convert.ToDouble(ALTKHandler.HealthBars[1].Value) * (1 - ((asteroidi.Mass / 360.0)))); |
---|
676 | ALTKHandler.SoundPlayer.PlaySound(6); |
---|
677 | PelaajanTuhoaja(); |
---|
678 | } |
---|
679 | } |
---|
680 | catch |
---|
681 | { |
---|
682 | } |
---|
683 | } |
---|
684 | |
---|
685 | private void AsteroidHitEffect(Vector position) |
---|
686 | { |
---|
687 | AsteroidExplosionES.AddEffect(position, 200); |
---|
688 | ALTKHandler.StaticAnimHandler.AddStaticAnim(19, |
---|
689 | ALTKHandler.AdjustJypeliVectorToXna(position.X, position.Y)); |
---|
690 | ALTKHandler.SoundPlayer.PlaySound(4); |
---|
691 | } |
---|
692 | |
---|
693 | private void TuhoaAsteroidiEfekti(Vector paikka) |
---|
694 | { |
---|
695 | AsteroidExplosionES.AddEffect(paikka, 400); |
---|
696 | AsteroidExplosionES2.AddEffect(paikka, 200); |
---|
697 | ALTKHandler.StaticAnimHandler.AddStaticAnim(20, |
---|
698 | ALTKHandler.AdjustJypeliVectorToXna(paikka.X, paikka.Y)); |
---|
699 | //ALTKHandler.SoundPlayer.PlaySound(4); |
---|
700 | } |
---|
701 | |
---|
702 | void Minioninliikuttaja_Timeout() |
---|
703 | { |
---|
704 | for (int minionID = 0; minionID < Minioni.Count; minionID++) |
---|
705 | { |
---|
706 | double etäisyys1 = 100000.0; |
---|
707 | double etäisyys2 = 100000.0; |
---|
708 | if (!Pelaaja[0].IsDestroyed) |
---|
709 | { |
---|
710 | double x1 = Math.Abs(Pelaaja[0].X - Minioni[minionID].X); |
---|
711 | double y1 = Math.Abs(Pelaaja[0].Y - Minioni[minionID].Y); |
---|
712 | etäisyys1 = Math.Sqrt(x1 + y1); |
---|
713 | } |
---|
714 | |
---|
715 | if (!Pelaaja[1].IsDestroyed) |
---|
716 | { |
---|
717 | double x2 = Math.Abs(Pelaaja[1].X - Minioni[minionID].X); |
---|
718 | double y2 = Math.Abs(Pelaaja[1].Y - Minioni[minionID].Y); |
---|
719 | etäisyys2 = Math.Sqrt(x2 + y2); |
---|
720 | } |
---|
721 | if (etäisyys1 > etäisyys2) |
---|
722 | { |
---|
723 | MinioninLiike(Minioni[minionID], 1); |
---|
724 | } |
---|
725 | else |
---|
726 | { |
---|
727 | MinioninLiike(Minioni[minionID], 0); |
---|
728 | } |
---|
729 | } |
---|
730 | } |
---|
731 | |
---|
732 | void Minioniajastin_Timeout() |
---|
733 | { |
---|
734 | Timer.SingleShot (2, AjaLuoMinioni); |
---|
735 | } |
---|
736 | |
---|
737 | void Automaattiammus_Timeout() |
---|
738 | { |
---|
739 | if (Keyboard.GetKeyState(Key.RightShift) == ButtonState.Down) |
---|
740 | { |
---|
741 | Timer.SingleShot(0, AjaLuoPelaajan1Ammus); |
---|
742 | } |
---|
743 | |
---|
744 | if (Keyboard.GetKeyState(Key.LeftShift) == ButtonState.Down) |
---|
745 | { |
---|
746 | Timer.SingleShot(0, AjaLuoPelaajan2Ammus); |
---|
747 | } |
---|
748 | } |
---|
749 | |
---|
750 | void MinioninAmmus_Timeout() |
---|
751 | { |
---|
752 | Timer.SingleShot(RandomGen.NextDouble(0.5, 2), AjaLuoMinioninAmmus); |
---|
753 | } |
---|
754 | |
---|
755 | void AjaLuoPelaajan1Ammus() |
---|
756 | { |
---|
757 | LuoPelaajanAmmus(0, Pelaaja[0].Angle); |
---|
758 | } |
---|
759 | |
---|
760 | void AjaLuoPelaajan2Ammus() |
---|
761 | { |
---|
762 | LuoPelaajanAmmus(1, Pelaaja[1].Angle); |
---|
763 | } |
---|
764 | |
---|
765 | void AjaLuoMinioninAmmus() |
---|
766 | { |
---|
767 | for (int mId = 0; mId < Minioni.Count; mId++) |
---|
768 | { |
---|
769 | if (!Minioni[mId].IsDestroyed) |
---|
770 | { |
---|
771 | int jtn = RandomGen.NextInt(10000); |
---|
772 | if (jtn > 5000) |
---|
773 | { |
---|
774 | LuoMinioninAmmus(mId); |
---|
775 | } |
---|
776 | } |
---|
777 | } |
---|
778 | } |
---|
779 | |
---|
780 | void AjaLuoMinioni() |
---|
781 | { |
---|
782 | for (int Madonreikaa = 0; Madonreikaa < Madonreika.Count; Madonreikaa++) |
---|
783 | { |
---|
784 | if (!Madonreika[Madonreikaa].IsDestroyed) |
---|
785 | LuoMinioni(Madonreikaa); |
---|
786 | } |
---|
787 | } |
---|
788 | |
---|
789 | void NaytaAnimaatio() |
---|
790 | { |
---|
791 | int arvo = RandomGen.NextInt(4); |
---|
792 | |
---|
793 | double x = 0.0; |
---|
794 | double y = 0.0; |
---|
795 | |
---|
796 | // yläreuna |
---|
797 | if (arvo == 0) |
---|
798 | { |
---|
799 | x = RandomGen.NextDouble(Level.Left + 30, Level.Right - 30); |
---|
800 | y = RandomGen.NextDouble(Level.Top - 30, Level.Top - 300); |
---|
801 | } |
---|
802 | // alareuna |
---|
803 | else if (arvo == 1) |
---|
804 | { |
---|
805 | x = RandomGen.NextDouble(Level.Left + 30, Level.Right - 30); |
---|
806 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Bottom + 300); |
---|
807 | } |
---|
808 | // vasen reuna |
---|
809 | else if (arvo == 2) |
---|
810 | { |
---|
811 | x = RandomGen.NextDouble(Level.Left + 30, Level.Left + 300); |
---|
812 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Top - 30); |
---|
813 | } |
---|
814 | // oikea reuna |
---|
815 | else |
---|
816 | { |
---|
817 | x = RandomGen.NextDouble(Level.Right - 30, Level.Right - 300); |
---|
818 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Top - 30); |
---|
819 | } |
---|
820 | |
---|
821 | MadonreikaPosX = x; |
---|
822 | MadonreikaPosY = y; |
---|
823 | |
---|
824 | ALTKHandler.StaticAnimHandler.AddStaticAnim(16, ALTKHandler.AdjustJypeliVectorToXna(x, y)); |
---|
825 | ALTKHandler.SoundPlayer.PlaySound(2); |
---|
826 | |
---|
827 | Timer.SingleShot(2, LuoMadonreika); |
---|
828 | } |
---|
829 | |
---|
830 | void LuoMadonreika() |
---|
831 | { |
---|
832 | PhysicsObject madonreika = PhysicsObject.CreateStaticObject(50, 50); |
---|
833 | |
---|
834 | madonreika.X = MadonreikaPosX; |
---|
835 | madonreika.Y = MadonreikaPosY; |
---|
836 | madonreika.CollisionIgnoreGroup = 5; |
---|
837 | madonreika.MaxVelocity = 15.0; |
---|
838 | madonreika.Tag = 1337; |
---|
839 | madonreika.Shape = Shape.Circle; |
---|
840 | madonreika.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole.png")); |
---|
841 | Madonreika.Add(madonreika); |
---|
842 | AddCollisionHandler(madonreika, MadonreikaTormaa); |
---|
843 | Add(madonreika, -3); |
---|
844 | madonreika.AngularVelocity = 1; |
---|
845 | LuoMinioni(Madonreika.Count - 1); |
---|
846 | } |
---|
847 | |
---|
848 | void AsteroidinTuhoaja() |
---|
849 | { |
---|
850 | for (int asteroidiId = 0; asteroidiId < Asteroidi.Count; asteroidiId++) |
---|
851 | { |
---|
852 | if (Math.Abs(Asteroidi[asteroidiId].X) > 500.0 || |
---|
853 | Math.Abs(Asteroidi[asteroidiId].Y) > 500.0) |
---|
854 | { |
---|
855 | Asteroidi[asteroidiId].Destroy(); |
---|
856 | |
---|
857 | Asteroidi.RemoveAt(asteroidiId); |
---|
858 | asteroidiId--; |
---|
859 | } |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | void LuoAsteroidi() |
---|
864 | { |
---|
865 | int arvo = RandomGen.NextInt(4); |
---|
866 | |
---|
867 | double x = 0.0; |
---|
868 | double y = 0.0; |
---|
869 | |
---|
870 | // yläreuna |
---|
871 | if (arvo == 0) |
---|
872 | { |
---|
873 | x = RandomGen.NextDouble(Level.Left -60, Level.Right + 60); |
---|
874 | y = Level.Top + 60; |
---|
875 | } |
---|
876 | // alareuna |
---|
877 | else if (arvo == 1) |
---|
878 | { |
---|
879 | x = RandomGen.NextDouble(Level.Left - 60, Level.Right + 60); |
---|
880 | y = Level.Bottom - 60; |
---|
881 | } |
---|
882 | // vasen reuna |
---|
883 | else if (arvo == 2) |
---|
884 | { |
---|
885 | x = Level.Left - 60; |
---|
886 | y = RandomGen.NextDouble(Level.Bottom - 60, Level.Top + 60); |
---|
887 | } |
---|
888 | // oikea reuna |
---|
889 | else |
---|
890 | { |
---|
891 | x = Level.Right + 60; |
---|
892 | y = RandomGen.NextDouble(Level.Bottom - 60, Level.Top + 60); |
---|
893 | } |
---|
894 | PhysicsObject asteroidi = new PhysicsObject (RandomGen.NextDouble (10, 60), RandomGen.NextDouble(10, 60)); |
---|
895 | asteroidi.Shape = Shape.Circle; |
---|
896 | asteroidi.Color = new Color(96, 96, 96); |
---|
897 | asteroidi.X = x; |
---|
898 | asteroidi.Y = y; |
---|
899 | asteroidi.Mass = (Math.Abs((asteroidi.Left - asteroidi.Right) * (asteroidi.Top - asteroidi.Bottom))) / 20; |
---|
900 | asteroidi.Tag = 123; |
---|
901 | |
---|
902 | Vector suunta = -asteroidi.Position; |
---|
903 | Vector origo = Vector.FromLengthAndAngle(RandomGen.NextDouble(2000, 4000), suunta.Angle); |
---|
904 | Vector ohi = new Vector (RandomGen.NextDouble(-3000.0, 3000.0), RandomGen.NextDouble(-3000.0, 3000.0)); |
---|
905 | Vector hit = origo + ohi; |
---|
906 | |
---|
907 | Asteroidi.Add(asteroidi); |
---|
908 | Add(Asteroidi[Asteroidi.Count -1], 0); |
---|
909 | asteroidi.CollisionIgnoreGroup = 3; |
---|
910 | AddCollisionHandler(Asteroidi[Asteroidi.Count - 1], AsteroidiTormaa); |
---|
911 | asteroidi.Hit(hit); |
---|
912 | asteroidi.AngularVelocity = RandomGen.NextDouble (4, -4); |
---|
913 | |
---|
914 | } |
---|
915 | |
---|
916 | void LuoMinioni(int madonreikaID) |
---|
917 | { |
---|
918 | if (!GameSettings.MinionsEnabled) |
---|
919 | return; |
---|
920 | |
---|
921 | PhysicsObject minioni = new PhysicsObject(20, 20); |
---|
922 | |
---|
923 | minioni.X = Madonreika[madonreikaID].X; |
---|
924 | minioni.Y = Madonreika[madonreikaID].Y; |
---|
925 | minioni.CollisionIgnoreGroup = 5; |
---|
926 | minioni.Shape = Shape.Triangle; |
---|
927 | minioni.Color = Color.Red; |
---|
928 | minioni.Angle = (Pelaaja[1].Position - minioni.Position).Angle; |
---|
929 | minioni.Hit(Vector.FromLengthAndAngle(100, minioni.Angle)); |
---|
930 | minioni.MaxVelocity = 100.0; |
---|
931 | minioni.AngularDamping = 0.1; |
---|
932 | minioni.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_ship.png")); |
---|
933 | minioni.Tag = 5; |
---|
934 | AddCollisionHandler(minioni, MinioninTuhoaja); |
---|
935 | Minioni.Add(minioni); |
---|
936 | Add(Minioni[Minioni.Count - 1]); |
---|
937 | MinioninLiike(Minioni[Minioni.Count - 1], 0); |
---|
938 | } |
---|
939 | |
---|
940 | void MadonreikaTormaa (PhysicsObject madonreika, PhysicsObject kohde) |
---|
941 | { |
---|
942 | try |
---|
943 | { |
---|
944 | int tagi = (int)kohde.Tag; |
---|
945 | |
---|
946 | if (tagi == 1) |
---|
947 | { |
---|
948 | madonreika.MaxVelocity = madonreika.MaxVelocity - 1.0; |
---|
949 | |
---|
950 | WormholeExplosionES.AddEffect(kohde.Position, 150); |
---|
951 | WormholeExplosionES2.AddEffect(kohde.Position, 5); |
---|
952 | ALTKHandler.SoundPlayer.PlaySound(9); |
---|
953 | |
---|
954 | LisaaPisteita(0, Convert.ToInt32 ( 2 * Pelaajan1Kerroin)); |
---|
955 | |
---|
956 | if (kohde.MaxVelocity < 1) |
---|
957 | { |
---|
958 | WormholeExplosionES.AddEffect(madonreika.Position, 500); |
---|
959 | WormholeExplosionES2.AddEffect(madonreika.Position, 150); |
---|
960 | ALTKHandler.StaticAnimHandler.AddStaticAnim(15, ALTKHandler.AdjustJypeliVectorToXna(madonreika.X, madonreika.Y)); |
---|
961 | kohde.Destroy(); |
---|
962 | ALTKHandler.SoundPlayer.PlaySound(8); |
---|
963 | CreatePowerUp(kohde.Position); |
---|
964 | |
---|
965 | LisaaPisteita(0, Convert.ToInt32(13 * Pelaajan1Kerroin)); |
---|
966 | } |
---|
967 | } |
---|
968 | else if (tagi == 2) |
---|
969 | { |
---|
970 | madonreika.MaxVelocity = madonreika.MaxVelocity - 1.0; |
---|
971 | |
---|
972 | WormholeExplosionES.AddEffect(kohde.Position, 150); |
---|
973 | WormholeExplosionES2.AddEffect(kohde.Position, 5); |
---|
974 | ALTKHandler.SoundPlayer.PlaySound(9); |
---|
975 | |
---|
976 | LisaaPisteita(1, Convert.ToInt32 ( 2 * Pelaajan2Kerroin)); |
---|
977 | |
---|
978 | if (kohde.MaxVelocity < 1) |
---|
979 | { |
---|
980 | WormholeExplosionES.AddEffect(kohde.Position, 500); |
---|
981 | WormholeExplosionES2.AddEffect(kohde.Position, 150); |
---|
982 | ALTKHandler.StaticAnimHandler.AddStaticAnim(15, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
983 | kohde.Destroy(); |
---|
984 | ALTKHandler.SoundPlayer.PlaySound(8); |
---|
985 | CreatePowerUp(kohde.Position); |
---|
986 | |
---|
987 | LisaaPisteita(1, Convert.ToInt32(13 * Pelaajan1Kerroin)); |
---|
988 | } |
---|
989 | } |
---|
990 | else if (tagi == 11) |
---|
991 | { |
---|
992 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 17; |
---|
993 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
994 | ALTKHandler.SoundPlayer.PlaySound(6); |
---|
995 | PelaajanTuhoaja(); |
---|
996 | } |
---|
997 | else if (tagi == 12) |
---|
998 | { |
---|
999 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 17; |
---|
1000 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
1001 | ALTKHandler.SoundPlayer.PlaySound(6); |
---|
1002 | PelaajanTuhoaja(); |
---|
1003 | } |
---|
1004 | } |
---|
1005 | catch |
---|
1006 | { |
---|
1007 | } |
---|
1008 | } |
---|
1009 | |
---|
1010 | void LuoMinioninAmmus(int minioniID) |
---|
1011 | { |
---|
1012 | Projectile minioninAmmus = new Projectile(4.0, 4.0, Color.Yellow); |
---|
1013 | minioninAmmus.Angle = Minioni[minioniID].Angle; |
---|
1014 | minioninAmmus.Shape = Shape.Rectangle; |
---|
1015 | minioninAmmus.Width = 8.0; |
---|
1016 | minioninAmmus.Height = 2.0; |
---|
1017 | Vector a = Vector.FromLengthAndAngle(25.0, Minioni[minioniID].Angle); |
---|
1018 | minioninAmmus.Position = Minioni[minioniID].Position + a; |
---|
1019 | minioninAmmus.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minionProjectile.png")); |
---|
1020 | AddCollisionHandler(minioninAmmus, MinioninAmmuksenTuhoaja); |
---|
1021 | minioninAmmus.Tag = 8; |
---|
1022 | minioninAmmus.CollisionIgnoreGroup = 5; |
---|
1023 | Add(minioninAmmus); |
---|
1024 | minioninAmmus.Mass = 0.5; |
---|
1025 | Vector b = Vector.FromLengthAndAngle(250.0, Minioni[minioniID].Angle); |
---|
1026 | minioninAmmus.Hit(b); |
---|
1027 | //ALTKHandler.SoundPlayer.PlaySound(3); |
---|
1028 | } |
---|
1029 | |
---|
1030 | void PelaajanTuhoaja() |
---|
1031 | { |
---|
1032 | if (ALTKHandler.HealthBars[0].Value < 1 && !Pelaaja[0].IsDestroyed) |
---|
1033 | { |
---|
1034 | ALTKHandler.StaticAnimHandler.AddStaticAnim(21, |
---|
1035 | ALTKHandler.AdjustJypeliVectorToXna(Pelaaja[0].X, Pelaaja[0].Y)); |
---|
1036 | |
---|
1037 | PlayerDeathES.AddEffect(Pelaaja[0].Position, 2000); |
---|
1038 | PlayerDeathESL.AddEffect(Pelaaja[0].Position, 4000); |
---|
1039 | PlayerDeathES2.AddEffect(Pelaaja[0].Position, 1400); |
---|
1040 | |
---|
1041 | Pelaaja[0].Destroy(); |
---|
1042 | |
---|
1043 | ALTKHandler.SoundPlayer.PlaySound(7); // BOOOOOOOOOOOOOMMMMMM |
---|
1044 | ALTKHandler.MessageDisplay.AddItem(GameSettings.PlayerNames[0] + " tuhoutui!"); |
---|
1045 | |
---|
1046 | if (Pelaaja[1].IsDestroyed || !GameSettings.MinionsEnabled) |
---|
1047 | { |
---|
1048 | ALTKHandler.MessageDisplay.AddItem("Paina F11 aloittaaksesi uuden pelin."); |
---|
1049 | } |
---|
1050 | } |
---|
1051 | |
---|
1052 | if (ALTKHandler.HealthBars[1].Value < 1 && !Pelaaja[1].IsDestroyed) |
---|
1053 | { |
---|
1054 | ALTKHandler.StaticAnimHandler.AddStaticAnim(21, |
---|
1055 | ALTKHandler.AdjustJypeliVectorToXna(Pelaaja[1].X, Pelaaja[1].Y)); |
---|
1056 | |
---|
1057 | PlayerDeathES.AddEffect(Pelaaja[1].Position, 2000); |
---|
1058 | PlayerDeathESL.AddEffect(Pelaaja[1].Position, 4000); |
---|
1059 | PlayerDeathES2.AddEffect(Pelaaja[1].Position, 1400); |
---|
1060 | |
---|
1061 | Pelaaja[1].Destroy(); |
---|
1062 | |
---|
1063 | ALTKHandler.SoundPlayer.PlaySound(7); // BOOOOOOOOOOOOOMMMMMM |
---|
1064 | ALTKHandler.MessageDisplay.AddItem(GameSettings.PlayerNames[1] + " tuhoutui!"); |
---|
1065 | |
---|
1066 | if (Pelaaja[0].IsDestroyed || !GameSettings.MinionsEnabled) |
---|
1067 | { |
---|
1068 | ALTKHandler.MessageDisplay.AddItem("Paina F11 aloittaaksesi uuden pelin."); |
---|
1069 | } |
---|
1070 | } |
---|
1071 | |
---|
1072 | } |
---|
1073 | |
---|
1074 | void MinioninAmmuksenTuhoaja(PhysicsObject minioninAmmus, PhysicsObject kohde) |
---|
1075 | { |
---|
1076 | minioninAmmus.Destroy(); |
---|
1077 | |
---|
1078 | try |
---|
1079 | { |
---|
1080 | int tagi = (int)kohde.Tag; |
---|
1081 | if (tagi == 11) |
---|
1082 | { |
---|
1083 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 10 ; |
---|
1084 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
1085 | ALTKHandler.SoundPlayer.PlaySound(5); |
---|
1086 | PelaajanTuhoaja(); |
---|
1087 | } |
---|
1088 | else if (tagi == 12) |
---|
1089 | { |
---|
1090 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 10; |
---|
1091 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
1092 | ALTKHandler.SoundPlayer.PlaySound(5); |
---|
1093 | PelaajanTuhoaja(); |
---|
1094 | } |
---|
1095 | else if (tagi == 1 || |
---|
1096 | tagi == 2) |
---|
1097 | { |
---|
1098 | MinionExplosionES.AddEffect(kohde.Position, 200); |
---|
1099 | kohde.Destroy(); |
---|
1100 | } |
---|
1101 | |
---|
1102 | } |
---|
1103 | catch |
---|
1104 | { |
---|
1105 | } |
---|
1106 | } |
---|
1107 | |
---|
1108 | void MinioninLiike(PhysicsObject minioni, int pelaaja) |
---|
1109 | { |
---|
1110 | minioni.Angle = (Pelaaja[pelaaja].Position - minioni.Position).Angle; |
---|
1111 | Vector q = Vector.FromLengthAndAngle(5.0, minioni.Angle); |
---|
1112 | minioni.Hit(q); |
---|
1113 | return; |
---|
1114 | } |
---|
1115 | |
---|
1116 | void LisaaPisteita(int pelaajaID, int pistemaara) |
---|
1117 | { |
---|
1118 | if (pelaajaID == 0) |
---|
1119 | { |
---|
1120 | Pelaajan1Pisteet = Pelaajan1Pisteet + pistemaara; |
---|
1121 | |
---|
1122 | if (Pelaajan1Pisteet > 999) |
---|
1123 | ALTKHandler.ScoreDisplayers[0].Color = Microsoft.Xna.Framework.Color.Red; |
---|
1124 | } |
---|
1125 | |
---|
1126 | |
---|
1127 | if (pelaajaID == 1) |
---|
1128 | { |
---|
1129 | Pelaajan2Pisteet = Pelaajan2Pisteet + pistemaara; |
---|
1130 | |
---|
1131 | if (Pelaajan2Pisteet > 999) |
---|
1132 | ALTKHandler.ScoreDisplayers[1].Color = Microsoft.Xna.Framework.Color.Red; |
---|
1133 | } |
---|
1134 | } |
---|
1135 | |
---|
1136 | void LisaaKerrointa(int pelaajaID, double kerroin) |
---|
1137 | { |
---|
1138 | if (pelaajaID == 0) |
---|
1139 | Pelaajan1Kerroin = Pelaajan1Kerroin + kerroin; |
---|
1140 | if (pelaajaID == 1) |
---|
1141 | Pelaajan2Kerroin = Pelaajan2Kerroin + kerroin; |
---|
1142 | } |
---|
1143 | |
---|
1144 | void AsetaNappaimet() |
---|
1145 | { |
---|
1146 | Keyboard.Listen(Key.Up, ButtonState.Down, AlkuKiihdytys, String.Empty, Pelaaja[0]); |
---|
1147 | Keyboard.Listen(Key.Up, ButtonState.Down, Kiihdyta, String.Empty, Pelaaja[0]); |
---|
1148 | Keyboard.Listen(Key.Down, ButtonState.Down, Hidasta, String.Empty, Pelaaja[0]); |
---|
1149 | Keyboard.Listen(Key.Left, ButtonState.Down, kaannaVasemmalle, String.Empty, Pelaaja[0]); |
---|
1150 | Keyboard.Listen(Key.Right, ButtonState.Down, kaannaOikealle, String.Empty, Pelaaja[0]); |
---|
1151 | Keyboard.Listen(Key.RightShift, ButtonState.Pressed, AjaLuoPelaajan1Ammus, String.Empty); |
---|
1152 | |
---|
1153 | Keyboard.Listen(Key.W, ButtonState.Down, AlkuKiihdytys, String.Empty, Pelaaja[1]); |
---|
1154 | Keyboard.Listen(Key.W, ButtonState.Down, Kiihdyta, String.Empty, Pelaaja[1]); |
---|
1155 | Keyboard.Listen(Key.S, ButtonState.Down, Hidasta, String.Empty, Pelaaja[1]); |
---|
1156 | Keyboard.Listen(Key.A, ButtonState.Down, kaannaVasemmalle, String.Empty, Pelaaja[1]); |
---|
1157 | Keyboard.Listen(Key.D, ButtonState.Down, kaannaOikealle, String.Empty, Pelaaja[1]); |
---|
1158 | Keyboard.Listen(Key.LeftShift, ButtonState.Pressed, AjaLuoPelaajan2Ammus, String.Empty); |
---|
1159 | |
---|
1160 | Keyboard.Listen(Key.F11, ButtonState.Pressed, Reset, String.Empty); |
---|
1161 | } |
---|
1162 | |
---|
1163 | void AlkuKiihdytys(PhysicsObject pelaaja) |
---|
1164 | { |
---|
1165 | if (pelaaja.Velocity.Magnitude < 7) |
---|
1166 | { |
---|
1167 | Vector o = Vector.FromLengthAndAngle(50.0, pelaaja.Angle); |
---|
1168 | pelaaja.Hit(o); |
---|
1169 | ALTKHandler.SoundPlayer.PlaySound(1); |
---|
1170 | } |
---|
1171 | } |
---|
1172 | |
---|
1173 | void Kiihdyta(PhysicsObject pelaaja) |
---|
1174 | { |
---|
1175 | Vector z = Vector.FromLengthAndAngle(5.0, pelaaja.Angle); |
---|
1176 | pelaaja.Hit(z); |
---|
1177 | |
---|
1178 | ALTKHandler.StaticAnimHandler.AddStaticAnim("ENGINE_SMOKE", |
---|
1179 | ALTKHandler.AdjustJypeliVectorToXna(pelaaja.Position.X, pelaaja.Position.Y)); |
---|
1180 | } |
---|
1181 | |
---|
1182 | void Hidasta(PhysicsObject pelaaja) |
---|
1183 | { |
---|
1184 | pelaaja.Velocity = new Vector(pelaaja.Velocity.X * 0.95, pelaaja.Velocity.Y * 0.95); |
---|
1185 | } |
---|
1186 | |
---|
1187 | void kaannaVasemmalle(PhysicsObject pelaaja) |
---|
1188 | { |
---|
1189 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 4); |
---|
1190 | } |
---|
1191 | |
---|
1192 | void kaannaOikealle(PhysicsObject pelaaja) |
---|
1193 | { |
---|
1194 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees - 4); |
---|
1195 | } |
---|
1196 | |
---|
1197 | void PowerUpCollisionHandler(PhysicsObject Powerup, PhysicsObject kohde) |
---|
1198 | { |
---|
1199 | int powUp = (int)Powerup.Tag; |
---|
1200 | int pelaaja = (int)kohde.Tag; |
---|
1201 | |
---|
1202 | if (powUp == 200) |
---|
1203 | { |
---|
1204 | if (pelaaja == 11) |
---|
1205 | { |
---|
1206 | if (ALTKHandler.HealthBars[0].Value < 80) |
---|
1207 | { |
---|
1208 | ALTKHandler.HealthBars[0].Value = Convert.ToInt32(ALTKHandler.HealthBars[0].Value + 20); |
---|
1209 | } |
---|
1210 | else |
---|
1211 | { |
---|
1212 | ALTKHandler.HealthBars[0].Value = 100; |
---|
1213 | } |
---|
1214 | Powerup.Destroy(); |
---|
1215 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1216 | } |
---|
1217 | else if (pelaaja == 12) |
---|
1218 | { |
---|
1219 | if (ALTKHandler.HealthBars[1].Value < 80) |
---|
1220 | { |
---|
1221 | ALTKHandler.HealthBars[1].Value = Convert.ToInt32(ALTKHandler.HealthBars[1].Value + 20); |
---|
1222 | } |
---|
1223 | else |
---|
1224 | { |
---|
1225 | ALTKHandler.HealthBars[1].Value = 100; |
---|
1226 | } |
---|
1227 | Powerup.Destroy(); |
---|
1228 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1229 | } |
---|
1230 | } |
---|
1231 | else if (powUp == 201) |
---|
1232 | { |
---|
1233 | if (pelaaja == 11) |
---|
1234 | { |
---|
1235 | Konekivaari1.Start(200); |
---|
1236 | Powerup.Destroy(); |
---|
1237 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1238 | } |
---|
1239 | else if (pelaaja == 12) |
---|
1240 | { |
---|
1241 | Konekivaari2.Start(200); |
---|
1242 | Powerup.Destroy(); |
---|
1243 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1244 | } |
---|
1245 | } |
---|
1246 | else if (powUp == 202) |
---|
1247 | { |
---|
1248 | if (pelaaja == 11) |
---|
1249 | { |
---|
1250 | Triplefire1.Start(50); |
---|
1251 | Powerup.Destroy(); |
---|
1252 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1253 | } |
---|
1254 | else if (pelaaja == 12) |
---|
1255 | { |
---|
1256 | Triplefire2.Start(50); |
---|
1257 | Powerup.Destroy(); |
---|
1258 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1259 | } |
---|
1260 | } |
---|
1261 | else if (powUp == 203) |
---|
1262 | { |
---|
1263 | if (pelaaja == 11) |
---|
1264 | { |
---|
1265 | ALTKHandler.HealthBars[0].Value = 100; |
---|
1266 | Powerup.Destroy(); |
---|
1267 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1268 | } |
---|
1269 | else if (pelaaja == 12) |
---|
1270 | { |
---|
1271 | ALTKHandler.HealthBars[1].Value = 100; |
---|
1272 | Powerup.Destroy(); |
---|
1273 | ALTKHandler.SoundPlayer.PlaySound(11); |
---|
1274 | } |
---|
1275 | } |
---|
1276 | } |
---|
1277 | |
---|
1278 | void CreatePowerUp(Vector position) |
---|
1279 | { |
---|
1280 | int arvo = RandomGen.NextInt(20); |
---|
1281 | //int pelaaja = (int)pelaajaID].Tag; |
---|
1282 | |
---|
1283 | int tagi = 0; |
---|
1284 | |
---|
1285 | PhysicsObject powerup = PhysicsObject.CreateStaticObject(25.0, 25.0); |
---|
1286 | |
---|
1287 | if (arvo == 1 || arvo == 2) |
---|
1288 | { |
---|
1289 | //Energiaboosti |
---|
1290 | tagi = 200; |
---|
1291 | powerup.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "powerup_health.png")); |
---|
1292 | } |
---|
1293 | else if (arvo == 3 || arvo == 4) |
---|
1294 | { |
---|
1295 | //Konekivääri |
---|
1296 | tagi = 201; |
---|
1297 | powerup.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "powerup_chaingun.png")); |
---|
1298 | } |
---|
1299 | else if (arvo == 5 || arvo == 6 ) |
---|
1300 | { |
---|
1301 | //Triplefire |
---|
1302 | tagi = 202; |
---|
1303 | powerup.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "powerup_triplefire.png")); |
---|
1304 | } |
---|
1305 | else if (arvo == 7) |
---|
1306 | { |
---|
1307 | //Full restore |
---|
1308 | tagi = 203; |
---|
1309 | powerup.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "powerup_fullrestore.png")); |
---|
1310 | } |
---|
1311 | else |
---|
1312 | { |
---|
1313 | return; |
---|
1314 | } |
---|
1315 | |
---|
1316 | powerup.CollisionIgnoreGroup = 5; |
---|
1317 | powerup.Position = position; |
---|
1318 | powerup.Tag = tagi; |
---|
1319 | AddCollisionHandler(powerup, PowerUpCollisionHandler); |
---|
1320 | Add(powerup); |
---|
1321 | } |
---|
1322 | |
---|
1323 | void Reset() |
---|
1324 | { |
---|
1325 | ClearAll(); |
---|
1326 | Asteroidi.Clear(); |
---|
1327 | Minioni.Clear(); |
---|
1328 | Pelaaja.Clear(); |
---|
1329 | Madonreika.Clear(); |
---|
1330 | ALTKHandler.StaticAnimHandler.ClearAnims(); |
---|
1331 | AddInitialAnims(); |
---|
1332 | ALTKHandler.HealthBars[0].Value = 100; |
---|
1333 | ALTKHandler.HealthBars[1].Value = 100; |
---|
1334 | |
---|
1335 | Pelaajan1Pisteet = 0; |
---|
1336 | Pelaajan1Kerroin = 1.0; |
---|
1337 | |
---|
1338 | Pelaajan2Pisteet = 0; |
---|
1339 | Pelaajan2Kerroin = 1.0; |
---|
1340 | |
---|
1341 | ALTKHandler.ScoreDisplayers[0].Color = Microsoft.Xna.Framework.Color.Purple; |
---|
1342 | ALTKHandler.ScoreDisplayers[1].Color = Microsoft.Xna.Framework.Color.Purple; |
---|
1343 | |
---|
1344 | CreateCursor(); |
---|
1345 | SettingsConfirmed = false; |
---|
1346 | ALTKHandler.GameSettingsWindow.Enabled = true; |
---|
1347 | ALTKHandler.GameSettingsWindow.Visible = true; |
---|
1348 | ALTKHandler.Cursor.Visible = true; |
---|
1349 | } |
---|
1350 | |
---|
1351 | #region XNA / ALTK-Based Code |
---|
1352 | |
---|
1353 | private void HandleCursor(AnalogState analogState) |
---|
1354 | { |
---|
1355 | Kursori.AbsolutePosition = new Vector(Kursori.Position.X + analogState.MouseMovement.X, Kursori.Position.Y + analogState.MouseMovement.Y); |
---|
1356 | } |
---|
1357 | |
---|
1358 | protected override void Initialize() |
---|
1359 | { |
---|
1360 | base.Initialize(); |
---|
1361 | |
---|
1362 | InitALTK(); |
---|
1363 | } |
---|
1364 | |
---|
1365 | protected override void Update(Microsoft.Xna.Framework.GameTime gameTime) |
---|
1366 | { |
---|
1367 | base.Update(gameTime); |
---|
1368 | |
---|
1369 | if (ALTKHandler.MusicPlayer.soundEffectInstance.State == Microsoft.Xna.Framework.Audio.SoundState.Stopped) |
---|
1370 | { |
---|
1371 | ALTKHandler.MusicPlayer.LoadTrack("LOOP", true); |
---|
1372 | } |
---|
1373 | |
---|
1374 | ALTKHandler.ScoreDisplayers[0].Value = Pelaajan1Pisteet; |
---|
1375 | ALTKHandler.ScoreDisplayers[1].Value = Pelaajan2Pisteet; |
---|
1376 | ALTKHandler.ScoreDisplayers[2].Value = Pelaajan1Pisteet + Pelaajan2Pisteet; |
---|
1377 | |
---|
1378 | ALTKHandler.ScoreRatioDisplayers[0].Value = Pelaajan1Kerroin; |
---|
1379 | ALTKHandler.ScoreRatioDisplayers[1].Value = Pelaajan2Kerroin; |
---|
1380 | |
---|
1381 | if (Kursori.Position.X > ALTKConstants.WindowWidth / 2.0) |
---|
1382 | Kursori.MoveTo(new Vector(ALTKConstants.WindowWidth / 2.0, Kursori.Position.Y), 1000000.0); |
---|
1383 | else if (Kursori.Position.X < ALTKConstants.WindowWidth / -2.0) |
---|
1384 | Kursori.MoveTo(new Vector(ALTKConstants.WindowWidth / -2.0, Kursori.Position.Y), 1000000.0); |
---|
1385 | |
---|
1386 | if (Kursori.Position.Y > ALTKConstants.WindowHeight / 2.0) |
---|
1387 | Kursori.MoveTo(new Vector(Kursori.Position.X, ALTKConstants.WindowHeight / 2.0), 1000000.0); |
---|
1388 | else if (Kursori.Position.Y < ALTKConstants.WindowHeight / -2.0) |
---|
1389 | Kursori.MoveTo(new Vector(Kursori.Position.X, ALTKConstants.WindowHeight / -2.0), 1000000.0); |
---|
1390 | |
---|
1391 | ALTK.Cursor.SecPosX = Convert.ToInt32((ALTKConstants.WindowWidth / 2) + Kursori.Position.X * 1.12); |
---|
1392 | ALTK.Cursor.SecPosY = Convert.ToInt32(ALTK.ALTKConstants.WindowHeight - ((ALTKConstants.WindowHeight / 2) + Kursori.Position.Y * 1.12)); |
---|
1393 | |
---|
1394 | if (ALTK.GameHandler.DoUpdate) |
---|
1395 | { |
---|
1396 | } |
---|
1397 | else |
---|
1398 | { |
---|
1399 | //PhysicsEnabled = false; |
---|
1400 | } |
---|
1401 | } |
---|
1402 | |
---|
1403 | /// <summary> |
---|
1404 | /// Initializes the ALTKEngine components used by the game. -Rampastring |
---|
1405 | /// </summary> |
---|
1406 | private void InitALTK() |
---|
1407 | { |
---|
1408 | ALTKConstants.WindowWidth = this.Window.ClientBounds.Width; |
---|
1409 | ALTKConstants.WindowHeight = this.Window.ClientBounds.Height; |
---|
1410 | |
---|
1411 | if (ALTKConstants.WindowHeight / ALTKConstants.WindowWidth < 0.9) |
---|
1412 | { |
---|
1413 | ALTKConstants.JypeliToXNARatioY = Convert.ToDouble(ALTKConstants.WindowHeight) / Convert.ToDouble(ALTKConstants.JYDefaultResY); |
---|
1414 | ALTKConstants.JypeliToXNARatioX = ALTKConstants.JypeliToXNARatioY; |
---|
1415 | } |
---|
1416 | else // if (ALTKConstants.WindowHeight > ALTKConstants.WindowWidth) |
---|
1417 | { |
---|
1418 | ALTKConstants.JypeliToXNARatioX = Convert.ToDouble(ALTKConstants.WindowWidth) / Convert.ToDouble(ALTKConstants.JYDefaultResX); |
---|
1419 | ALTKConstants.JypeliToXNARatioY = ALTKConstants.JypeliToXNARatioX; |
---|
1420 | } |
---|
1421 | |
---|
1422 | ALTKConstants.StaticAnimRatioY = Convert.ToDouble(ALTKConstants.WindowHeight) / ALTKConstants.StaticAnimDevelopResY; |
---|
1423 | ALTKConstants.StaticAnimRatioX = Convert.ToDouble(ALTKConstants.WindowWidth) / ALTKConstants.StaticAnimDevelopResX; |
---|
1424 | |
---|
1425 | if (ALTKConstants.StaticAnimRatioY > ALTKConstants.StaticAnimRatioX) |
---|
1426 | ALTKConstants.StaticAnimRatioY = ALTKConstants.StaticAnimRatioX; |
---|
1427 | else |
---|
1428 | ALTKConstants.StaticAnimRatioX = ALTKConstants.StaticAnimRatioY; |
---|
1429 | |
---|
1430 | altkHandler = new ALTKHandler(this); |
---|
1431 | altkHandler.Initialize(); |
---|
1432 | this.Components.Add(altkHandler); |
---|
1433 | |
---|
1434 | AddInitialAnims(); |
---|
1435 | } |
---|
1436 | |
---|
1437 | private void AddInitialAnims() |
---|
1438 | { |
---|
1439 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARS_1", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1440 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARS_2", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1441 | |
---|
1442 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1443 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_BLUE", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1444 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_RED", new Microsoft.Xna.Framework.Vector2(200, 100)); |
---|
1445 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_WHITE", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1446 | |
---|
1447 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE", new Microsoft.Xna.Framework.Vector2(200, -250)); |
---|
1448 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_BLUE", new Microsoft.Xna.Framework.Vector2(400, 250)); |
---|
1449 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_RED", new Microsoft.Xna.Framework.Vector2(-350, -200)); |
---|
1450 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_WHITE", new Microsoft.Xna.Framework.Vector2(-300, 250)); |
---|
1451 | |
---|
1452 | ALTKHandler.MusicPlayer.StopPlaying(); |
---|
1453 | ALTKHandler.MusicPlayer.LoadTrack("INTRO", false); |
---|
1454 | } |
---|
1455 | |
---|
1456 | private void ShowExit() |
---|
1457 | { |
---|
1458 | //this.StopAll(); |
---|
1459 | if (!ALTKHandler.ExitWindow.Enabled && !ALTKHandler.GameSettingsWindow.Enabled) |
---|
1460 | { |
---|
1461 | ALTKHandler.ExitWindow.Enabled = true; |
---|
1462 | ALTKHandler.ExitWindow.Visible = true; |
---|
1463 | |
---|
1464 | ALTKHandler.Cursor.Visible = true; |
---|
1465 | } |
---|
1466 | } |
---|
1467 | |
---|
1468 | #endregion |
---|
1469 | } |
---|