1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | |
---|
10 | class Taso2 : PhysicsObject |
---|
11 | { |
---|
12 | public int hitPoints = 2; |
---|
13 | public Taso2() |
---|
14 | : base(40, 10) |
---|
15 | { |
---|
16 | MakeStatic(); |
---|
17 | } |
---|
18 | |
---|
19 | |
---|
20 | } |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | public class Peli : PhysicsGame |
---|
27 | { |
---|
28 | int mailanNopeus = 600; |
---|
29 | int pallonNopeus = 300; |
---|
30 | int äläLuoPalloa = 0; |
---|
31 | int isoMaila = 0; |
---|
32 | int pieniMaila = 0; |
---|
33 | //Vector nopeusVasen = new Vector(-600, 0); |
---|
34 | |
---|
35 | PhysicsObject pallo; |
---|
36 | PhysicsObject maila; |
---|
37 | PhysicsObject tnt; |
---|
38 | PhysicsObject elämä; |
---|
39 | PhysicsObject Power1; |
---|
40 | PhysicsObject Power2; |
---|
41 | |
---|
42 | PhysicsObject alaReuna; |
---|
43 | int kenttäNro = 1; |
---|
44 | int kenttäMäärä = 5; |
---|
45 | |
---|
46 | int palloolemassa; |
---|
47 | const int RUUDUN_KOKO = 5; |
---|
48 | |
---|
49 | Image palloKuva = LoadImage("Pallo"); |
---|
50 | Image tntKuva = LoadImage("TNT"); |
---|
51 | Image tasoKuva = LoadImage("Palikka"); |
---|
52 | Image taso2Kuva = LoadImage("Vahvistettu palikka"); |
---|
53 | Image taso2Kuva2 = LoadImage("Vahvistettu palikka2"); |
---|
54 | Image tasoTuhoutumatonKuva = LoadImage("Tuhoutumaton"); |
---|
55 | Image tasoTuhoutumatonKuvaPysty = LoadImage("TuhoutumatonPysty"); |
---|
56 | Image taustaKuva = LoadImage("Taustakuva1"); |
---|
57 | Image taustaKuva2 = LoadImage("Taustakuva2"); |
---|
58 | Image taustaKuva3 = LoadImage("Taustakuva3"); |
---|
59 | Image mailanKuva = LoadImage("Maila"); |
---|
60 | Image elämänKuva = LoadImage("elämä"); |
---|
61 | Image Power2Kuva = LoadImage("Power2"); |
---|
62 | Image Power1Kuva = LoadImage("Power1"); |
---|
63 | int pisteet; |
---|
64 | int elämät = 3; |
---|
65 | int randomKentät = 0; |
---|
66 | int ySuuntaKorjattu = 0; |
---|
67 | IntMeter pisteetL; |
---|
68 | IntMeter elämätL; |
---|
69 | |
---|
70 | Label päälläPois; |
---|
71 | |
---|
72 | List<Label> valikonKohdat; |
---|
73 | List<PhysicsObject> tasot = new List<PhysicsObject>(); |
---|
74 | List<PhysicsObject> taso2t = new List<PhysicsObject>(); |
---|
75 | List<PhysicsObject> tntt = new List<PhysicsObject>(); |
---|
76 | List<PhysicsObject> tasoTuhoutumatont = new List<PhysicsObject>(); |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | public override void Begin() |
---|
81 | { |
---|
82 | Valikko(); |
---|
83 | } |
---|
84 | |
---|
85 | void Valikko() |
---|
86 | { |
---|
87 | |
---|
88 | äläLuoPalloa = 1; |
---|
89 | ClearAll(); |
---|
90 | Level.Background.Image = taustaKuva3; |
---|
91 | Level.Background.Size = new Vector(Screen.Width, Screen.Height); |
---|
92 | Camera.ZoomToLevel(1); |
---|
93 | |
---|
94 | valikonKohdat = new List<Label>(); |
---|
95 | |
---|
96 | Label kohta1 = new Label("Aloita uusi peli"); |
---|
97 | kohta1.Position = new Vector(-80, 40); |
---|
98 | valikonKohdat.Add(kohta1); |
---|
99 | |
---|
100 | Label kohta2 = new Label("Asetukset"); |
---|
101 | kohta2.Position = new Vector(-80, -40); |
---|
102 | valikonKohdat.Add(kohta2); |
---|
103 | |
---|
104 | Label kohta3 = new Label("Lopeta"); |
---|
105 | kohta3.Position = new Vector(80, -40); |
---|
106 | valikonKohdat.Add(kohta3); |
---|
107 | |
---|
108 | Label kohta4 = new Label("Ohjeet"); |
---|
109 | kohta4.Position = new Vector(80, 40); |
---|
110 | valikonKohdat.Add(kohta4); |
---|
111 | |
---|
112 | foreach (Label valikonKohta in valikonKohdat) |
---|
113 | { |
---|
114 | Add(valikonKohta); |
---|
115 | } |
---|
116 | |
---|
117 | Mouse.ListenOn(kohta1, MouseButton.Left, ButtonState.Pressed, AloitaPeli, null); |
---|
118 | Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, Asetukset, null); |
---|
119 | Mouse.ListenOn(kohta3, MouseButton.Left, ButtonState.Pressed, Lopeta, null); |
---|
120 | Mouse.ListenOn(kohta4, MouseButton.Left, ButtonState.Pressed, Ohjeet, null); |
---|
121 | |
---|
122 | Mouse.IsCursorVisible = true; |
---|
123 | Mouse.ListenMovement(1.0, ValikossaLiikkuminen, null); |
---|
124 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Lopeta, ""); |
---|
125 | } |
---|
126 | |
---|
127 | void ValikossaLiikkuminen(AnalogState hiirenTila) |
---|
128 | { |
---|
129 | foreach (Label kohta in valikonKohdat) |
---|
130 | { |
---|
131 | if (Mouse.IsCursorOn(kohta)) |
---|
132 | { |
---|
133 | kohta.TextColor = Color.Red; |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | kohta.TextColor = Color.Black; |
---|
138 | } |
---|
139 | |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | void ValikossaLiikkuminen2(AnalogState hiirenTila) |
---|
144 | { |
---|
145 | foreach (Label kohta in valikonKohdat) |
---|
146 | { |
---|
147 | if (Mouse.IsCursorOn(kohta)) |
---|
148 | { |
---|
149 | kohta.TextColor = Color.Red; |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | kohta.TextColor = Color.White; |
---|
154 | } |
---|
155 | |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | void AloitaPeli() |
---|
161 | { |
---|
162 | ClearAll(); |
---|
163 | äläLuoPalloa = 0; |
---|
164 | nollaaPisteet(); |
---|
165 | LuoKenttä(1); |
---|
166 | AsetaOhjaimet(); |
---|
167 | LisääLaskurit(3, 0); |
---|
168 | AloitaPeliUudestaan(); |
---|
169 | } |
---|
170 | |
---|
171 | void nollaaPisteet() |
---|
172 | { |
---|
173 | kenttäNro = 1; |
---|
174 | pisteet = 0; |
---|
175 | elämät = 3; |
---|
176 | } |
---|
177 | |
---|
178 | void Lopeta() |
---|
179 | { |
---|
180 | Exit(); |
---|
181 | } |
---|
182 | |
---|
183 | void Ohjeet() |
---|
184 | { |
---|
185 | |
---|
186 | } |
---|
187 | |
---|
188 | void Asetukset() |
---|
189 | { |
---|
190 | ClearAll(); |
---|
191 | |
---|
192 | Level.Background.Image = taustaKuva2; |
---|
193 | Level.Background.Size = new Vector(Screen.Width, Screen.Height); |
---|
194 | Camera.ZoomToLevel(1); |
---|
195 | |
---|
196 | valikonKohdat = new List<Label>(); |
---|
197 | |
---|
198 | Label kohta1 = new Label("Pallon nopeus"); |
---|
199 | kohta1.Position = new Vector(-80, 40); |
---|
200 | valikonKohdat.Add(kohta1); |
---|
201 | kohta1.TextColor = Color.White; |
---|
202 | |
---|
203 | Label kohta2 = new Label("Mailan nopeus"); |
---|
204 | kohta2.Position = new Vector(-80, -40); |
---|
205 | valikonKohdat.Add(kohta2); |
---|
206 | kohta2.TextColor = Color.White; |
---|
207 | |
---|
208 | Label kohta3 = new Label("Takaisin"); |
---|
209 | kohta3.Position = new Vector(80, -40); |
---|
210 | valikonKohdat.Add(kohta3); |
---|
211 | kohta3.TextColor = Color.White; |
---|
212 | |
---|
213 | Label kohta4 = new Label("Satunaiset kentät"); |
---|
214 | kohta4.TextColor = Color.White; |
---|
215 | |
---|
216 | if (randomKentät == 1) |
---|
217 | { |
---|
218 | päälläPois = new Label("Päällä"); |
---|
219 | } |
---|
220 | else { päälläPois = new Label("Pois päältä"); } |
---|
221 | kohta4.Position = new Vector(100, 40); |
---|
222 | päälläPois.Position = new Vector(70, 15); |
---|
223 | päälläPois.TextColor = Color.White; |
---|
224 | valikonKohdat.Add(päälläPois); |
---|
225 | Add(kohta4); |
---|
226 | |
---|
227 | foreach (Label valikonKohta in valikonKohdat) |
---|
228 | { |
---|
229 | Add(valikonKohta); |
---|
230 | } |
---|
231 | |
---|
232 | Mouse.ListenOn(kohta1, MouseButton.Left, ButtonState.Pressed, AsetaPallonNopeus, null); |
---|
233 | Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, AsetaMailanNopeus, null); |
---|
234 | Mouse.ListenOn(kohta3, MouseButton.Left, ButtonState.Pressed, Valikko, null); |
---|
235 | Mouse.ListenOn(päälläPois, MouseButton.Left, ButtonState.Pressed, satunaisetKentät, null); |
---|
236 | |
---|
237 | Mouse.IsCursorVisible = true; |
---|
238 | Mouse.ListenMovement(1.0, ValikossaLiikkuminen2, null); |
---|
239 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Lopeta, ""); |
---|
240 | } |
---|
241 | |
---|
242 | void satunaisetKentät() |
---|
243 | { |
---|
244 | if (randomKentät == 1) |
---|
245 | { |
---|
246 | randomKentät = 0; |
---|
247 | } |
---|
248 | else |
---|
249 | { |
---|
250 | randomKentät = 1; |
---|
251 | } |
---|
252 | Asetukset(); |
---|
253 | } |
---|
254 | |
---|
255 | void AsetaPallonNopeus() |
---|
256 | { |
---|
257 | InputWindow kysymysIkkuna = new InputWindow("Pallon nopeus", "Oletus on 300"); |
---|
258 | kysymysIkkuna.TextEntered += KäsitteleAsetukset; |
---|
259 | Add(kysymysIkkuna); |
---|
260 | |
---|
261 | } |
---|
262 | |
---|
263 | void AsetaMailanNopeus() |
---|
264 | { |
---|
265 | InputWindow kysymysIkkuna = new InputWindow("Mailan nopeus", "Oletus on 600"); |
---|
266 | kysymysIkkuna.TextEntered += KäsitteleAsetukset2; |
---|
267 | Add(kysymysIkkuna); |
---|
268 | } |
---|
269 | |
---|
270 | void KäsitteleAsetukset(InputWindow ikkuna) |
---|
271 | { |
---|
272 | try |
---|
273 | { |
---|
274 | int vastaus = int.Parse(ikkuna.InputBox.Text); |
---|
275 | pallonNopeus = vastaus; |
---|
276 | } |
---|
277 | catch (FormatException) |
---|
278 | { |
---|
279 | ClearAll(); |
---|
280 | Label tekstikentta = new Label("Anna luku!"); |
---|
281 | Add(tekstikentta); |
---|
282 | Timer.SingleShot(2, ClearAll); |
---|
283 | Timer.SingleShot(2.01, Asetukset); |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | void KäsitteleAsetukset2(InputWindow ikkuna) |
---|
288 | { |
---|
289 | try |
---|
290 | { |
---|
291 | int vastaus = int.Parse(ikkuna.InputBox.Text); |
---|
292 | mailanNopeus = vastaus; |
---|
293 | } |
---|
294 | catch (FormatException) |
---|
295 | { |
---|
296 | ClearAll(); |
---|
297 | Label tekstikentta = new Label("Anna luku!"); |
---|
298 | Add(tekstikentta); |
---|
299 | Timer.SingleShot(2, ClearAll); |
---|
300 | Timer.SingleShot(2.01, Asetukset); |
---|
301 | } |
---|
302 | } |
---|
303 | |
---|
304 | PhysicsObject LuoPallo() //-170 |
---|
305 | { |
---|
306 | PhysicsObject pallo1 = new PhysicsObject(18.0, 18.0); |
---|
307 | pallo1.Image = palloKuva; |
---|
308 | pallo1.Shape = Shape.Circle; |
---|
309 | pallo1.Color = Color.LightGreen; |
---|
310 | pallo1.Tag = "pallo"; |
---|
311 | pallo1.Restitution = 1.0; |
---|
312 | pallo1.X = 0; |
---|
313 | pallo1.Y = -168; |
---|
314 | pallo1.CanRotate = false; |
---|
315 | palloolemassa = 1; |
---|
316 | return pallo1; |
---|
317 | } |
---|
318 | |
---|
319 | void LuoKenttä(int a) |
---|
320 | { |
---|
321 | |
---|
322 | LuoPalikat(a); |
---|
323 | Level.Background.Image = taustaKuva; |
---|
324 | Level.Background.Size = new Vector(Screen.Width, Screen.Height); |
---|
325 | |
---|
326 | Camera.ZoomToLevel(1); |
---|
327 | } |
---|
328 | |
---|
329 | void AloitaPeliUudestaan() |
---|
330 | { |
---|
331 | maila.X = 0; |
---|
332 | if (palloolemassa == 1) |
---|
333 | { |
---|
334 | pallo.Destroy(); |
---|
335 | } |
---|
336 | if (äläLuoPalloa == 0) |
---|
337 | { |
---|
338 | pallo = LuoPallo(); |
---|
339 | AddCollisionHandler(pallo, KäsittelePallonTörmäys); |
---|
340 | Add(pallo); |
---|
341 | } |
---|
342 | } |
---|
343 | |
---|
344 | void AsetaOhjaimet() |
---|
345 | { |
---|
346 | Vector nopeusVasen = new Vector(-mailanNopeus, 0); |
---|
347 | Vector nopeusOikea = new Vector(mailanNopeus, 0); |
---|
348 | Keyboard.Listen(Key.Right, ButtonState.Down, AsetaNopeus, "Liikuta mailaa oikealle", maila, nopeusOikea); |
---|
349 | Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus, null, maila, Vector.Zero); |
---|
350 | Keyboard.Listen(Key.Left, ButtonState.Down, AsetaNopeus, "Liikuta mailaa vasemmalle", maila, nopeusVasen); |
---|
351 | Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, maila, Vector.Zero); |
---|
352 | |
---|
353 | Keyboard.Listen(Key.T, ButtonState.Pressed, AloitaPeliUudestaan, null); |
---|
354 | Keyboard.Listen(Key.R, ButtonState.Pressed, DebugRäjäytys, null); |
---|
355 | |
---|
356 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
357 | Keyboard.Listen(Key.F2, ButtonState.Pressed, SeuraavaTaso, null); |
---|
358 | Keyboard.Listen(Key.F3, ButtonState.Pressed, AnnaElämä, null); |
---|
359 | |
---|
360 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, "Palaa valikkoon"); |
---|
361 | |
---|
362 | |
---|
363 | } |
---|
364 | |
---|
365 | void AnnaElämä() |
---|
366 | { |
---|
367 | elämät++; |
---|
368 | pisteet += 200; |
---|
369 | pisteetL.Value = pisteet; |
---|
370 | elämätL.Value = elämät; |
---|
371 | } |
---|
372 | |
---|
373 | void DebugRäjäytys() { Räjähdys(tnt.Position); } |
---|
374 | |
---|
375 | void LisääLaskurit(int elämät, int pisteet) |
---|
376 | { |
---|
377 | pisteetL = LuoPisteLaskuri(Screen.Left + 180.0, Screen.Top - 80.0, pisteet); |
---|
378 | elämätL = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 80.0, elämät); |
---|
379 | Label tekstikentta = new Label("Palloja jäljellä: "); |
---|
380 | tekstikentta.X = Screen.Right - 180; |
---|
381 | tekstikentta.Y = Screen.Top - 80; |
---|
382 | tekstikentta.TextColor = Color.White; |
---|
383 | Label tekstikentta2 = new Label("Pisteet: "); |
---|
384 | tekstikentta2.X = Screen.Left + 100.0; |
---|
385 | tekstikentta2.Y = Screen.Top - 80; |
---|
386 | tekstikentta2.TextColor = Color.White; |
---|
387 | |
---|
388 | Add(tekstikentta2); |
---|
389 | Add(tekstikentta); |
---|
390 | } |
---|
391 | |
---|
392 | IntMeter LuoPisteLaskuri(double x, double y, int määrä) |
---|
393 | { |
---|
394 | IntMeter laskuri = new IntMeter(määrä); |
---|
395 | Label näyttö = new Label(); |
---|
396 | näyttö.BindTo(laskuri); |
---|
397 | näyttö.X = x; |
---|
398 | näyttö.Y = y; |
---|
399 | näyttö.TextColor = Color.White; |
---|
400 | Add(näyttö); |
---|
401 | return laskuri; |
---|
402 | } |
---|
403 | |
---|
404 | void KäsittelePallonTörmäys(PhysicsObject pallo, PhysicsObject kohde) |
---|
405 | { |
---|
406 | if (kohde == alaReuna) |
---|
407 | { |
---|
408 | pallo.Destroy(); |
---|
409 | palloolemassa = 0; |
---|
410 | elämät -= 1; |
---|
411 | if (elämät == 0) |
---|
412 | { |
---|
413 | HävisitPelin(); |
---|
414 | } |
---|
415 | else Timer.SingleShot(1, AloitaPeliUudestaan); |
---|
416 | } |
---|
417 | if (kohde.Tag.ToString() == "taso") |
---|
418 | { |
---|
419 | pisteet += 100; |
---|
420 | AnnaPowerUp(kohde); |
---|
421 | Timer.SingleShot(0.01, kohde.Destroy); |
---|
422 | tasot.Remove(kohde); |
---|
423 | TarkistaVoitto(); |
---|
424 | } |
---|
425 | if (kohde.Tag.ToString() == "taso2") |
---|
426 | { |
---|
427 | Taso2 taso2 = (Taso2)kohde; |
---|
428 | taso2.hitPoints--; |
---|
429 | if (taso2.hitPoints == 1) |
---|
430 | { taso2.Image = taso2Kuva2; } |
---|
431 | else if (taso2.hitPoints == 0) |
---|
432 | { |
---|
433 | AnnaPowerUp(kohde); |
---|
434 | Timer.SingleShot(0.01, kohde.Destroy); |
---|
435 | pisteet += 300; |
---|
436 | } |
---|
437 | taso2t.Remove(kohde); |
---|
438 | TarkistaVoitto(); |
---|
439 | |
---|
440 | } |
---|
441 | if (kohde.Tag.ToString() == "TNT") |
---|
442 | { |
---|
443 | pisteet += 100; |
---|
444 | Räjähdys(kohde.Position); |
---|
445 | Timer.SingleShot(0.01, kohde.Destroy); |
---|
446 | TarkistaVoitto(); |
---|
447 | |
---|
448 | } |
---|
449 | if (kohde != maila && pallo.Velocity.Y == 0 && ySuuntaKorjattu == 0) |
---|
450 | { |
---|
451 | Timer.SingleShot(0.1, korjaaYSuunta); |
---|
452 | ySuuntaKorjattu = 1; |
---|
453 | } |
---|
454 | |
---|
455 | pisteetL.Value = pisteet; |
---|
456 | elämätL.Value = elämät; |
---|
457 | |
---|
458 | } |
---|
459 | |
---|
460 | void korjaaYSuunta() |
---|
461 | { |
---|
462 | pallo.Velocity = new Vector(pallo.Velocity.X, 20); |
---|
463 | ySuuntaKorjattu = 0; |
---|
464 | } |
---|
465 | |
---|
466 | |
---|
467 | void AnnaPowerUp(PhysicsObject kohde) |
---|
468 | { |
---|
469 | int Power = RandomGen.NextInt(0, 100); |
---|
470 | //int mailaPower1 = RandomGen.NextInt(0, 20); |
---|
471 | //int mailaPower2 = RandomGen.NextInt(0, 20); |
---|
472 | if (Power < 5) |
---|
473 | { |
---|
474 | PudotaElämä(kohde); |
---|
475 | } |
---|
476 | else if ((Power > 4)&&(Power < 10)) |
---|
477 | { |
---|
478 | PudotaPower1(kohde); |
---|
479 | } |
---|
480 | else if ((Power > 9) && (Power < 15)) |
---|
481 | { |
---|
482 | PudotaPower2(kohde); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | void PudotaElämä(PhysicsObject kohde) |
---|
487 | { |
---|
488 | elämä = new PhysicsObject(10, 10); |
---|
489 | elämä.IgnoresCollisionResponse = true; |
---|
490 | elämä.Tag = "elämä"; |
---|
491 | elämä.Position = kohde.Position; |
---|
492 | elämä.Image = elämänKuva; |
---|
493 | Vector impulssi = new Vector(0, -100); |
---|
494 | Add(elämä); |
---|
495 | elämä.Hit(impulssi); |
---|
496 | } |
---|
497 | |
---|
498 | void PudotaPower1(PhysicsObject kohde) |
---|
499 | { |
---|
500 | Power1 = new PhysicsObject(10, 10); |
---|
501 | Power1.IgnoresCollisionResponse = true; |
---|
502 | Power1.Tag = "Power1"; |
---|
503 | Power1.Position = kohde.Position; |
---|
504 | Power1.Image = Power1Kuva; |
---|
505 | Vector impulssi = new Vector(0, -100); |
---|
506 | Add(Power1); |
---|
507 | Power1.Hit(impulssi); |
---|
508 | } |
---|
509 | |
---|
510 | |
---|
511 | void PudotaPower2(PhysicsObject kohde) |
---|
512 | { |
---|
513 | Power2 = new PhysicsObject(10, 10); |
---|
514 | Power2.IgnoresCollisionResponse = true; |
---|
515 | Power2.Tag = "Power2"; |
---|
516 | Power2.Position = kohde.Position; |
---|
517 | Power2.Image = Power2Kuva; |
---|
518 | Vector impulssi = new Vector(0, -100); |
---|
519 | Add(Power2); |
---|
520 | Power2.Hit(impulssi); |
---|
521 | } |
---|
522 | |
---|
523 | void TarkistaVoitto() |
---|
524 | { |
---|
525 | if ((tasot.Count == 0) && (taso2t.Count == 0) && (tntt.Count == 0)) |
---|
526 | { |
---|
527 | SeuraavaTaso(); |
---|
528 | } |
---|
529 | |
---|
530 | } |
---|
531 | |
---|
532 | void SeuraavaTaso() |
---|
533 | { |
---|
534 | tasot.Clear(); |
---|
535 | tntt.Clear(); |
---|
536 | taso2t.Clear(); |
---|
537 | kenttäNro += 1; |
---|
538 | if (kenttäNro > kenttäMäärä) |
---|
539 | { |
---|
540 | ClearAll(); |
---|
541 | Label tekstikentta = new Label("Voitit, onneksi olkoon! Sait " + pisteet + " pistettä!"); |
---|
542 | Add(tekstikentta); |
---|
543 | Timer.SingleShot(2, Exit); |
---|
544 | } |
---|
545 | else |
---|
546 | { |
---|
547 | ClearAll(); |
---|
548 | Label tekstikentta = new Label("Pääsit seuraavaan tasoon"); |
---|
549 | Add(tekstikentta); |
---|
550 | Timer.SingleShot(1.5, SeuraavaTaso2); |
---|
551 | } |
---|
552 | |
---|
553 | } |
---|
554 | |
---|
555 | void SeuraavaTaso2() |
---|
556 | { |
---|
557 | ClearAll(); |
---|
558 | LuoKenttä(kenttäNro); |
---|
559 | AsetaOhjaimet(); |
---|
560 | LisääLaskurit(elämät, pisteet); |
---|
561 | AloitaPeliUudestaan(); |
---|
562 | } |
---|
563 | |
---|
564 | void Räjähdys(Vector kohde) |
---|
565 | { |
---|
566 | |
---|
567 | Explosion rajahdys = new Explosion(10); |
---|
568 | rajahdys.Position = kohde; |
---|
569 | rajahdys.Force = 0; |
---|
570 | Add(rajahdys); |
---|
571 | |
---|
572 | //foreach (PhysicsObject taso in tasot) |
---|
573 | //for(int i = 0; i<tasot.Count; i++) |
---|
574 | int i = 0; |
---|
575 | while (i < tasot.Count) |
---|
576 | { |
---|
577 | if (((tasot[i].X - kohde.X) < 100) && ((tasot[i].X - kohde.X) > -100) |
---|
578 | && ((tasot[i].Y - kohde.Y) < 80) && ((tasot[i].Y - kohde.Y) > -80)) |
---|
579 | { |
---|
580 | tasot[i].Destroy(); |
---|
581 | tasot.RemoveAt(i); |
---|
582 | pisteet += 100; |
---|
583 | pisteetL.Value = pisteet; |
---|
584 | } |
---|
585 | else |
---|
586 | { |
---|
587 | i++; |
---|
588 | } |
---|
589 | } |
---|
590 | int w = 0; |
---|
591 | while (w < taso2t.Count) |
---|
592 | { |
---|
593 | if (((taso2t[w].X - kohde.X) < 100) && ((taso2t[w].X - kohde.X) > -100) |
---|
594 | && ((taso2t[w].Y - kohde.Y) < 80) && ((taso2t[w].Y - kohde.Y) > -80)) |
---|
595 | { |
---|
596 | taso2t[w].Destroy(); |
---|
597 | taso2t.RemoveAt(w); |
---|
598 | pisteet += 300; |
---|
599 | pisteetL.Value = pisteet; |
---|
600 | } |
---|
601 | else |
---|
602 | { |
---|
603 | w++; |
---|
604 | } |
---|
605 | } |
---|
606 | int o = 0; |
---|
607 | while (o < tntt.Count) |
---|
608 | { |
---|
609 | if (((tntt[o].X - kohde.X) < 100) && ((tntt[o].X - kohde.X) > -100) |
---|
610 | && ((tntt[o].Y - kohde.Y) < 80) && ((tntt[o].Y - kohde.Y) > -80)) |
---|
611 | { |
---|
612 | Vector räjähdysPaikka = tntt[o].Position; |
---|
613 | tntt[o].Destroy(); |
---|
614 | tntt.RemoveAt(o); |
---|
615 | pisteet += 100; |
---|
616 | pisteetL.Value = pisteet; |
---|
617 | Räjähdys(räjähdysPaikka); |
---|
618 | |
---|
619 | } |
---|
620 | else |
---|
621 | { |
---|
622 | o++; |
---|
623 | } |
---|
624 | } |
---|
625 | } |
---|
626 | |
---|
627 | void LuoPalikat(int x) |
---|
628 | { |
---|
629 | |
---|
630 | if (randomKentät == 0) |
---|
631 | { |
---|
632 | TileMap kentta = TileMap.FromFile("kentta" + x + ".txt"); |
---|
633 | kentta['#'] = lisaaTaso; |
---|
634 | kentta['!'] = lisaaTaso2; |
---|
635 | kentta['p'] = lisaaPystyTaso; |
---|
636 | kentta['P'] = lisaaPystyTasoTuhoutumaton; |
---|
637 | kentta['*'] = lisaaTNT; |
---|
638 | kentta['T'] = lisaaTasoTuhoutumaton; |
---|
639 | kentta['m'] = LuoMaila; |
---|
640 | kentta['-'] = LuoReunat; |
---|
641 | kentta['_'] = LuoAlaReuna; |
---|
642 | kentta['y'] = LuoYläReuna; |
---|
643 | kentta.Insert(20, 20); |
---|
644 | } |
---|
645 | else |
---|
646 | { |
---|
647 | TileMap kentta = TileMap.FromFile("kenttarandom.txt"); |
---|
648 | kentta['#'] = lisaaRandomTaso; |
---|
649 | kentta['m'] = LuoMaila; |
---|
650 | kentta['-'] = LuoReunat; |
---|
651 | kentta['_'] = LuoAlaReuna; |
---|
652 | kentta['y'] = LuoYläReuna; |
---|
653 | kentta.Insert(40, 40); |
---|
654 | } |
---|
655 | } |
---|
656 | |
---|
657 | PhysicsObject lisaaTaso() |
---|
658 | { |
---|
659 | PhysicsObject taso = PhysicsObject.CreateStaticObject(40, 10); |
---|
660 | taso.Tag = "taso"; |
---|
661 | taso.Image = tasoKuva; |
---|
662 | taso.Restitution = 1.0; |
---|
663 | tasot.Add(taso); |
---|
664 | return taso; |
---|
665 | } |
---|
666 | |
---|
667 | PhysicsObject lisaaTasoTuhoutumaton() |
---|
668 | { |
---|
669 | PhysicsObject tasoTuhoutumaton = PhysicsObject.CreateStaticObject(40, 10); |
---|
670 | //tasoTuhoutumaton.Tag = "taso"; |
---|
671 | tasoTuhoutumaton.Image = tasoTuhoutumatonKuva; |
---|
672 | tasoTuhoutumaton.Restitution = 1.0; |
---|
673 | return tasoTuhoutumaton; |
---|
674 | } |
---|
675 | |
---|
676 | PhysicsObject lisaaPystyTaso() |
---|
677 | { |
---|
678 | PhysicsObject taso = PhysicsObject.CreateStaticObject(10, 40); |
---|
679 | taso.Tag = "taso"; |
---|
680 | taso.Image = tasoKuva; |
---|
681 | taso.Restitution = 1.0; |
---|
682 | tasot.Add(taso); |
---|
683 | return taso; |
---|
684 | } |
---|
685 | |
---|
686 | PhysicsObject lisaaPystyTasoTuhoutumaton() |
---|
687 | { |
---|
688 | PhysicsObject tasoTuhoutumaton = PhysicsObject.CreateStaticObject(10, 40); |
---|
689 | //tasoTuhoutumaton.Tag = "taso"; |
---|
690 | tasoTuhoutumaton.Image = tasoTuhoutumatonKuvaPysty; |
---|
691 | tasoTuhoutumaton.Restitution = 1.0; |
---|
692 | return tasoTuhoutumaton; |
---|
693 | } |
---|
694 | |
---|
695 | PhysicsObject lisaaTaso2() |
---|
696 | { |
---|
697 | Taso2 taso2 = new Taso2(); |
---|
698 | taso2.Tag = "taso2"; |
---|
699 | taso2.Image = taso2Kuva; |
---|
700 | taso2.Restitution = 1.0; |
---|
701 | taso2t.Add(taso2); |
---|
702 | return taso2; |
---|
703 | } |
---|
704 | |
---|
705 | PhysicsObject lisaaTNT() |
---|
706 | { |
---|
707 | tnt = PhysicsObject.CreateStaticObject(40, 10); |
---|
708 | tnt.Image = tntKuva; |
---|
709 | tnt.Restitution = 1; |
---|
710 | tntt.Add(tnt); |
---|
711 | tnt.Tag = "TNT"; |
---|
712 | |
---|
713 | return tnt; |
---|
714 | } |
---|
715 | |
---|
716 | PhysicsObject LuoMaila() |
---|
717 | { |
---|
718 | maila = PhysicsObject.CreateStaticObject(60.0, 10); |
---|
719 | maila.Shape = Shape.Rectangle; |
---|
720 | maila.Image = mailanKuva; |
---|
721 | maila.Restitution = 0.5; |
---|
722 | maila.Color = Color.Green; |
---|
723 | AddCollisionHandler(maila, KäsitteleMailanTörmäys); |
---|
724 | return maila; |
---|
725 | } |
---|
726 | |
---|
727 | PhysicsObject lisaaRandomTaso() |
---|
728 | { |
---|
729 | int tasonTyyppi = RandomGen.NextInt(1, 4); |
---|
730 | PhysicsObject taso; |
---|
731 | |
---|
732 | if (tasonTyyppi == 1) |
---|
733 | { |
---|
734 | taso = lisaaTaso(); |
---|
735 | } |
---|
736 | else if (tasonTyyppi == 2) |
---|
737 | { |
---|
738 | taso = lisaaTaso2(); |
---|
739 | } |
---|
740 | else if (tasonTyyppi == 3) |
---|
741 | { |
---|
742 | taso = lisaaTNT(); |
---|
743 | } |
---|
744 | else if (tasonTyyppi == 4) |
---|
745 | { |
---|
746 | MessageDisplay.Add("tuli nelonen"); |
---|
747 | taso = lisaaTaso(); |
---|
748 | } |
---|
749 | else |
---|
750 | { |
---|
751 | taso = lisaaTaso(); |
---|
752 | } |
---|
753 | |
---|
754 | |
---|
755 | return taso; |
---|
756 | } |
---|
757 | |
---|
758 | PhysicsObject LuoReunat() |
---|
759 | { |
---|
760 | PhysicsObject reuna = PhysicsObject.CreateStaticObject(40, 800); |
---|
761 | reuna.IsVisible = false; |
---|
762 | reuna.Restitution = 1.0; |
---|
763 | return reuna; |
---|
764 | } |
---|
765 | |
---|
766 | PhysicsObject LuoAlaReuna() |
---|
767 | { |
---|
768 | alaReuna = PhysicsObject.CreateStaticObject(800, 40); |
---|
769 | alaReuna.Color = Color.Black; |
---|
770 | alaReuna.IsVisible = false; |
---|
771 | alaReuna.Restitution = 1.0; |
---|
772 | return alaReuna; |
---|
773 | } |
---|
774 | |
---|
775 | PhysicsObject LuoYläReuna() |
---|
776 | { |
---|
777 | PhysicsObject yläReuna = PhysicsObject.CreateStaticObject(800, 40); |
---|
778 | yläReuna.Color = Color.Black; |
---|
779 | yläReuna.IsVisible = false; |
---|
780 | yläReuna.Restitution = 1.0; |
---|
781 | return yläReuna; |
---|
782 | } |
---|
783 | |
---|
784 | void KäsitteleMailanTörmäys(PhysicsObject maila, PhysicsObject kohde) |
---|
785 | { |
---|
786 | if (kohde.Tag.ToString() == "elämä") |
---|
787 | { |
---|
788 | AnnaElämä(); |
---|
789 | kohde.Destroy(); |
---|
790 | } |
---|
791 | else if (kohde.Tag.ToString() == "Power1") |
---|
792 | { |
---|
793 | |
---|
794 | if (pieniMaila == 1) |
---|
795 | { |
---|
796 | PalautaMaila(); |
---|
797 | } |
---|
798 | else if (isoMaila == 0) |
---|
799 | { |
---|
800 | maila.Width += 20; |
---|
801 | isoMaila = 1; |
---|
802 | Timer.SingleShot(20, PalautaMaila); |
---|
803 | } |
---|
804 | |
---|
805 | kohde.Destroy(); |
---|
806 | } |
---|
807 | else if (kohde.Tag.ToString() == "Power2") |
---|
808 | { |
---|
809 | if (isoMaila == 1) |
---|
810 | { |
---|
811 | PalautaMaila(); |
---|
812 | } |
---|
813 | else if (pieniMaila == 0) |
---|
814 | { |
---|
815 | kohde.Destroy(); |
---|
816 | pieniMaila = 1; |
---|
817 | maila.Width -= 20; |
---|
818 | Timer.SingleShot(20, PalautaMaila); |
---|
819 | } |
---|
820 | |
---|
821 | } |
---|
822 | } |
---|
823 | |
---|
824 | void PalautaMaila() |
---|
825 | { |
---|
826 | if (isoMaila == 1) |
---|
827 | { |
---|
828 | maila.Width = 60; |
---|
829 | isoMaila = 0; |
---|
830 | } |
---|
831 | if (pieniMaila == 1) |
---|
832 | { |
---|
833 | maila.Width = 60; |
---|
834 | |
---|
835 | pieniMaila = 0; |
---|
836 | } |
---|
837 | |
---|
838 | } |
---|
839 | |
---|
840 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
841 | { |
---|
842 | if ((nopeus.X < 0) && (maila.Left < Level.Left + 40)) |
---|
843 | { |
---|
844 | maila.Velocity = Vector.Zero; |
---|
845 | return; |
---|
846 | } |
---|
847 | |
---|
848 | if ((nopeus.X > 0) && (maila.Right > Level.Right - 40)) |
---|
849 | { |
---|
850 | maila.Velocity = Vector.Zero; |
---|
851 | return; |
---|
852 | } |
---|
853 | maila.Velocity = nopeus; |
---|
854 | } |
---|
855 | |
---|
856 | void HävisitPelin() |
---|
857 | { |
---|
858 | ClearAll(); |
---|
859 | Label tekstikentta = new Label("Hävisit. Sait " + pisteet + " pistettä"); |
---|
860 | Add(tekstikentta); |
---|
861 | Timer.SingleShot(3, Valikko); |
---|
862 | } |
---|
863 | |
---|
864 | protected override void Update(Time time) |
---|
865 | { |
---|
866 | if (pallo != null && Math.Abs(pallo.Velocity.Y) < pallonNopeus) |
---|
867 | { |
---|
868 | pallo.Velocity = new Vector(pallo.Velocity.X, pallo.Velocity.Y * 1.1); |
---|
869 | |
---|
870 | } |
---|
871 | //if (pallo != null && Math.Abs(pallo.Velocity.X) < pallonNopeus) |
---|
872 | //{ |
---|
873 | // pallo.Velocity = new Vector(pallo.Velocity.X * 1.1, pallo.Velocity.Y); |
---|
874 | |
---|
875 | //} |
---|
876 | base.Update(time); |
---|
877 | |
---|
878 | } |
---|
879 | |
---|
880 | |
---|
881 | } |
---|