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