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 | using Microsoft.Xna.Framework.Content; |
---|
9 | |
---|
10 | public partial class Attack_to_Agora : PhysicsGame |
---|
11 | { |
---|
12 | private Animation chuckinkavely; |
---|
13 | private Animation chuckinKavelyFlipped; |
---|
14 | |
---|
15 | /// <summary> |
---|
16 | /// Vakiot kannattaa merkitä constiksi (ei voi muuttaa). Tällöin ne kirjoitetaan isolla. |
---|
17 | /// </summary> |
---|
18 | const double NOPEUS = 500; // 500 |
---|
19 | const double HYPPYVOIMA = 1500; |
---|
20 | double prevVelocityX = 0.0; |
---|
21 | const double STOP_LIMIT_X = 1; |
---|
22 | bool controlsActive = true; |
---|
23 | |
---|
24 | Image level1 = LoadImage("kentta1"); |
---|
25 | Image taistelijanvarjo = LoadImage("varjo"); |
---|
26 | Image taistelijaOlio = LoadImage("olio"); |
---|
27 | Image cCaseD = LoadImage("laatikko_opening"); |
---|
28 | Image cCaseF = LoadImage("caseavausruutu"); |
---|
29 | Image karambitInspect = LoadImage("karambitfade"); |
---|
30 | Image keyInspect = LoadImage("avaintyohuoneeseen"); |
---|
31 | Image tormaavavihollinen = LoadImage("ajlauta"); |
---|
32 | |
---|
33 | Image ePalkkiTyhja = LoadImage("healthbarempty"); |
---|
34 | Image ePalkkiTaysi = LoadImage("healthbarfull"); |
---|
35 | |
---|
36 | Image valveAlku = LoadImage("peliaukeaa1"); |
---|
37 | Image ajAlku = LoadImage("peliaukeaa2"); |
---|
38 | private bool stSequenceSkipped = false; |
---|
39 | |
---|
40 | Elava taistelija; |
---|
41 | AssaultRifle taistelijanAse; |
---|
42 | const double ASEEN_DMG = 25.0; |
---|
43 | const double WEAPON_INACCURACY = 20.0; |
---|
44 | bool walkBackwards = false; |
---|
45 | |
---|
46 | const double VIHOLLISEN_TORMAYSDMG = 4.0; |
---|
47 | |
---|
48 | int kenttaNro = 18; |
---|
49 | |
---|
50 | /// <summary> |
---|
51 | /// Mitä tehdään tämänhetkisessä kentässä osuttaessa triggeriin. |
---|
52 | /// </summary> |
---|
53 | Action TriggerAction; |
---|
54 | bool tActionTriggered = false; |
---|
55 | |
---|
56 | /// <summary> |
---|
57 | /// Viimeisen pelissä olevan kentän indeksi. |
---|
58 | /// </summary> |
---|
59 | const int VIIMEINEN_KENTTA = 19; |
---|
60 | |
---|
61 | #region yleiset toiminnot |
---|
62 | public override void Begin() |
---|
63 | { |
---|
64 | SetWindowSize(1366, 768); |
---|
65 | LataaContent(); |
---|
66 | AloitusAnimaatio(); |
---|
67 | } |
---|
68 | |
---|
69 | void AloitaPeli() |
---|
70 | { |
---|
71 | ClearAll(); |
---|
72 | LuoKentta(); |
---|
73 | AsetaOhjaimet(); |
---|
74 | KirkastaRuutua(0.03, 1.0); |
---|
75 | ensimmainentehtava.Play(); |
---|
76 | Timer.SingleShot(4.0, delegate { taustamusiikki_1.Play(); }); |
---|
77 | } |
---|
78 | |
---|
79 | protected override void Update(Time time) |
---|
80 | { |
---|
81 | if (taistelija != null && taistelijanAse != null) |
---|
82 | { |
---|
83 | if (!walkBackwards) |
---|
84 | { |
---|
85 | if (taistelija.Velocity.X < -STOP_LIMIT_X) |
---|
86 | { |
---|
87 | taistelijanAse.Angle = Angle.FromDegrees(180.0); |
---|
88 | taistelija.Animation = chuckinKavelyFlipped; |
---|
89 | if (prevVelocityX > 0) |
---|
90 | taistelija.Animation.Start(); |
---|
91 | } |
---|
92 | if (taistelija.Velocity.X > STOP_LIMIT_X) |
---|
93 | { |
---|
94 | taistelijanAse.Angle = Angle.FromDegrees(0.0); |
---|
95 | taistelija.Animation = chuckinkavely; |
---|
96 | if (prevVelocityX < 0) |
---|
97 | taistelija.Animation.Start(); |
---|
98 | } |
---|
99 | if (taistelija.Velocity.X >= -STOP_LIMIT_X && taistelija.Velocity.X <= STOP_LIMIT_X) |
---|
100 | taistelija.Animation.Stop(); |
---|
101 | |
---|
102 | prevVelocityX = taistelija.Velocity.X; |
---|
103 | } |
---|
104 | } |
---|
105 | base.Update(time); |
---|
106 | } |
---|
107 | |
---|
108 | void FixCamera() |
---|
109 | { |
---|
110 | double widthReduction = 1920.0 / Window.Width; |
---|
111 | double heightReduction = 1080.0 / Window.Height; |
---|
112 | |
---|
113 | double multiplier = Math.Max(widthReduction, heightReduction); |
---|
114 | |
---|
115 | Camera.ZoomFactor = 1 / multiplier; |
---|
116 | } |
---|
117 | |
---|
118 | /// <summary> |
---|
119 | /// Pimennetään ruutua pikku hiljaa. |
---|
120 | /// Oletusnopeus 0.01. |
---|
121 | /// </summary> |
---|
122 | public void PimennaRuutua(double nopeus) |
---|
123 | { |
---|
124 | Timer ajastin = new Timer(); |
---|
125 | ajastin.Interval = 0.1; |
---|
126 | ajastin.Timeout += delegate |
---|
127 | { |
---|
128 | Level.AmbientLight -= nopeus; |
---|
129 | if (Level.AmbientLight <= 0.0) |
---|
130 | { |
---|
131 | ajastin.Stop(); |
---|
132 | ajastin.Reset(); |
---|
133 | } |
---|
134 | }; |
---|
135 | ajastin.Start(); |
---|
136 | } |
---|
137 | |
---|
138 | /// <summary> |
---|
139 | /// Pimennetään ruutua pikku hiljaa. |
---|
140 | /// Oletusnopeus 0.01. |
---|
141 | /// </summary> |
---|
142 | public void PimennaRuutua(double nopeus, Action onFinished) |
---|
143 | { |
---|
144 | Timer ajastin = new Timer(); |
---|
145 | ajastin.Interval = 0.1; |
---|
146 | ajastin.Timeout += delegate |
---|
147 | { |
---|
148 | Level.AmbientLight -= nopeus; |
---|
149 | if (Level.AmbientLight <= 0.0) |
---|
150 | { |
---|
151 | ajastin.Stop(); |
---|
152 | ajastin.Reset(); |
---|
153 | if (onFinished != null) |
---|
154 | onFinished(); |
---|
155 | } |
---|
156 | }; |
---|
157 | ajastin.Start(); |
---|
158 | } |
---|
159 | |
---|
160 | /// <summary> |
---|
161 | /// Kirkastetaan ruutua pikku hiljaa. |
---|
162 | /// </summary> |
---|
163 | public void KirkastaRuutua(double nopeus, double tavoite) |
---|
164 | { |
---|
165 | Timer ajastin = new Timer(); |
---|
166 | ajastin.Interval = 0.1; |
---|
167 | ajastin.Timeout += delegate |
---|
168 | { |
---|
169 | //if (Level.AmbientLight > 0.1) return; |
---|
170 | Level.AmbientLight += nopeus; |
---|
171 | if (Level.AmbientLight > tavoite) |
---|
172 | { |
---|
173 | ajastin.Stop(); |
---|
174 | ajastin.Reset(); |
---|
175 | } |
---|
176 | }; |
---|
177 | ajastin.Start(); |
---|
178 | } |
---|
179 | |
---|
180 | /// <summary> |
---|
181 | /// Kirkastetaan ruutua pikku hiljaa. |
---|
182 | /// </summary> |
---|
183 | public void KirkastaRuutua(double nopeus, double tavoite, Action onFinished) |
---|
184 | { |
---|
185 | Timer ajastin = new Timer(); |
---|
186 | ajastin.Interval = 0.1; |
---|
187 | ajastin.Timeout += delegate |
---|
188 | { |
---|
189 | //if (Level.AmbientLight > 0.1) return; |
---|
190 | Level.AmbientLight += nopeus; |
---|
191 | if (Level.AmbientLight > tavoite) |
---|
192 | { |
---|
193 | ajastin.Stop(); |
---|
194 | ajastin.Reset(); |
---|
195 | if (onFinished != null) |
---|
196 | onFinished(); |
---|
197 | } |
---|
198 | }; |
---|
199 | ajastin.Start(); |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | /// <summary> |
---|
204 | /// Piirretään valojuovia. |
---|
205 | /// </summary> |
---|
206 | /// <param name="position">Valojuovan tämänhetkinen sijainti.</param> |
---|
207 | /// <param name="color">Valojuovan väri.</param> |
---|
208 | /// <param name="lifetimeInSeconds">Kauanko valojuova pysyy kentällä.</param> |
---|
209 | void DrawTracers(Vector position, Color color, double lifetimeInSeconds, double brightnessFactor) |
---|
210 | { |
---|
211 | color.AlphaComponent = (byte)(32 * brightnessFactor); // 64 toimii |
---|
212 | GameObject tracer = new GameObject(2, 2); |
---|
213 | tracer.Shape = Shape.Circle; |
---|
214 | tracer.Color = color; |
---|
215 | tracer.Position = position; |
---|
216 | tracer.MaximumLifetime = TimeSpan.FromSeconds(lifetimeInSeconds); |
---|
217 | Add(tracer); |
---|
218 | } |
---|
219 | /// <summary> |
---|
220 | /// Piirretään valojuovia. |
---|
221 | /// </summary> |
---|
222 | /// <param name="tracingObject">Olio, josta valojuovat tulevat.</param> |
---|
223 | /// <param name="color">Valojuovan väri.</param> |
---|
224 | /// <param name="lifetimeInSeconds">Kauanko valojuova pysyy kentällä.</param> |
---|
225 | /// <param name="brightnessFactor">Valojuovan kirkkaus.</param> |
---|
226 | void DrawTracers(PhysicsObject tracingObject, Color color, double lifetimeInSeconds, double brightnessFactor) |
---|
227 | { |
---|
228 | color.AlphaComponent = (byte)(32 * brightnessFactor); // 64 toimii |
---|
229 | GameObject tracer = new GameObject(90, 2); |
---|
230 | tracer.Shape = Shape.Circle; |
---|
231 | tracer.Color = color; |
---|
232 | tracer.Position = tracingObject.Position; |
---|
233 | tracer.Angle = tracingObject.Angle; |
---|
234 | tracer.MaximumLifetime = TimeSpan.FromSeconds(lifetimeInSeconds); |
---|
235 | Add(tracer); |
---|
236 | } |
---|
237 | |
---|
238 | void AloitusAnimaatio() |
---|
239 | { |
---|
240 | Level.Background.Color = Color.Black; |
---|
241 | Level.AmbientLight = 0.0; |
---|
242 | GameObject tausta = new GameObject(ajAlku); |
---|
243 | Add(tausta); |
---|
244 | KirkastaRuutua(0.05, 1.0); |
---|
245 | H2Oopening.Play(); |
---|
246 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, delegate { |
---|
247 | stSequenceSkipped = true; |
---|
248 | H2Oopening.Stop(); |
---|
249 | AloitaPeli(); |
---|
250 | }, null); |
---|
251 | |
---|
252 | |
---|
253 | Timer.SingleShot(7.0, delegate { |
---|
254 | if (!stSequenceSkipped) |
---|
255 | { |
---|
256 | PimennaRuutua(0.1, delegate |
---|
257 | { |
---|
258 | if (!stSequenceSkipped) |
---|
259 | AloitaPeli(); |
---|
260 | }); |
---|
261 | } |
---|
262 | }); |
---|
263 | } |
---|
264 | |
---|
265 | void LataaContent() |
---|
266 | { |
---|
267 | chuckinkavely = LoadAnimation("pelaaja_anim"); |
---|
268 | chuckinKavelyFlipped = Animation.Mirror(chuckinkavely); |
---|
269 | jounibossArrive = LoadAnimation("jouniboss_anim"); |
---|
270 | asemiesLiikkuu = LoadAnimation("asemiesliikkuu"); |
---|
271 | tuliAnimaatio = LoadAnimation("tulianimaatio"); |
---|
272 | } |
---|
273 | |
---|
274 | #endregion |
---|
275 | |
---|
276 | |
---|
277 | void Liikuta(PhysicsObject pelaaja, double suunta) |
---|
278 | { |
---|
279 | if (!controlsActive) return; |
---|
280 | |
---|
281 | pelaaja.Velocity = new Vector(suunta, pelaaja.Velocity.Y); |
---|
282 | |
---|
283 | if (!pelaaja.Animation.IsPlaying) |
---|
284 | pelaaja.Animation.Resume(); |
---|
285 | } |
---|
286 | |
---|
287 | void LiikutaYlos(PhysicsObject pelaaja) |
---|
288 | { |
---|
289 | if (!controlsActive) return; |
---|
290 | |
---|
291 | pelaaja.Hit(new Vector(0, HYPPYVOIMA * pelaaja.Mass)); |
---|
292 | |
---|
293 | Sound pelaajaHyppyAani = hyppy.CreateSound(); |
---|
294 | pelaajaHyppyAani.Pitch = 0.1; |
---|
295 | Timer.SingleShot(0.1, delegate { pelaajaHyppyAani.Play(); }); |
---|
296 | |
---|
297 | } |
---|
298 | |
---|
299 | void LuoKentta() |
---|
300 | { |
---|
301 | SmoothTextures = false; |
---|
302 | // IsFullScreen = true; |
---|
303 | Gravity = new Vector(0, -2500); |
---|
304 | // Synkataan taustakuvan ja colortilemapin pikselit |
---|
305 | Level.Background.Image = LoadImage("kentta" + kenttaNro.ToString()); |
---|
306 | |
---|
307 | Level.Width = Screen.Width; |
---|
308 | double kerroin = (double)Level.Background.Image.Width / Level.Background.Image.Height; |
---|
309 | Level.Height = Level.Width / kerroin; |
---|
310 | Level.Background.FitToLevel(); |
---|
311 | |
---|
312 | Image pohjaLevynKuva = LoadImage("kentta" + kenttaNro.ToString() + "pohja"); |
---|
313 | |
---|
314 | ColorTileMap pohjaLevy = new ColorTileMap(pohjaLevynKuva); |
---|
315 | pohjaLevy.SetTileMethod(Color.Gold, LuoPohja); |
---|
316 | pohjaLevy.SetTileMethod(Color.Cyan, Luotaistelija); |
---|
317 | pohjaLevy.SetTileMethod(Color.DarkGray, LuoTormaavaVihollinen); |
---|
318 | pohjaLevy.SetTileMethod(Color.Gray, LuoAmpuvaVihollinen); |
---|
319 | pohjaLevy.SetTileMethod(Color.Red, LuoTriggerPalikka); |
---|
320 | pohjaLevy.Optimize(Color.Gold); |
---|
321 | pohjaLevy.Optimize(Color.Red); |
---|
322 | |
---|
323 | // oletuksena 1 pikseli = 1 unit |
---|
324 | const double BASE_SIZE = 1.0; |
---|
325 | double widthMultiplier = Level.Width / pohjaLevynKuva.Width; |
---|
326 | double heightMultiplier = Level.Height / pohjaLevynKuva.Height; |
---|
327 | pohjaLevy.Execute(BASE_SIZE * widthMultiplier, BASE_SIZE * heightMultiplier); |
---|
328 | |
---|
329 | PhysicsObject vasenreuna = Level.CreateLeftBorder(); |
---|
330 | vasenreuna.X -= 75; |
---|
331 | vasenreuna.Tag = "vasenreuna"; |
---|
332 | vasenreuna.CollisionIgnoreGroup = 1; // ettei Jouni törmää |
---|
333 | PhysicsObject oikeareuna = Level.CreateRightBorder(); |
---|
334 | oikeareuna.Tag = "oikeareuna"; |
---|
335 | |
---|
336 | if (taistelija != null) |
---|
337 | Varjo(taistelija); |
---|
338 | TeeKenttaKohtaisetAsiat(kenttaNro); |
---|
339 | } |
---|
340 | |
---|
341 | void Luotaistelija(Vector paikka, double leveys, double korkeus) |
---|
342 | { |
---|
343 | taistelija = new Elava(150, 150, 100.0); |
---|
344 | taistelija.Shape = Shape.Rectangle; |
---|
345 | taistelija.Animation = new Animation(chuckinkavely); |
---|
346 | taistelija.Animation.Start(); |
---|
347 | taistelija.Tag = "pelaaja"; |
---|
348 | taistelija.Position = paikka; |
---|
349 | taistelija.Kuoli += PelaajaKuoli; |
---|
350 | |
---|
351 | AddCollisionHandler(taistelija, "vasenreuna", SeuraavaKentta); |
---|
352 | //AddCollisionHandler<PhysicsObject, PhysicsObject>(taistelija, "vihollinen", delegate { |
---|
353 | // taistelija.Damagea(VIHOLLISEN_TORMAYSDMG); |
---|
354 | //}); |
---|
355 | |
---|
356 | taistelija.Mass = 10.0; |
---|
357 | Add(taistelija); |
---|
358 | Camera.Follow(taistelija); |
---|
359 | Camera.StayInLevel = true; |
---|
360 | |
---|
361 | taistelijanAse = new AssaultRifle(20, 10); |
---|
362 | taistelijanAse.FireRate = 20; |
---|
363 | taistelijanAse.InfiniteAmmo = true; |
---|
364 | taistelijanAse.Power.Value = 750; |
---|
365 | taistelijanAse.Power.DefaultValue = 750; |
---|
366 | taistelijanAse.AttackSound = ampuminen; |
---|
367 | taistelijanAse.IsVisible = false; |
---|
368 | taistelija.Add(taistelijanAse); |
---|
369 | |
---|
370 | LuoElamaPalkki(); |
---|
371 | } |
---|
372 | |
---|
373 | void LuoElamaPalkki() |
---|
374 | { |
---|
375 | ProgressBar elamat = new ProgressBar(532 / 1.5, 49 / 1.5); |
---|
376 | elamat.BindTo(taistelija.Elamat); |
---|
377 | elamat.Left = Screen.Left + 40; |
---|
378 | elamat.Top = Screen.Top - 40; |
---|
379 | elamat.Image = ePalkkiTyhja; |
---|
380 | elamat.BarImage = ePalkkiTaysi; |
---|
381 | Add(elamat); |
---|
382 | } |
---|
383 | |
---|
384 | void LuoTriggerPalikka(Vector paikka, double leveys, double korkeus) |
---|
385 | { |
---|
386 | PhysicsObject trigger = new PhysicsObject(leveys, korkeus); |
---|
387 | trigger.IsVisible = false; |
---|
388 | trigger.IgnoresCollisionResponse = true; |
---|
389 | trigger.Tag = "trigger"; |
---|
390 | trigger.Collided += delegate(IPhysicsObject t, IPhysicsObject kohde) |
---|
391 | { |
---|
392 | if (tActionTriggered) return; |
---|
393 | if (kohde.Tag.ToString() == "trigger") return; |
---|
394 | |
---|
395 | if (TriggerAction != null) |
---|
396 | TriggerAction(); |
---|
397 | |
---|
398 | tActionTriggered = true; |
---|
399 | }; |
---|
400 | trigger.Position = paikka; |
---|
401 | trigger.MakeStatic(); |
---|
402 | Add(trigger); |
---|
403 | } |
---|
404 | |
---|
405 | GameObject Varjo(GameObject shadowCaster) |
---|
406 | { |
---|
407 | GameObject varjo = new GameObject(70, 30); |
---|
408 | varjo.Image = taistelijanvarjo; |
---|
409 | Add(varjo, -1); |
---|
410 | |
---|
411 | Timer ajastin = new Timer(); |
---|
412 | ajastin.Interval = 1.0 / 60.0; |
---|
413 | ajastin.Timeout += delegate |
---|
414 | { |
---|
415 | varjo.X = shadowCaster.X; |
---|
416 | varjo.Y = EtsiVarjonY(shadowCaster); |
---|
417 | }; |
---|
418 | ajastin.Start(); |
---|
419 | |
---|
420 | return varjo; |
---|
421 | } |
---|
422 | |
---|
423 | /// <summary> |
---|
424 | /// Etsii suoraan pelaajan alla olevan lattiapalikan Y-koordinaatin. |
---|
425 | /// </summary> |
---|
426 | /// <returns></returns> |
---|
427 | double EtsiVarjonY(GameObject shadowCaster) |
---|
428 | { |
---|
429 | Vector rayDown = new Vector(0.0, -2000.0); |
---|
430 | List<GameObject> possibleObjects = GetObjects(x => x != shadowCaster && x is PhysicsObject); |
---|
431 | List<GameObject> objectsBelow = new List<GameObject>(); |
---|
432 | |
---|
433 | for (int i = 0; i < possibleObjects.Count; i++) |
---|
434 | { |
---|
435 | if (possibleObjects[i].IsBlocking(new Vector(shadowCaster.X, shadowCaster.Bottom), new Vector(shadowCaster.X, shadowCaster.Bottom) + rayDown)) |
---|
436 | { |
---|
437 | objectsBelow.Add(possibleObjects[i]); |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | if (objectsBelow.Count == 0) |
---|
442 | return double.MinValue; |
---|
443 | |
---|
444 | double minDistance = double.MaxValue; |
---|
445 | int minIndex = -1; |
---|
446 | |
---|
447 | for (int i = 0; i < objectsBelow.Count; i++) |
---|
448 | { |
---|
449 | double currentDistance = Math.Abs(shadowCaster.Bottom - objectsBelow[i].Top); |
---|
450 | if (currentDistance < minDistance) |
---|
451 | { |
---|
452 | minDistance = currentDistance; |
---|
453 | minIndex = i; |
---|
454 | } |
---|
455 | } |
---|
456 | |
---|
457 | return objectsBelow[minIndex].Top; |
---|
458 | } |
---|
459 | |
---|
460 | |
---|
461 | void SeuraavaKentta(PhysicsObject tormaaja, PhysicsObject tormatty) |
---|
462 | { |
---|
463 | if (!paaseekoSeuraavaanKenttaan) return; |
---|
464 | |
---|
465 | ClearAll(); |
---|
466 | taistelija = null; |
---|
467 | TriggerAction = null; |
---|
468 | tActionTriggered = false; |
---|
469 | controlsActive = true; |
---|
470 | |
---|
471 | kenttaNro++; |
---|
472 | |
---|
473 | if (kenttaNro > VIIMEINEN_KENTTA) |
---|
474 | { |
---|
475 | VoititPelin(); |
---|
476 | } |
---|
477 | |
---|
478 | else |
---|
479 | { |
---|
480 | LuoKentta(); |
---|
481 | AsetaOhjaimet(); |
---|
482 | } |
---|
483 | } |
---|
484 | |
---|
485 | void TeeKenttaKohtaisetAsiat(int kentta) |
---|
486 | { |
---|
487 | switch (kentta) |
---|
488 | { |
---|
489 | case 9: |
---|
490 | taustamusiikki_1.Stop(); |
---|
491 | MediaPlayer.Play("bossfightmusicAJ"); |
---|
492 | MediaPlayer.IsRepeating = true; |
---|
493 | TriggerAction += delegate { LuoJouniBoss(new Vector(Screen.Left - jouniBoss.Width / 2 - 20, Screen.Bottom + (jouniBoss.Height / 2) - 100), Screen.Left + jouniBoss.Width / 2); }; |
---|
494 | break; |
---|
495 | case 10: |
---|
496 | paaseekoSeuraavaanKenttaan = false; |
---|
497 | MediaPlayer.Stop(); |
---|
498 | TriggerAction += delegate { LuoChromaCase(ItemType.Knife); }; |
---|
499 | break; |
---|
500 | case 11: |
---|
501 | taustamusiikki_1.Play(); |
---|
502 | break; |
---|
503 | case 16: |
---|
504 | taustamusiikki_1.Stop(); |
---|
505 | controlsActive = false; |
---|
506 | Level.AmbientLight = 0.0; |
---|
507 | KirkastaRuutua(0.03, 1.0); |
---|
508 | Timer.SingleShot(4.0, delegate { SeuraavaKentta(null, null); }); |
---|
509 | break; |
---|
510 | case 17: |
---|
511 | controlsActive = false; |
---|
512 | Timer.SingleShot(4.0, delegate { PimennaRuutua(0.03, delegate { SeuraavaKentta(null, null); }); }); |
---|
513 | break; |
---|
514 | case 18: |
---|
515 | controlsActive = false; |
---|
516 | taistelija.Size *= 0.5; |
---|
517 | taustamusiikki_1.Stop(); |
---|
518 | MediaPlayer.Play("bossfightmusicAJ"); |
---|
519 | MediaPlayer.IsRepeating = true; |
---|
520 | LuoAnttiJussi(new Vector(0.0, Screen.Top + anttijussiboss.Height)); |
---|
521 | break; |
---|
522 | default: |
---|
523 | break; |
---|
524 | } |
---|
525 | } |
---|
526 | |
---|
527 | void LuoPohja(Vector paikka, double leveys, double korkeus) |
---|
528 | { |
---|
529 | PhysicsObject pala = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
530 | pala.Position = paikka; |
---|
531 | pala.IsVisible = false; |
---|
532 | Add(pala); |
---|
533 | } |
---|
534 | |
---|
535 | void LuoChromaCase(ItemType forceItem) |
---|
536 | { |
---|
537 | Mouse.IsCursorVisible = true; |
---|
538 | |
---|
539 | List<GameObject> pItems = new List<GameObject>(); |
---|
540 | GameObject knife = new GameObject(LoadImage("rareitem_knife")); |
---|
541 | knife.Tag = new object[2] {(object)50.0, (object)ItemType.Knife}; |
---|
542 | pItems.Add(knife); |
---|
543 | |
---|
544 | GameObject avain = new GameObject(LoadImage("rareitem_avain_small")); |
---|
545 | avain.Tag = new object[2] { (object)50.0, (object)ItemType.Key }; |
---|
546 | pItems.Add(avain); |
---|
547 | |
---|
548 | GameObject cCaseDialog = new GameObject(cCaseD); // koko debug |
---|
549 | Add(cCaseDialog); |
---|
550 | |
---|
551 | Mouse.ListenOn(cCaseDialog, MouseButton.Left, ButtonState.Pressed, delegate |
---|
552 | { |
---|
553 | cCaseDialog.Destroy(); |
---|
554 | |
---|
555 | GameObject cCaseFront = new GameObject(cCaseF); |
---|
556 | |
---|
557 | if (forceItem == ItemType.Knife) |
---|
558 | { |
---|
559 | ChromaCase cCase = new ChromaCase(pItems, cCaseFront, knife, 20); |
---|
560 | cCase.Add(new Vector(0.0, Level.Bottom + cCaseFront.Height / 2), 2); |
---|
561 | cCase.ItemReceived += delegate(GameObject o) { GotItemFromCase(o); }; |
---|
562 | cCase.ItemRelativePosition = new Vector((472 - 467.5), (455 - 204)); |
---|
563 | cCase.Start(); |
---|
564 | } |
---|
565 | else |
---|
566 | { |
---|
567 | ChromaCase cCase = new ChromaCase(pItems, cCaseFront, avain, 20); |
---|
568 | cCase.Add(new Vector(0.0, Level.Bottom + cCaseFront.Height / 2), 2); |
---|
569 | cCase.ItemReceived += delegate(GameObject o) { GotItemFromCase(o); }; |
---|
570 | cCase.ItemRelativePosition = new Vector((472 - 467.5), (455 - 204)); |
---|
571 | cCase.Start(); |
---|
572 | } |
---|
573 | }, null); |
---|
574 | } |
---|
575 | |
---|
576 | void GotItemFromCase(GameObject o) |
---|
577 | { |
---|
578 | ItemType gotType = (ItemType)(((object[])o.Tag)[1]); |
---|
579 | |
---|
580 | switch (gotType) |
---|
581 | { |
---|
582 | case ItemType.Knife: |
---|
583 | GameObject inspect = new GameObject(karambitInspect); |
---|
584 | inspect.Position = Camera.ScreenToWorld(Screen.Center); |
---|
585 | karambitfadeSound.Play(); |
---|
586 | Timer.SingleShot(karambitfadeSound.Duration.Seconds + 1, delegate |
---|
587 | { |
---|
588 | inspect.Destroy(); |
---|
589 | tActionTriggered = false; |
---|
590 | TriggerAction = null; |
---|
591 | TriggerAction = delegate { LuoChromaCase(ItemType.Key); }; |
---|
592 | }); |
---|
593 | Add(inspect); |
---|
594 | break; |
---|
595 | case ItemType.Key: |
---|
596 | GameObject inspectKey = new GameObject(keyInspect); |
---|
597 | inspectKey.Position = Camera.ScreenToWorld(Screen.Center); |
---|
598 | taisteletiesi.Play(); |
---|
599 | Timer.SingleShot(taisteletiesi.Duration.Seconds + 1, delegate |
---|
600 | { |
---|
601 | inspectKey.Destroy(); |
---|
602 | paaseekoSeuraavaanKenttaan = true; |
---|
603 | }); |
---|
604 | Add(inspectKey); |
---|
605 | break; |
---|
606 | default: |
---|
607 | break; |
---|
608 | } |
---|
609 | } |
---|
610 | |
---|
611 | /// <summary> |
---|
612 | /// Asetetaan pelaajalle ohjaimet. |
---|
613 | /// </summary> |
---|
614 | void AsetaOhjaimet() |
---|
615 | { |
---|
616 | Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, null, taistelija, -NOPEUS); |
---|
617 | Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, null, taistelija, NOPEUS); |
---|
618 | Keyboard.Listen(Key.W, ButtonState.Pressed, LiikutaYlos, null, taistelija); |
---|
619 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
620 | Keyboard.Listen(Key.Space, ButtonState.Down, Ammu, null); |
---|
621 | Keyboard.Listen(Key.LeftShift, ButtonState.Pressed, delegate { walkBackwards = true; }, null); |
---|
622 | Keyboard.Listen(Key.LeftShift, ButtonState.Released, delegate { walkBackwards = false; }, null); |
---|
623 | |
---|
624 | |
---|
625 | // haxnapit |
---|
626 | |
---|
627 | Keyboard.Listen(Key.N, ButtonState.Pressed, delegate { taistelija.IgnoresCollisionResponse = true; }, null); |
---|
628 | Keyboard.Listen(Key.N, ButtonState.Released, delegate { taistelija.IgnoresCollisionResponse = false; }, null); |
---|
629 | |
---|
630 | Keyboard.Listen(Key.K, ButtonState.Pressed, delegate { SeuraavaKentta(null, null); }, null); |
---|
631 | } |
---|
632 | |
---|
633 | void Ammu() |
---|
634 | { |
---|
635 | if (!controlsActive) return; |
---|
636 | |
---|
637 | if (taistelijanAse == null) |
---|
638 | return; |
---|
639 | |
---|
640 | PhysicsObject ammus = taistelijanAse.Shoot(); |
---|
641 | |
---|
642 | if (ammus == null) |
---|
643 | return; |
---|
644 | ammus.Size *= 0.2; |
---|
645 | |
---|
646 | ammus.Hit(new Vector(0.0, RandomGen.NextDouble(-WEAPON_INACCURACY, WEAPON_INACCURACY))); |
---|
647 | ammus.IsUpdated = true; |
---|
648 | ammus.NeedsUpdateCall = true; |
---|
649 | ammus.CanRotate = false; |
---|
650 | ammus.Updated += delegate(PhysicsObject a) |
---|
651 | { |
---|
652 | DrawTracers(a, Color.Yellow, 0.2, 2.0); |
---|
653 | }; |
---|
654 | |
---|
655 | AddCollisionHandler(ammus, "vihollinen", AmmusOsuuViholliseen); |
---|
656 | AddCollisionHandler(ammus, "jouni", AmmusOsuuViholliseen); |
---|
657 | AddCollisionHandler(ammus, "anttijussi", AmmusOsuuViholliseen); |
---|
658 | |
---|
659 | AddCollisionHandler<PhysicsObject, PhysicsObject>(ammus, delegate(PhysicsObject a, PhysicsObject k) { |
---|
660 | |
---|
661 | if (k.Tag.ToString() == "trigger") return; |
---|
662 | ammus.Destroy(); |
---|
663 | }); |
---|
664 | } |
---|
665 | |
---|
666 | void AmmusOsuuViholliseen(PhysicsObject ammus, PhysicsObject kohde) |
---|
667 | { |
---|
668 | Elava vihu = kohde as Elava; |
---|
669 | |
---|
670 | if (vihu == null) return; |
---|
671 | |
---|
672 | vihu.Damagea(ASEEN_DMG); |
---|
673 | } |
---|
674 | |
---|
675 | void PelaajaKuoli() |
---|
676 | { |
---|
677 | kenttaNro -= kenttaNro % 3; // 3 kentän välein checkpoint |
---|
678 | |
---|
679 | if (kenttaNro < 1) |
---|
680 | kenttaNro = 1; |
---|
681 | |
---|
682 | paaseekoSeuraavaanKenttaan = true; |
---|
683 | |
---|
684 | taistelija = null; |
---|
685 | TriggerAction = null; |
---|
686 | tActionTriggered = false; |
---|
687 | |
---|
688 | |
---|
689 | ClearAll(); |
---|
690 | LuoKentta(); |
---|
691 | AsetaOhjaimet(); |
---|
692 | } |
---|
693 | |
---|
694 | void VoititPelin() |
---|
695 | { |
---|
696 | MediaPlayer.Stop(); |
---|
697 | |
---|
698 | SeuraavaKentta(null, null); |
---|
699 | Level.AmbientLight = 0.0; |
---|
700 | taustamusiikki_1.Stop(); |
---|
701 | |
---|
702 | ClearControls(); |
---|
703 | |
---|
704 | KirkastaRuutua(0.03, 1.0, delegate { |
---|
705 | hirmuvallanalta.Play(); |
---|
706 | Timer.SingleShot(hirmuvallanalta.Duration.Seconds + 1, delegate |
---|
707 | { |
---|
708 | yliopistiolaiset.Play(); |
---|
709 | Timer.SingleShot(yliopistiolaiset.Duration.Seconds, delegate { |
---|
710 | PimennaRuutua(0.03, delegate { |
---|
711 | Exit(); |
---|
712 | }); |
---|
713 | }); |
---|
714 | }); |
---|
715 | }); |
---|
716 | } |
---|
717 | } |
---|