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 | |
---|
30 | public override void Begin() |
---|
31 | { |
---|
32 | #region Cursor handling |
---|
33 | Kursori = new GameObject(32, 32); |
---|
34 | Kursori.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "cursor.png")); |
---|
35 | Kursori.IsVisible = false; |
---|
36 | AnalogHandler handler = new AnalogHandler(HandleCursor); |
---|
37 | Mouse.ListenMovement(0.1, handler, ""); |
---|
38 | Add(Kursori); |
---|
39 | #endregion |
---|
40 | LuoKentta(); |
---|
41 | AsetaNappaimet(); |
---|
42 | LuoAjastin(); |
---|
43 | //LuoMadonreika(); |
---|
44 | //PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
45 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ShowExit, "Lopeta peli"); |
---|
46 | } |
---|
47 | |
---|
48 | void LuoKentta() |
---|
49 | { |
---|
50 | PhysicsObject vasenReuna = Level.CreateLeftBorder(); |
---|
51 | vasenReuna.CollisionIgnoreGroup = 3; |
---|
52 | vasenReuna.IsVisible = false; |
---|
53 | PhysicsObject oikeaReuna = Level.CreateRightBorder(); |
---|
54 | oikeaReuna.IsVisible = false; |
---|
55 | oikeaReuna.CollisionIgnoreGroup = 3; |
---|
56 | PhysicsObject ylaReuna = Level.CreateTopBorder(); |
---|
57 | ylaReuna.IsVisible = false; |
---|
58 | ylaReuna.CollisionIgnoreGroup = 3; |
---|
59 | PhysicsObject alaReuna = Level.CreateBottomBorder(); |
---|
60 | alaReuna.IsVisible = false; |
---|
61 | alaReuna.CollisionIgnoreGroup = 3; |
---|
62 | |
---|
63 | Level.BackgroundColor = Color.Black; |
---|
64 | |
---|
65 | Camera.ZoomToLevel(); |
---|
66 | |
---|
67 | LuoPelaaja(300); |
---|
68 | Pelaaja[0].Tag = 11; |
---|
69 | Pelaaja[0].CollisionIgnoreGroup = 1; |
---|
70 | LuoPelaaja(-300); |
---|
71 | Pelaaja[1].CollisionIgnoreGroup = 2; |
---|
72 | Pelaaja[1].Tag = 12; |
---|
73 | } |
---|
74 | |
---|
75 | void LuoPelaaja(double x) |
---|
76 | { |
---|
77 | PhysicsObject pelaaja = new PhysicsObject(20, 20); |
---|
78 | |
---|
79 | pelaaja.X = x; |
---|
80 | pelaaja.Y = -250; |
---|
81 | pelaaja.Restitution = 0.5; |
---|
82 | pelaaja.AngularDamping = 0.1; |
---|
83 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 90); |
---|
84 | pelaaja.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player.png")); |
---|
85 | Pelaaja.Add(pelaaja); |
---|
86 | Add(Pelaaja[Pelaaja.Count - 1]); |
---|
87 | } |
---|
88 | |
---|
89 | void LuoAjastin() |
---|
90 | { |
---|
91 | MadonreikaAjastin = new Timer(); |
---|
92 | MadonreikaAjastin.Interval = 3; |
---|
93 | MadonreikaAjastin.Timeout += new Action(NaytaAnimaatio); |
---|
94 | MadonreikaAjastin.Start(); |
---|
95 | |
---|
96 | Minioniajastin = new Timer(); |
---|
97 | Minioniajastin.Interval = 2; |
---|
98 | Minioniajastin.Timeout += new Action(Minioniajastin_Timeout); |
---|
99 | Minioniajastin.Start(); |
---|
100 | |
---|
101 | Minioninliikuttaja = new Timer(); |
---|
102 | Minioninliikuttaja.Interval = 0.1; |
---|
103 | Minioninliikuttaja.Timeout += new Action(Minioninliikuttaja_Timeout); |
---|
104 | Minioninliikuttaja.Start(); |
---|
105 | |
---|
106 | Automaattiammus = new Timer(); |
---|
107 | Automaattiammus.Interval = 0.2; |
---|
108 | Automaattiammus.Timeout += new Action(Automaattiammus_Timeout); |
---|
109 | Automaattiammus.Start(); |
---|
110 | |
---|
111 | MinioninAmmus = new Timer(); |
---|
112 | MinioninAmmus.Interval = 1.0; |
---|
113 | MinioninAmmus.Timeout += new Action(MinioninAmmus_Timeout); |
---|
114 | MinioninAmmus.Start(); |
---|
115 | |
---|
116 | Asteroidiajastin = new Timer(); |
---|
117 | Asteroidiajastin.Interval = RandomGen.NextDouble (5, 12); |
---|
118 | Asteroidiajastin.Timeout += new Action(Asteroidiajastin_Timeout); |
---|
119 | Asteroidiajastin.Start(); |
---|
120 | |
---|
121 | TuhoaAsteroidi = new Timer(); |
---|
122 | TuhoaAsteroidi.Interval = 30.0; |
---|
123 | TuhoaAsteroidi.Timeout += new Action(TuhoaAsteroidi_Timeout); |
---|
124 | TuhoaAsteroidi.Start(); |
---|
125 | } |
---|
126 | |
---|
127 | void TuhoaAsteroidi_Timeout() |
---|
128 | { |
---|
129 | Timer.SingleShot(0.0, AsteroidinTuhoaja); |
---|
130 | } |
---|
131 | |
---|
132 | void Asteroidiajastin_Timeout() |
---|
133 | { |
---|
134 | Timer.SingleShot(0.0, LuoAsteroidi); |
---|
135 | } |
---|
136 | |
---|
137 | void LuoPelaajanAmmus(int pelaajaID) |
---|
138 | { |
---|
139 | if (Pelaaja[pelaajaID].IsDestroyed) |
---|
140 | { |
---|
141 | return; |
---|
142 | } |
---|
143 | Projectile PelaajanAmmus = new Projectile(4.0, 4.0, Color.Green); |
---|
144 | PelaajanAmmus.Shape = Shape.Triangle; |
---|
145 | PelaajanAmmus.Position = Pelaaja[pelaajaID].Position; |
---|
146 | Vector jotain = Vector.FromLengthAndAngle(25.0, Pelaaja[pelaajaID].Angle); |
---|
147 | PelaajanAmmus.Position = PelaajanAmmus.Position + jotain; |
---|
148 | AddCollisionHandler(PelaajanAmmus, PelaajanAmmuksenTuhoaja); |
---|
149 | if (pelaajaID == 0) |
---|
150 | { |
---|
151 | PelaajanAmmus.Tag = 1; |
---|
152 | PelaajanAmmus.CollisionIgnoreGroup = 1; |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | PelaajanAmmus.Tag = 2; |
---|
157 | PelaajanAmmus.CollisionIgnoreGroup = 2; |
---|
158 | } |
---|
159 | Add(PelaajanAmmus); |
---|
160 | Vector Pelaajanammus = jotain * 80; |
---|
161 | PelaajanAmmus.Hit(Pelaajanammus); |
---|
162 | ALTKHandler.SoundPlayer.PlaySound(0); |
---|
163 | } |
---|
164 | |
---|
165 | void PelaajanAmmuksenTuhoaja(PhysicsObject PelaajanAmmus, PhysicsObject kohde) |
---|
166 | { |
---|
167 | PelaajanAmmus.Destroy(); |
---|
168 | |
---|
169 | try |
---|
170 | { |
---|
171 | int tagi = (int)kohde.Tag; |
---|
172 | if (tagi == 5) |
---|
173 | { |
---|
174 | kohde.Destroy(); |
---|
175 | } |
---|
176 | else if (tagi == 1337) |
---|
177 | { |
---|
178 | kohde.MaxVelocity = kohde.MaxVelocity - 1.0; |
---|
179 | if (kohde.MaxVelocity < 1) |
---|
180 | { |
---|
181 | kohde.Destroy(); |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | catch |
---|
186 | { |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | void MinioninTuhoaja(PhysicsObject minioni, PhysicsObject kohde) |
---|
191 | { |
---|
192 | try |
---|
193 | { |
---|
194 | int tagi = (int)kohde.Tag; |
---|
195 | if (tagi == 11) |
---|
196 | { |
---|
197 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 20; |
---|
198 | minioni.Destroy(); |
---|
199 | PelaajanTuhoaja(); |
---|
200 | } |
---|
201 | |
---|
202 | if (tagi == 12) |
---|
203 | { |
---|
204 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 20; |
---|
205 | minioni.Destroy(); |
---|
206 | PelaajanTuhoaja(); |
---|
207 | } |
---|
208 | |
---|
209 | } |
---|
210 | catch |
---|
211 | { |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | void AsteroidiTormaa(PhysicsObject asteroidi, PhysicsObject kohde) |
---|
216 | { |
---|
217 | try |
---|
218 | { |
---|
219 | int tagi = (int)kohde.Tag; |
---|
220 | if (tagi == 11) |
---|
221 | { |
---|
222 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value * Convert.ToInt32((asteroidi.Mass / 3600)); |
---|
223 | PelaajanTuhoaja(); |
---|
224 | } |
---|
225 | else if (tagi == 12) |
---|
226 | { |
---|
227 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[0].Value * Convert.ToInt32((asteroidi.Mass / 3600)); |
---|
228 | PelaajanTuhoaja(); |
---|
229 | } |
---|
230 | } |
---|
231 | catch |
---|
232 | { |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | void Minioninliikuttaja_Timeout() |
---|
237 | { |
---|
238 | for (int minionID = 0; minionID < Minioni.Count; minionID++) |
---|
239 | { |
---|
240 | double etäisyys1 = 100000.0; |
---|
241 | double etäisyys2 = 100000.0; |
---|
242 | if (!Pelaaja[0].IsDestroyed) |
---|
243 | { |
---|
244 | double x1 = Math.Abs(Pelaaja[0].X - Minioni[minionID].X); |
---|
245 | double y1 = Math.Abs(Pelaaja[0].Y - Minioni[minionID].Y); |
---|
246 | etäisyys1 = Math.Sqrt(x1 + y1); |
---|
247 | } |
---|
248 | |
---|
249 | if (!Pelaaja[1].IsDestroyed) |
---|
250 | { |
---|
251 | double x2 = Math.Abs(Pelaaja[1].X - Minioni[minionID].X); |
---|
252 | double y2 = Math.Abs(Pelaaja[1].Y - Minioni[minionID].Y); |
---|
253 | etäisyys2 = Math.Sqrt(x2 + y2); |
---|
254 | } |
---|
255 | if (etäisyys1 > etäisyys2) |
---|
256 | { |
---|
257 | MinioninLiike(Minioni[minionID], 1); |
---|
258 | } |
---|
259 | else |
---|
260 | { |
---|
261 | MinioninLiike(Minioni[minionID], 0); |
---|
262 | } |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | void Minioniajastin_Timeout() |
---|
267 | { |
---|
268 | Timer.SingleShot (2, AjaLuoMinioni); |
---|
269 | } |
---|
270 | |
---|
271 | void Automaattiammus_Timeout() |
---|
272 | { |
---|
273 | if (Keyboard.GetKeyState(Key.RightShift) == ButtonState.Down) |
---|
274 | { |
---|
275 | Timer.SingleShot(0, AjaLuoPelaajan1Ammus); |
---|
276 | } |
---|
277 | |
---|
278 | if (Keyboard.GetKeyState(Key.LeftShift) == ButtonState.Down) |
---|
279 | { |
---|
280 | Timer.SingleShot(0, AjaLuoPelaajan2Ammus); |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | void MinioninAmmus_Timeout() |
---|
285 | { |
---|
286 | Timer.SingleShot(RandomGen.NextDouble(0.5, 2), AjaLuoMinioninAmmus); |
---|
287 | } |
---|
288 | |
---|
289 | void AjaLuoPelaajan1Ammus() |
---|
290 | { |
---|
291 | LuoPelaajanAmmus(0); |
---|
292 | } |
---|
293 | |
---|
294 | void AjaLuoMinioninAmmus() |
---|
295 | { |
---|
296 | for (int mId = 0; mId < Minioni.Count; mId++) |
---|
297 | { |
---|
298 | if (!Minioni[mId].IsDestroyed) |
---|
299 | { |
---|
300 | int jtn = RandomGen.NextInt(10000); |
---|
301 | if (jtn > 5000) |
---|
302 | { |
---|
303 | LuoMinioninAmmus(mId); |
---|
304 | } |
---|
305 | } |
---|
306 | } |
---|
307 | } |
---|
308 | |
---|
309 | void AjaLuoPelaajan2Ammus() |
---|
310 | { |
---|
311 | LuoPelaajanAmmus(1); |
---|
312 | } |
---|
313 | |
---|
314 | void AjaLuoMinioni() |
---|
315 | { |
---|
316 | for (int Madonreikaa = 0; Madonreikaa < Madonreika.Count; Madonreikaa++) |
---|
317 | { |
---|
318 | if (!Madonreika[Madonreikaa].IsDestroyed) |
---|
319 | LuoMinioni(Madonreikaa); |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | void NaytaAnimaatio() |
---|
324 | { |
---|
325 | Timer.SingleShot(2, LuoMadonreika); |
---|
326 | } |
---|
327 | |
---|
328 | void AsteroidinTuhoaja() |
---|
329 | { |
---|
330 | for (int asteroidiId = 0; asteroidiId < Asteroidi.Count; asteroidiId++) |
---|
331 | { |
---|
332 | if (Math.Abs(Asteroidi[asteroidiId].X) > 500.0 || |
---|
333 | Math.Abs(Asteroidi[asteroidiId].Y) > 500.0) |
---|
334 | { |
---|
335 | Asteroidi[asteroidiId].Destroy(); |
---|
336 | Asteroidi.RemoveAt(asteroidiId); |
---|
337 | asteroidiId--; |
---|
338 | ALTKHandler.MessageDisplay.AddItem("545455453453453453454354"); |
---|
339 | } |
---|
340 | } |
---|
341 | } |
---|
342 | |
---|
343 | void LuoMadonreika() |
---|
344 | { |
---|
345 | int arvo = RandomGen.NextInt(4); |
---|
346 | |
---|
347 | double x = 0.0; |
---|
348 | double y = 0.0; |
---|
349 | |
---|
350 | // yläreuna |
---|
351 | if (arvo == 0) |
---|
352 | { |
---|
353 | x = RandomGen.NextDouble(Level.Left + 30, Level.Right - 30); |
---|
354 | y = RandomGen.NextDouble(Level.Top - 30, Level.Top - 300); |
---|
355 | } |
---|
356 | // alareuna |
---|
357 | else if (arvo == 1) |
---|
358 | { |
---|
359 | x = RandomGen.NextDouble(Level.Left + 30, Level.Right - 30); |
---|
360 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Bottom + 300); |
---|
361 | } |
---|
362 | // vasen reuna |
---|
363 | else if (arvo == 2) |
---|
364 | { |
---|
365 | x = RandomGen.NextDouble(Level.Left + 30, Level.Left + 300); |
---|
366 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Top - 30); |
---|
367 | } |
---|
368 | // oikea reuna |
---|
369 | else |
---|
370 | { |
---|
371 | x = RandomGen.NextDouble(Level.Right - 30, Level.Right - 300); |
---|
372 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Top - 30); |
---|
373 | } |
---|
374 | |
---|
375 | PhysicsObject madonreika = PhysicsObject.CreateStaticObject(50, 50); |
---|
376 | |
---|
377 | madonreika.X = x; |
---|
378 | madonreika.Y = y; |
---|
379 | madonreika.CollisionIgnoreGroup = 5; |
---|
380 | madonreika.MaxVelocity = 15.0; |
---|
381 | madonreika.Tag = 1337; |
---|
382 | Madonreika.Add(madonreika); |
---|
383 | Add(madonreika, -3); |
---|
384 | AddCollisionHandler(madonreika, MadonreikaTormaa); |
---|
385 | LuoMinioni(Madonreika.Count - 1); |
---|
386 | ALTKHandler.SoundPlayer.PlaySound(2); |
---|
387 | } |
---|
388 | |
---|
389 | void LuoAsteroidi() |
---|
390 | { |
---|
391 | int arvo = RandomGen.NextInt(4); |
---|
392 | |
---|
393 | double x = 0.0; |
---|
394 | double y = 0.0; |
---|
395 | |
---|
396 | // yläreuna |
---|
397 | if (arvo == 0) |
---|
398 | { |
---|
399 | x = RandomGen.NextDouble(Level.Left -60, Level.Right + 60); |
---|
400 | y = Level.Top + 60; |
---|
401 | } |
---|
402 | // alareuna |
---|
403 | else if (arvo == 1) |
---|
404 | { |
---|
405 | x = RandomGen.NextDouble(Level.Left - 60, Level.Right + 60); |
---|
406 | y = Level.Bottom - 60; |
---|
407 | } |
---|
408 | // vasen reuna |
---|
409 | else if (arvo == 2) |
---|
410 | { |
---|
411 | x = Level.Left - 60; |
---|
412 | y = RandomGen.NextDouble(Level.Bottom - 60, Level.Top + 60); |
---|
413 | } |
---|
414 | // oikea reuna |
---|
415 | else |
---|
416 | { |
---|
417 | x = Level.Right + 60; |
---|
418 | y = RandomGen.NextDouble(Level.Bottom - 60, Level.Top + 60); |
---|
419 | } |
---|
420 | PhysicsObject asteroidi = new PhysicsObject (RandomGen.NextDouble (10, 60), RandomGen.NextDouble(10, 60)); |
---|
421 | asteroidi.Shape = Shape.Circle; |
---|
422 | asteroidi.X = x; |
---|
423 | asteroidi.Y = y; |
---|
424 | asteroidi.Mass = (Math.Abs((asteroidi.Left - asteroidi.Right) * (asteroidi.Top - asteroidi.Bottom))) / 20; |
---|
425 | Vector position = -asteroidi.Position; |
---|
426 | Vector random = Vector.FromLengthAndAngle(RandomGen.NextDouble(2000, 4000), position.Angle); |
---|
427 | Asteroidi.Add(asteroidi); |
---|
428 | Add(Asteroidi[Asteroidi.Count -1], 0); |
---|
429 | asteroidi.CollisionIgnoreGroup = 3; |
---|
430 | asteroidi.Hit(random); |
---|
431 | asteroidi.AngularVelocity = RandomGen.NextDouble (4, -4); |
---|
432 | |
---|
433 | } |
---|
434 | |
---|
435 | void LuoMinioni(int madonreikaID) |
---|
436 | { |
---|
437 | PhysicsObject minioni = new PhysicsObject(20, 20); |
---|
438 | |
---|
439 | minioni.X = Madonreika[madonreikaID].X; |
---|
440 | minioni.Y = Madonreika[madonreikaID].Y; |
---|
441 | minioni.CollisionIgnoreGroup = 5; |
---|
442 | minioni.Shape = Shape.Triangle; |
---|
443 | minioni.Color = Color.Red; |
---|
444 | minioni.Angle = (Pelaaja[1].Position - minioni.Position).Angle; |
---|
445 | minioni.Hit(Vector.FromLengthAndAngle(100, minioni.Angle)); |
---|
446 | minioni.MaxVelocity = 100.0; |
---|
447 | minioni.AngularDamping = 0.1; |
---|
448 | minioni.Tag = 5; |
---|
449 | AddCollisionHandler(minioni, MinioninTuhoaja); |
---|
450 | Minioni.Add(minioni); |
---|
451 | Add(Minioni[Minioni.Count - 1]); |
---|
452 | MinioninLiike(Minioni[Minioni.Count - 1], 0); |
---|
453 | } |
---|
454 | |
---|
455 | void MadonreikaTormaa (PhysicsObject madonreika, PhysicsObject kohde) |
---|
456 | { |
---|
457 | try |
---|
458 | { |
---|
459 | int tagi = (int)kohde.Tag; |
---|
460 | if (tagi == 11) |
---|
461 | { |
---|
462 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 30; |
---|
463 | } |
---|
464 | else if (tagi == 12) |
---|
465 | { |
---|
466 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 30; |
---|
467 | } |
---|
468 | } |
---|
469 | catch |
---|
470 | { |
---|
471 | } |
---|
472 | PelaajanTuhoaja(); |
---|
473 | } |
---|
474 | |
---|
475 | void LuoMinioninAmmus(int minioniID) |
---|
476 | { |
---|
477 | Projectile minioninAmmus = new Projectile(4.0, 4.0, Color.Yellow); |
---|
478 | minioninAmmus.Angle = Minioni[minioniID].Angle; |
---|
479 | minioninAmmus.Shape = Shape.Rectangle; |
---|
480 | minioninAmmus.Width = 8.0; |
---|
481 | minioninAmmus.Height = 2.0; |
---|
482 | Vector a = Vector.FromLengthAndAngle(25.0, Minioni[minioniID].Angle); |
---|
483 | minioninAmmus.Position = Minioni[minioniID].Position + a; |
---|
484 | AddCollisionHandler(minioninAmmus, MinioninAmmuksenTuhoaja); |
---|
485 | minioninAmmus.CollisionIgnoreGroup = 5; |
---|
486 | Add(minioninAmmus); |
---|
487 | Vector b = Vector.FromLengthAndAngle(2000.0, Minioni[minioniID].Angle); |
---|
488 | minioninAmmus.Hit(b); |
---|
489 | ALTKHandler.SoundPlayer.PlaySound(3); |
---|
490 | } |
---|
491 | |
---|
492 | void PelaajanTuhoaja() |
---|
493 | { |
---|
494 | //if (ALTKHandler.HealthBars[0].Value < 1) |
---|
495 | //{ |
---|
496 | // Pelaaja[0].Destroy(); |
---|
497 | //} |
---|
498 | |
---|
499 | //if (ALTKHandler.HealthBars[1].Value < 1) |
---|
500 | //{ |
---|
501 | // Pelaaja[1].Destroy(); |
---|
502 | //} |
---|
503 | |
---|
504 | } |
---|
505 | |
---|
506 | void MinioninAmmuksenTuhoaja(PhysicsObject minioninAmmus, PhysicsObject kohde) |
---|
507 | { |
---|
508 | minioninAmmus.Destroy(); |
---|
509 | |
---|
510 | try |
---|
511 | { |
---|
512 | int tagi = (int)kohde.Tag; |
---|
513 | if (tagi == 11) |
---|
514 | { |
---|
515 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 10 ; |
---|
516 | PelaajanTuhoaja(); |
---|
517 | } |
---|
518 | else if (tagi == 12) |
---|
519 | { |
---|
520 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 10; |
---|
521 | PelaajanTuhoaja(); |
---|
522 | } |
---|
523 | |
---|
524 | } |
---|
525 | catch |
---|
526 | { |
---|
527 | } |
---|
528 | } |
---|
529 | |
---|
530 | void MinioninLiike(PhysicsObject minioni, int pelaaja) |
---|
531 | { |
---|
532 | minioni.Angle = (Pelaaja[pelaaja].Position - minioni.Position).Angle; |
---|
533 | Vector q = Vector.FromLengthAndAngle(5.0, minioni.Angle); |
---|
534 | minioni.Hit(q); |
---|
535 | return; |
---|
536 | } |
---|
537 | |
---|
538 | void AsetaNappaimet() |
---|
539 | { |
---|
540 | Keyboard.Listen(Key.Up, ButtonState.Down, AlkuKiihdytys, null, Pelaaja[0]); |
---|
541 | Keyboard.Listen(Key.Up, ButtonState.Down, Kiihdyta, null, Pelaaja[0]); |
---|
542 | Keyboard.Listen(Key.Down, ButtonState.Down, Hidasta, null, Pelaaja[0]); |
---|
543 | Keyboard.Listen(Key.Left, ButtonState.Down, kaannaVasemmalle, null, Pelaaja[0]); |
---|
544 | Keyboard.Listen(Key.Right, ButtonState.Down, kaannaOikealle, null, Pelaaja[0]); |
---|
545 | Keyboard.Listen(Key.RightShift, ButtonState.Pressed, LuoPelaajanAmmus, null, 0); |
---|
546 | |
---|
547 | Keyboard.Listen(Key.W, ButtonState.Down, AlkuKiihdytys, null, Pelaaja[1]); |
---|
548 | Keyboard.Listen(Key.W, ButtonState.Down, Kiihdyta, null, Pelaaja[1]); |
---|
549 | Keyboard.Listen(Key.S, ButtonState.Down, Hidasta, null, Pelaaja[1]); |
---|
550 | Keyboard.Listen(Key.A, ButtonState.Down, kaannaVasemmalle, null, Pelaaja[1]); |
---|
551 | Keyboard.Listen(Key.D, ButtonState.Down, kaannaOikealle, null, Pelaaja[1]); |
---|
552 | Keyboard.Listen(Key.LeftShift, ButtonState.Pressed, LuoPelaajanAmmus, null, 1); |
---|
553 | } |
---|
554 | |
---|
555 | void AlkuKiihdytys(PhysicsObject pelaaja) |
---|
556 | { |
---|
557 | if (pelaaja.Velocity.Magnitude < 7) |
---|
558 | { |
---|
559 | Vector o = Vector.FromLengthAndAngle(50.0, pelaaja.Angle); |
---|
560 | pelaaja.Hit(o); |
---|
561 | ALTKHandler.SoundPlayer.PlaySound(1); |
---|
562 | } |
---|
563 | } |
---|
564 | |
---|
565 | void Kiihdyta(PhysicsObject pelaaja) |
---|
566 | { |
---|
567 | Vector z = Vector.FromLengthAndAngle(5.0, pelaaja.Angle); |
---|
568 | pelaaja.Hit(z); |
---|
569 | } |
---|
570 | |
---|
571 | void Hidasta(PhysicsObject pelaaja) |
---|
572 | { |
---|
573 | pelaaja.Velocity = new Vector(pelaaja.Velocity.X * 0.95, pelaaja.Velocity.Y * 0.95); |
---|
574 | } |
---|
575 | |
---|
576 | void kaannaVasemmalle(PhysicsObject pelaaja) |
---|
577 | { |
---|
578 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 4); |
---|
579 | } |
---|
580 | |
---|
581 | void kaannaOikealle(PhysicsObject pelaaja) |
---|
582 | { |
---|
583 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees - 4); |
---|
584 | } |
---|
585 | |
---|
586 | #region XNA / ALTK-Based Code |
---|
587 | |
---|
588 | private void HandleCursor(AnalogState analogState) |
---|
589 | { |
---|
590 | Kursori.AbsolutePosition = new Vector(Kursori.Position.X + analogState.MouseMovement.X, Kursori.Position.Y + analogState.MouseMovement.Y); |
---|
591 | } |
---|
592 | |
---|
593 | protected override void Initialize() |
---|
594 | { |
---|
595 | base.Initialize(); |
---|
596 | |
---|
597 | InitALTK(); |
---|
598 | } |
---|
599 | |
---|
600 | protected override void Update(Microsoft.Xna.Framework.GameTime gameTime) |
---|
601 | { |
---|
602 | base.Update(gameTime); |
---|
603 | |
---|
604 | //for (int minioniId = 0; minioniId < Minioni.Count; minioniId++) |
---|
605 | //{ |
---|
606 | // MinioninLiike(Minioni[minioniId]); |
---|
607 | //} |
---|
608 | |
---|
609 | //ALTKHandler.MessageDisplay.AddItem("Trololollolollololoo, lololololooo..."); |
---|
610 | |
---|
611 | if (Kursori.Position.X > ALTKConstants.WindowWidth / 2.0) |
---|
612 | Kursori.MoveTo(new Vector(ALTKConstants.WindowWidth / 2.0, Kursori.Position.Y), 1000000.0); |
---|
613 | else if (Kursori.Position.X < ALTKConstants.WindowWidth / -2.0) |
---|
614 | Kursori.MoveTo(new Vector(ALTKConstants.WindowWidth / -2.0, Kursori.Position.Y), 1000000.0); |
---|
615 | |
---|
616 | if (Kursori.Position.Y > ALTKConstants.WindowHeight / 2.0) |
---|
617 | Kursori.MoveTo(new Vector(Kursori.Position.X, ALTKConstants.WindowHeight / 2.0), 1000000.0); |
---|
618 | else if (Kursori.Position.Y < ALTKConstants.WindowHeight / -2.0) |
---|
619 | Kursori.MoveTo(new Vector(Kursori.Position.X, ALTKConstants.WindowHeight / -2.0), 1000000.0); |
---|
620 | |
---|
621 | ALTK.Cursor.SecPosX = Convert.ToInt32((ALTKConstants.WindowWidth / 2) + Kursori.Position.X); |
---|
622 | ALTK.Cursor.SecPosY = Convert.ToInt32(ALTK.ALTKConstants.WindowHeight - ((ALTKConstants.WindowHeight / 2) + Kursori.Position.Y)); |
---|
623 | |
---|
624 | //ALTK.Cursor.PosX = Convert.ToInt32((ALTKConstants.WindowWidth / 2) + Kursori.Position.X); |
---|
625 | //ALTK.Cursor.PosY = ALTK.Cursor |
---|
626 | |
---|
627 | //MessageDisplay.Clear(); |
---|
628 | //MessageDisplay.Add(Convert.ToString(ALTK.Cursor.SecPosX + "; " + ALTK.Cursor.SecPosY)); |
---|
629 | |
---|
630 | //if (Keyboard.GetKeyState(Key.Up) == ButtonState.Down) |
---|
631 | //{ |
---|
632 | // Vector impulssi = Vector.FromLengthAndAngle(2.0, po.Angle); |
---|
633 | // po.Hit(impulssi); |
---|
634 | //} |
---|
635 | |
---|
636 | //if (Keyboard.GetKeyState(Key.Left) == ButtonState.Down) |
---|
637 | //{ |
---|
638 | // po.Angle = Angle.FromDegrees(po.Angle.Degrees - 5.0); |
---|
639 | //} |
---|
640 | |
---|
641 | //if (Keyboard.GetKeyState(Key.Right) == ButtonState.Down) |
---|
642 | //{ |
---|
643 | // po.Angle = Angle.FromDegrees(po.Angle.Degrees + 5.0); |
---|
644 | //} |
---|
645 | |
---|
646 | //if (Keyboard.GetKeyState(Key.Down) == ButtonState.Down) |
---|
647 | //{ |
---|
648 | // if (po.Velocity.Angle == po.Angle) |
---|
649 | // { |
---|
650 | // Vector impulssi = Vector.FromLengthAndAngle(-2.0, po.Angle); |
---|
651 | // po.Hit(impulssi); |
---|
652 | // } |
---|
653 | //} |
---|
654 | |
---|
655 | if (ALTK.GameHandler.DoUpdate) |
---|
656 | { |
---|
657 | } |
---|
658 | else |
---|
659 | { |
---|
660 | //PhysicsEnabled = false; |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | /// <summary> |
---|
665 | /// Initializes the ALTKEngine components used by the game. -Rampastring |
---|
666 | /// </summary> |
---|
667 | private void InitALTK() |
---|
668 | { |
---|
669 | ALTKConstants.WindowWidth = this.Window.ClientBounds.Width; |
---|
670 | ALTKConstants.WindowHeight = this.Window.ClientBounds.Height; |
---|
671 | |
---|
672 | altkHandler = new ALTKHandler(this); |
---|
673 | altkHandler.Initialize(); |
---|
674 | this.Components.Add(altkHandler); |
---|
675 | |
---|
676 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARS_1", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
677 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARS_2", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
678 | |
---|
679 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
680 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_BLUE", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
681 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_RED", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
682 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_WHITE", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
683 | |
---|
684 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE", new Microsoft.Xna.Framework.Vector2(200, -250)); |
---|
685 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_BLUE", new Microsoft.Xna.Framework.Vector2(400, 250)); |
---|
686 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_RED", new Microsoft.Xna.Framework.Vector2(-200, -200)); |
---|
687 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_WHITE", new Microsoft.Xna.Framework.Vector2(-250, 300)); |
---|
688 | } |
---|
689 | |
---|
690 | private void ShowExit() |
---|
691 | { |
---|
692 | //this.StopAll(); |
---|
693 | if (!ALTKHandler.ExitWindow.Enabled) |
---|
694 | { |
---|
695 | ALTKHandler.ExitWindow.Enabled = true; |
---|
696 | ALTKHandler.ExitWindow.Visible = true; |
---|
697 | |
---|
698 | Kursori.IsVisible = true; |
---|
699 | } |
---|
700 | } |
---|
701 | |
---|
702 | #endregion |
---|
703 | } |
---|