source: 2011/24/LauriK/Call of garden Modern carrotfare 2/Call of garden Modern carrotfare 2/Peli.cs @ 2445

Revision 2445, 25.8 KB checked in by lavevake, 12 years ago (diff)

Beta 2.0

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Peli : PhysicsGame
10{
11
12    const double nopeus = 200;
13    const double hyppyNopeus = 1000;
14    const int RUUDUN_KOKO = 40;
15
16    int kentanNro = 0;
17
18    ScoreList topLista = new ScoreList(10, false, 0);
19
20    PlatformCharacter porkkana;
21    PhysicsObject hautakivi;
22    PhysicsObject kuolluttomaatti;
23    PhysicsObject lipas;
24    PhysicsObject uusikranaatti;
25    PhysicsObject raha;
26
27    public bool pelaajallaOnLaser = false;
28
29    string cheat1 = "LaserBlast";
30    string cheat2 = "MoonGravity";
31    string cheat3 = "ClearAll";
32   
33    IntMeter panoslaskuri;
34    IntMeter pistelaskuri;
35    IntMeter kranaattiLaskuri;
36
37    List<GameObject> rajahdyksenTomaattiUhrit;
38    List<GameObject> rajahdyksenPorkkanaUhri;
39
40    Image[] pelaajanKuva = LoadImages("porkkana");
41    Image[] pelaajanKuvaPeilattu;
42    Image pelaajanKuvaKuolleena = LoadImage("rip");
43    Image[] vihollisenKuva = LoadImages("tomaatti");
44    Image[] vihollisenKuvaPeilattu;
45    Image vihollisenKuvaKuolleena = LoadImage("tomaattikuolleena");
46    Image lippaanKuva = LoadImage("Lipas2");
47    Image kranaatinKuva = LoadImage("ydinpommi");
48    Image uudenKranaatinKuva = LoadImage("Laatikko");
49    Image RahanKuva = LoadImage("Raha");
50    Image alustus1 = LoadImage("alustus1");
51    Image alustus2 = LoadImage("alustus2");
52    //Image alustus3 = LoadImage("alustus3");
53    Image maalinKuva = LoadImage("Maali");
54    Image alkuvalikko = LoadImage("alkuvalikko");
55
56    ExplosionSystem rajahdys;
57    int pMaxMaara = 50;
58
59    public override void Begin()
60    {
61        if (DataStorage.Exists("pisteet.xlm"))
62        {
63            topLista = DataStorage.Load<ScoreList>(topLista, "pisteet.xlm");
64        }     
65         
66        rajahdyksenTomaattiUhrit = new List<GameObject>();
67        rajahdyksenPorkkanaUhri = new List<GameObject>();
68       
69        pelaajanKuvaPeilattu = Image.Mirror(pelaajanKuva);
70        vihollisenKuvaPeilattu = Image.Mirror(vihollisenKuva);
71       
72        SeuraavaKentta(kentanNro);
73       
74        Gravity = new Vector(0, -1000);
75
76        rajahdys = new ExplosionSystem(LoadImage("rajahdys"), pMaxMaara);
77        rajahdys.MaxLifetime = 1.0;
78        rajahdys.MaxScale = 0.1;
79        Add(rajahdys);
80    }
81
82    void Valikko()
83    {
84        Camera.Reset();
85
86        ClearAll();
87
88        Level.Background.Image = alkuvalikko;
89        Level.Background.Width = Screen.Width;
90        Level.Background.Height = Screen.Height;
91
92        Label versio = new Label();
93        versio.SizeMode = TextSizeMode.Wrapped;
94        versio.Width = Screen.Width - 100;
95        versio.Height = Screen.Height;
96        versio.X = 500;
97        versio.Y = -95;
98        versio.TextColor = Color.Green;
99        versio.Font = Font.DefaultLargeBold;
100        Add(versio);
101        versio.Text = "Beta 2.0";
102       
103        MediaPlayer.Play("alkuaani");
104
105        ClearControls();
106
107        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä");
108        Keyboard.Listen(Key.Enter, ButtonState.Pressed, SeuraavaKentta, "Aloita peli", 1);
109
110        ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä");
111        ControllerOne.Listen(Button.Start, ButtonState.Pressed, SeuraavaKentta, "Aloita peli", 1);
112
113    }
114   
115    void SeuraavaKentta(int kentanNro)
116    {
117        if (kentanNro == 0) Valikko();
118        if (kentanNro == 1) luoAlustus1();
119        else if (kentanNro == 2) luoAlustus2();
120        //else if (kentanNro == 3) luoAlustus3();
121        else if (kentanNro > 2) LopetaPeli();
122    }
123
124    private void luoAlustus1()
125    {
126        Camera.Reset();
127
128        ClearAll();
129       
130        Level.Background.Image = alustus1;
131        Level.Background.Width = Screen.Width;
132        Level.Background.Height = Screen.Height;
133
134        MediaPlayer.Play("alustus1aani");
135
136        ClearControls();
137
138        Keyboard.Listen(Key.Enter, ButtonState.Pressed, TeeKentta1, "Aloita kenttä");
139
140        ControllerOne.Listen(Button.Start, ButtonState.Pressed, TeeKentta1,"Aloita kenttä");
141
142        MessageDisplay.TextColor = Color.White;
143    }
144
145    void luoAlustus2()
146    {
147        Camera.Reset();
148       
149        ClearAll();
150       
151        Level.Background.Image = alustus2;
152        Level.Background.Width = Screen.Width;
153        Level.Background.Height = Screen.Height;
154
155        MediaPlayer.Play("alustus2aani");
156
157        ClearControls();
158
159        Keyboard.Listen(Key.Enter, ButtonState.Pressed, TeeKentta2, "Aloita kenttä");
160
161        ControllerOne.Listen(Button.Start, ButtonState.Pressed, TeeKentta2, "Aloita kenttä");
162
163        MessageDisplay.TextColor = Color.White;
164    }
165
166    //void luoAlustus3()
167    //{
168    //    Camera.Reset();
169
170    //    ClearAll();
171
172    //    Level.Background.Image = alustus3;
173    //    Level.Background.Width = Screen.Width;
174    //    Level.Background.Height = Screen.Height;
175
176    //    MediaPlayer.Play("alustus3aani");
177
178    //    ClearControls();
179
180    //    Keyboard.Listen(Key.Enter, ButtonState.Pressed, TeeKentta3, "Aloita kenttä");
181
182    //    ControllerOne.Listen(Button.Start, ButtonState.Pressed, TeeKentta3, "Aloita kenttä");
183
184    //    MessageDisplay.TextColor = Color.White;
185    //}
186               
187    PhysicsObject lisaaTaso()
188    {
189        PhysicsObject taso = PhysicsObject.CreateStaticObject(RUUDUN_KOKO, RUUDUN_KOKO);
190        taso.Color = Color.Green;
191        return taso;
192    }
193
194    PhysicsObject lisaaTaso2()
195    {
196        PhysicsObject taso2 = PhysicsObject.CreateStaticObject(RUUDUN_KOKO, RUUDUN_KOKO);
197        taso2.Color = Color.Gray;
198        return taso2;
199    }
200
201    PhysicsObject lisaaTaso3()
202    {
203        PhysicsObject taso3 = PhysicsObject.CreateStaticObject(RUUDUN_KOKO, RUUDUN_KOKO);
204        taso3.Color = Color.Yellow;
205        return taso3;
206    }
207   
208    PlatformCharacter lisaaPelaaja()
209    {
210        porkkana = new PlatformCharacter(40, 40);
211        porkkana.Mass = 4.0;
212
213        if (pelaajallaOnLaser == true)
214        {
215            porkkana.Weapon = new LaserGun(60, 30);
216            porkkana.Weapon.Ammo.Value = 10;
217            porkkana.Weapon.Y = -3;
218            porkkana.Weapon.X = 0;
219            porkkana.Weapon.ProjectileCollision = AmmusOsui;
220        }
221
222        if (pelaajallaOnLaser == false)
223        {
224            porkkana.Weapon = new AssaultRifle(60, 30);
225            porkkana.Weapon.Ammo.Value = 10;
226            porkkana.Weapon.Y = -3;
227            porkkana.Weapon.X = 0;
228            porkkana.Weapon.ProjectileCollision = AmmusOsui;
229        }
230       
231        AddCollisionHandler(porkkana, LipasKranaattiOsuma);
232
233        porkkana.IgnoresExplosions = true;
234
235        porkkana.RightWalkingAnimation = new Animation(pelaajanKuva);
236        porkkana.LeftWalkingAnimation = new Animation(pelaajanKuvaPeilattu);
237
238        rajahdyksenPorkkanaUhri.Add(porkkana);
239       
240        return porkkana;
241    }
242
243    PlatformCharacter lisaaTomaatti()
244    {
245        PlatformCharacter tomaatti = new PlatformCharacter(40, 40);
246        tomaatti.Mass = 4.0;
247
248        tomaatti.Tag = "Vihollinen";
249
250        tomaatti.IgnoresGravity = false;
251
252        FollowerBrain SeuraajanAivot = new FollowerBrain();
253        tomaatti.Brain = SeuraajanAivot;
254        SeuraajanAivot.Target = porkkana;
255        SeuraajanAivot.Speed = 100;
256        SeuraajanAivot.TargetFollowDistance = 500;
257        SeuraajanAivot.TargetCloseDistance = 50;
258        SeuraajanAivot.StopWhenTargetClose = false;
259        AddCollisionHandler(tomaatti, TomaattiOsui);
260
261        tomaatti.RightWalkingAnimation = new Animation(vihollisenKuva);
262        tomaatti.LeftWalkingAnimation = new Animation(vihollisenKuvaPeilattu);
263       
264        rajahdyksenTomaattiUhrit.Add(tomaatti);
265
266        Timer.SingleShot(2, delegate { Seuraa(SeuraajanAivot); });
267
268        return tomaatti;
269
270    }
271
272    void Seuraa(FollowerBrain aivot)
273    {
274        aivot.Target = porkkana;
275    }
276
277    PlatformCharacter lisaaTomaatti2()
278    {
279        PlatformCharacter tomaatti2 = new PlatformCharacter(40, 40);
280        tomaatti2.Mass = 4.0;
281
282        tomaatti2.Tag = "Vihollinen2";
283
284        tomaatti2.Weapon = new AssaultRifle(60, 30);
285        tomaatti2.Weapon.Ammo.Value = 10;
286        tomaatti2.Weapon.Y = 0;
287        tomaatti2.Weapon.X = 0;
288        tomaatti2.Weapon.ProjectileCollision = AmmusOsui;
289       
290        Timer ampumaAjastin = new Timer();
291        ampumaAjastin.Interval = 2.0;
292        ampumaAjastin.Trigger += vihollinenAmpuu;
293        ampumaAjastin.Tag = tomaatti2;
294        ampumaAjastin.Start();
295
296        tomaatti2.RightWalkingAnimation = new Animation(vihollisenKuva);
297        tomaatti2.LeftWalkingAnimation = new Animation(vihollisenKuvaPeilattu);
298
299        rajahdyksenTomaattiUhrit.Add(tomaatti2);
300
301        return tomaatti2;
302    }
303   
304    void lisaaNappaimet()
305    {
306        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
307        Keyboard.Listen(Key.Escape, ButtonState.Pressed, SeuraavaKentta, "Poistu valikkoon", 0);
308        Keyboard.Listen(Key.A, ButtonState.Pressed, cheatIkkuna, "Avaa cheatikkuna");
309
310        Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", porkkana, -nopeus);
311        Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", porkkana, nopeus);
312        Keyboard.Listen(Key.Up, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", porkkana, hyppyNopeus);
313
314        Keyboard.Listen(Key.Space, ButtonState.Down, AmmuAseella, "Ammu rynnäkkökiväärillä");
315        Keyboard.Listen(Key.W, ButtonState.Down, TahtaaYlos, "Tähtää ylös rynnäkkökiväärillä");
316        Keyboard.Listen(Key.S, ButtonState.Down, TahtaaAlas, "Tähtää alas rynnäkkökiväärillä");
317        Keyboard.Listen(Key.Q, ButtonState.Pressed, HeitaKranaatti, "Heitä kranaatti");
318
319        ControllerOne.Listen(Button.Start, ButtonState.Pressed, SeuraavaKentta, "Poistu valikkoon", 0);
320        ControllerOne.Listen(Button.Back, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
321       
322        ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.01, liikutaTatilla, "Pelaaja liikkuu", porkkana);
323        ControllerOne.Listen(Button.A, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", porkkana, hyppyNopeus);
324
325        ControllerOne.Listen(Button.RightTrigger, ButtonState.Down, AmmuAseella, "Ammu rynnäkkökiväärillä");
326        ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.01, tahtaaTatilla, "Tähtää rynnäkkökiväärillä");
327        ControllerOne.Listen(Button.LeftTrigger, ButtonState.Pressed, HeitaKranaatti, "Heitä kranaatti");   
328    }
329
330    void liikuta(PlatformCharacter hahmo, double nopeus)
331    {
332        hahmo.Walk(nopeus);
333    }
334
335    void hyppaa(PlatformCharacter hahmo, double nopeus)
336    {
337        hahmo.Jump(nopeus);
338    }
339
340    void liikutaTatilla(AnalogState tatintila, PlatformCharacter hahmo)
341    {
342        Vector tatinAsento = tatintila.StateVector;
343        hahmo.Walk(tatinAsento.X*nopeus);
344
345    }
346
347    void AmmuAseella()
348    {
349        PhysicsObject ammus = porkkana.Weapon.Shoot();
350
351        if (ammus != null)
352        {
353            ammus.Size *= 1;
354            ammus.Restitution = 0.5;
355            ammus.MaximumLifetime = TimeSpan.FromSeconds(1.5);
356        }
357    }
358   
359    void TahtaaYlos()
360    {
361        if (porkkana.FacingDirection == Direction.Right)
362        {
363            porkkana.Weapon.Angle += Angle.FromDegrees(5);
364        }
365        if (porkkana.FacingDirection == Direction.Left)
366        {
367            porkkana.Weapon.Angle += Angle.FromDegrees(-5);
368        }
369
370
371    }
372
373    void TahtaaAlas()
374    {
375        if (porkkana.FacingDirection == Direction.Right)
376        {
377            porkkana.Weapon.Angle += Angle.FromDegrees(-5);
378        }
379        if (porkkana.FacingDirection == Direction.Left)
380        {
381            porkkana.Weapon.Angle += Angle.FromDegrees(5);
382        }
383    }
384   
385    void tahtaaTatilla(AnalogState toisentatintila)
386    {
387            Vector toisentatinAsento = toisentatintila.StateVector;
388            porkkana.Weapon.Angle = toisentatinAsento.Angle;
389    }   
390   
391    void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde)
392    {
393
394        if (kohde.Tag.ToString() == "Vihollinen" || kohde.Tag.ToString() == "Vihollinen2")
395        {
396            ammus.Destroy();
397            kohde.Brain = null;
398            TomaattiKuoli(kohde);
399            kohde.IgnoresCollisionResponse = true;
400            rajahdys.AddEffect(kohde.Position, 50);
401
402        }
403    }
404
405    void Ammus2Osui(PhysicsObject ammus2, PhysicsObject kohde)
406    {
407
408        if (kohde == porkkana)
409        {
410            ammus2.Destroy();;
411           
412            //porkkana.IgnoresCollisionResponse = true;
413
414            porkkana.Stop();
415
416            MediaPlayer.Play("pling");
417
418            porkkana.Destroy();
419
420            LuoHautakivi();
421
422            LopetaPeli();
423
424        }
425    }
426   
427    void LopetaPeli()
428    {
429        HighScoreWindow topIkkuna = new HighScoreWindow("Call of garden: Modern carrotfare",
430            "Parhaat pisteet",
431            "Onneksi olkoon, pääsit listalle pisteillä %p! Syötä nimesi:",
432            topLista, pistelaskuri.Value);
433        topIkkuna.Closed += TallennaPisteet;
434        Add(topIkkuna);       
435    }
436   
437    void LuoHautakivi()
438    {
439        hautakivi = new PhysicsObject(40, 40);
440        hautakivi.Mass = 100000000000.0;
441
442        hautakivi.IgnoresExplosions = true;
443
444        hautakivi.Image = pelaajanKuvaKuolleena;
445
446        hautakivi.Position = porkkana.Position;
447        Add(hautakivi);
448
449    }
450
451    void TomaattiKuoli(PhysicsObject tomaatti)
452    {
453        tomaatti.Destroy();
454
455        MediaPlayer.Play("ketshup");
456
457        pistelaskuri.Value += 100; 
458
459        kuolluttomaatti = new PhysicsObject(50, 50);
460        kuolluttomaatti.Mass = 4.0;
461
462        kuolluttomaatti.IgnoresCollisionResponse = true;
463
464        kuolluttomaatti.IgnoresGravity = true;
465
466        kuolluttomaatti.IgnoresExplosions = true;
467
468        kuolluttomaatti.Image = vihollisenKuvaKuolleena;
469
470        kuolluttomaatti.Position = tomaatti.Position;
471        Add(kuolluttomaatti);
472
473        LuoLipas(kuolluttomaatti.X - 30, kuolluttomaatti.Y);
474        LuoKranaatti(kuolluttomaatti.X + 30, kuolluttomaatti.Y);
475    }
476
477    void TomaattiOsui(PhysicsObject tomaatti, PhysicsObject kohde)
478    {
479        if (kohde == porkkana)
480        {         
481            tomaatti.Stop();
482            tomaatti.Brain.Active = false;
483
484            //porkkana.IgnoresCollisionResponse = true;
485
486            porkkana.Stop();
487
488            MediaPlayer.Play("pling");
489
490            porkkana.Destroy();
491
492            LuoHautakivi();
493
494            LopetaPeli();
495     
496        }
497
498    }
499
500    void LuoPanosLaskuri()
501    {
502        panoslaskuri = new IntMeter(0);
503
504        Label panosnaytto = new Label();
505        panosnaytto.X = Screen.Right - 100;
506        panosnaytto.Y = Screen.Top - 100;
507        panosnaytto.TextColor = Color.Red;
508       
509        panosnaytto.BindTo(porkkana.Weapon.Ammo);
510        Add(panosnaytto);
511
512        Label panosteksti = new Label("Panoksia jäljellä: ");
513        panosteksti.X = Screen.Right - 200;
514        panosteksti.Y = Screen.Top - 100;
515        panosteksti.TextColor = Color.Red;
516
517        Add(panosteksti); 
518    }
519   
520    void LuoPisteLaskuri()
521    {
522        pistelaskuri = new IntMeter(0);
523       
524        Label pistenaytto = new Label();
525        pistenaytto.X = Screen.Right - 100;
526        pistenaytto.Y = Screen.Top - 150;
527        pistenaytto.TextColor = Color.Red;
528
529        pistenaytto.BindTo(pistelaskuri);
530        Add(pistenaytto);
531
532        Label pisteteksti = new Label("Pisteitä: ");
533        pisteteksti.X = Screen.Right - 200;
534        pisteteksti.Y = Screen.Top - 150;
535        pisteteksti.TextColor = Color.Red;
536
537        Add(pisteteksti);
538    }
539
540    PhysicsObject LuoLipas()
541    {
542        lipas = new PhysicsObject(20, 20);
543        lipas.Mass = 2.0;
544
545        lipas.Image = lippaanKuva;
546
547        lipas.IgnoresExplosions = true;
548
549        lipas.Tag = "Lipas";
550
551        Add(lipas);
552        return lipas;
553    }
554
555    void LuoLipas(double x, double y)
556    {
557        LuoLipas().Position = new Vector(x,y);
558    }
559
560    void LipasKranaattiOsuma(PhysicsObject porkkana, PhysicsObject kohde)
561    {
562        if (kohde.Tag.ToString() == "Lipas")
563        {
564            ((PlatformCharacter)porkkana).Weapon.Ammo.Value +=5;
565            kohde.Destroy();
566        }
567        if (kohde.Tag.ToString() == "Kranaatti")
568        {
569            kranaattiLaskuri.Value++;
570            kohde.Destroy();
571        }
572       
573    }
574
575    void HeitaKranaatti()
576    {
577       
578        if (kranaattiLaskuri.Value > 0)
579        {
580            Grenade kranaatti = new Grenade(10.0);
581            kranaatti.Image = kranaatinKuva;
582            kranaatti.Mass = 1.0;
583            kranaatti.ExplosionRadius = 100.0;
584           
585            kranaattiLaskuri.Value -= 1;
586
587            kranaatti.X = porkkana.X;
588            kranaatti.Y = porkkana.Y;
589            Add(kranaatti);
590            Vector kranaatinlento = Vector.FromLengthAndAngle(700.0, porkkana.Weapon.Angle);
591            kranaatti.Hit(kranaatinlento);
592            kranaatti.Destroyed += new Action(delegate { kranaatti_Destroyed(kranaatti); });
593        }
594    }
595
596    void kranaatti_Destroyed(Grenade s)
597    {
598        foreach (PhysicsObject item in rajahdyksenTomaattiUhrit)
599        {
600            if (Vector.Distance(s.Position, item.Position) < s.ExplosionRadius)
601            {
602                TomaattiKuoli(item);
603                rajahdys.AddEffect(item.Position, 50);
604            }
605        }
606       
607        foreach (GameObject item in rajahdyksenPorkkanaUhri)
608        {
609            if (Vector.Distance(s.Position, item.Position) < s.ExplosionRadius)
610            {
611                porkkana.Stop();
612
613                MediaPlayer.Play("pling");
614
615                porkkana.Destroy();
616
617                LuoHautakivi();
618
619                LopetaPeli();
620     
621            }
622        }
623   
624   
625    }
626
627    void vihollinenAmpuu(Timer ampumaAjastin)
628    {
629        PlatformCharacter tomaatti2 = ampumaAjastin.Tag as PlatformCharacter;
630       
631        Vector ampumaSuunta = (porkkana.Position - tomaatti2.Position).Normalize();
632        tomaatti2.Weapon.Angle = ampumaSuunta.Angle;
633
634        PhysicsObject vihu = ampumaAjastin.Tag as PhysicsObject;
635       
636        PhysicsObject ammus2 = tomaatti2.Weapon.Shoot();
637       
638        if (ammus2 != null)
639        {
640            ammus2.Size *= 5;
641            ammus2.MaximumLifetime = TimeSpan.FromSeconds(1.5);
642            ammus2.IgnoresGravity = true;
643        }
644    }
645
646    void LuoKranaattiLaskuri ()
647    {
648        kranaattiLaskuri= new IntMeter(3);
649        kranaattiLaskuri.MinValue = 0;
650        Label kranaattiNaytto = new Label();
651        kranaattiNaytto.X = Screen.Right - 100;
652        kranaattiNaytto.Y = Screen.Top - 50;
653        kranaattiNaytto.TextColor = Color.Red;
654
655               
656        kranaattiNaytto.BindTo(kranaattiLaskuri);
657        Add( kranaattiNaytto);
658
659        Label kranaattiteksti = new Label("Kranaatteja jäljellä: ");
660        kranaattiteksti.X = Screen.Right - 200;
661        kranaattiteksti.Y = Screen.Top - 50;
662        kranaattiteksti.TextColor = Color.Red;
663
664        Add(kranaattiteksti); 
665    }
666
667    PhysicsObject LuoKranaatti()
668    {
669        uusikranaatti = new PhysicsObject(40, 20);
670        uusikranaatti.Mass = 2.0;
671
672        uusikranaatti.Image = uudenKranaatinKuva;
673
674        uusikranaatti.IgnoresExplosions = true;
675
676        uusikranaatti.Tag = "Kranaatti";
677
678        Add(uusikranaatti);
679        return uusikranaatti;
680    }
681
682    void LuoKranaatti(double x, double y)
683    {
684        LuoKranaatti().Position = new Vector(x, y);
685    }
686
687    PhysicsObject LuoMaali()
688    {
689        PhysicsObject maali = new PhysicsObject(40, 40);
690        maali.Image = maalinKuva;
691        maali.Mass = 4.0;
692        maali.Tag = "maali";
693        AddCollisionHandler(maali, MaaliinOsuma);
694        return maali;
695    }
696
697    void MaaliinOsuma(PhysicsObject maali, PhysicsObject kohde)
698    {
699            if (kentanNro == 1 ||  kohde == porkkana || maali.Tag == maali)
700            {
701                pistelaskuri.Value += 500;
702                //kentanNro = 2;
703                SeuraavaKentta(kentanNro);
704                kentanNro = 2;
705            }
706
707            else if (kentanNro == 2 || kohde == porkkana || maali.Tag == maali)
708            {
709                pistelaskuri.Value += 500;
710                //kentanNro = 3;
711                maali.Destroy();
712                SeuraavaKentta(kentanNro);
713                kentanNro = 3;
714            }     
715    }
716
717    void TallennaPisteet(Window sender)
718    {
719        DataStorage.Save<ScoreList>(topLista, "pisteet.xlm");
720
721        MediaPlayer.Stop();
722       
723        Label lopetus = new Label();
724        lopetus.SizeMode = TextSizeMode.Wrapped;
725        lopetus.Width = Screen.Width -100;
726        lopetus.Height = Screen.Height;
727        lopetus.TextColor = Color.Orange;
728        lopetus.Font = Font.DefaultLargeBold;
729        Add(lopetus);
730        lopetus.Text = "                                  Peli päättyi.\n" +
731        "Paina Escape/Start mennäksesi valikkoon tai Enter/A aloittaaksesi alusta.";
732
733        ClearControls();
734
735        Keyboard.Listen(Key.Enter, ButtonState.Pressed, SeuraavaKentta, "Aloita alusta", 1);
736       
737        Keyboard.Listen(Key.Escape, ButtonState.Pressed, SeuraavaKentta, "Poistu valikkoon", 0);
738
739        ControllerOne.Listen(Button.Start, ButtonState.Down, SeuraavaKentta, "Poistu valikkoon", 0);
740
741        ControllerOne.Listen(Button.A, ButtonState.Pressed, SeuraavaKentta, "Aloita alusta", 1);
742
743    }
744
745    PhysicsObject LuoRaha()
746    {
747        raha = new PhysicsObject(40, 40);
748        raha.Mass = 4.0;
749        raha.Image = RahanKuva;
750        AddCollisionHandler(raha, RahaanTormays);
751        return raha;
752    }
753
754    void RahaanTormays(PhysicsObject raha, PhysicsObject kohde)
755    {
756        if(kohde == porkkana)
757        {
758            pistelaskuri.Value += 100;
759            raha.Destroy();
760        }
761    }
762
763    void TeeKentta1()
764    {       
765        MediaPlayer.Stop();
766       
767        TileMap kentta = TileMap.FromFile("kentta1.txt");
768        kentta['#'] = lisaaTaso;
769        kentta['K'] = lisaaTaso2;
770        kentta['G'] = lisaaTaso3;
771        kentta['N'] = lisaaPelaaja;
772        kentta['E'] = lisaaTomaatti;
773        kentta['L'] = LuoLipas;
774        kentta['A'] = LuoKranaatti;
775        kentta['T'] = lisaaTomaatti2;
776        kentta['M'] = LuoMaali;
777        kentta['R'] = LuoRaha;
778        kentta['G'] = lisaaTaso3;
779        kentta.Insert(RUUDUN_KOKO, RUUDUN_KOKO);
780        Level.CreateBorders();
781        Level.Background.CreateGradient(Color.Blue, Color.Black);
782
783        Gravity = new Vector(0, -1000);
784       
785        LuoPanosLaskuri();
786        LuoPisteLaskuri();
787        LuoKranaattiLaskuri();
788
789        Camera.Follow(porkkana);
790
791        Camera.ZoomFactor = 0.5;
792        Camera.StayInLevel = true;
793
794        lisaaNappaimet();
795    }
796
797    void TeeKentta2()
798    {       
799        MediaPlayer.Stop();       
800       
801        TileMap kentta = TileMap.FromFile("kentta2.txt");
802        kentta['#'] = lisaaTaso;
803        kentta['K'] = lisaaTaso2;
804        kentta['G'] = lisaaTaso3;
805        kentta['N'] = lisaaPelaaja;
806        kentta['E'] = lisaaTomaatti;
807        kentta['L'] = LuoLipas;
808        kentta['A'] = LuoKranaatti;
809        kentta['T'] = lisaaTomaatti2;
810        kentta['M'] = LuoMaali;
811        kentta['R'] = LuoRaha;
812        kentta.Insert(RUUDUN_KOKO, RUUDUN_KOKO);
813        Level.CreateBorders();
814        Level.Background.CreateGradient(Color.Black, Color.Blue);
815
816        Gravity = new Vector(0, -1000);
817       
818        LuoPanosLaskuri();
819        LuoPisteLaskuri();
820        LuoKranaattiLaskuri();
821
822        Camera.Follow(porkkana);
823
824        Camera.ZoomFactor = 2.0;
825        Camera.StayInLevel = true;
826       
827        lisaaNappaimet();
828    }
829   
830    //void TeeKentta3()
831    //{
832    //    MediaPlayer.Stop();
833
834    //    TileMap kentta = TileMap.FromFile("kentta3.txt");
835    //    kentta['#'] = lisaaTaso;
836    //    kentta['K'] = lisaaTaso2;
837    //    kentta['G'] = lisaaTaso3;
838    //    kentta['N'] = lisaaPelaaja;
839    //    kentta['E'] = lisaaTomaatti;
840    //    kentta['L'] = LuoLipas;
841    //    kentta['A'] = LuoKranaatti;
842    //    kentta['T'] = lisaaTomaatti2;
843    //    kentta['M'] = LuoMaali;
844    //    kentta['R'] = LuoRaha;
845    //    kentta.Insert(RUUDUN_KOKO, RUUDUN_KOKO);
846    //    Level.CreateBorders();
847    //    Level.Background.CreateGradient(Color.Black, Color.Blue);
848
849    //    Gravity = new Vector(0, -1000);
850
851    //    LuoPanosLaskuri();
852    //    LuoPisteLaskuri();
853    //    LuoKranaattiLaskuri();
854
855    //    Camera.Follow(porkkana);
856
857    //    Camera.ZoomFactor = 1.0;
858    //    Camera.StayInLevel = true;
859
860    //    lisaaNappaimet();
861    //
862    //}
863
864    void cheatIkkuna()
865    {
866        InputWindow cheatIkkuna = new InputWindow("Kysymys", "Vastaa kysymykseen");
867        cheatIkkuna.TextEntered += ProcessInput;
868        Add(cheatIkkuna);
869    }
870
871    void ProcessInput(InputWindow cheatikkuna)
872    {
873        string vastaus = cheatikkuna.InputBox.Text;
874
875        if (vastaus == cheat1)
876        {
877            pelaajallaOnLaser = true;
878            MessageDisplay.Add("Laserase aktivoitu!");
879
880        }
881
882        if (vastaus == cheat2)
883        {
884            Gravity = new Vector(0, -250);
885            MessageDisplay.Add("Pieni painovoima aktivoitu!");
886        }
887
888        if (vastaus == cheat3)
889        {
890            Gravity = new Vector(0, -1000);
891            pelaajallaOnLaser = false;
892            MessageDisplay.Add("Kaikki cheatit poistettu!");
893        }
894
895        else
896        {
897            MessageDisplay.Add("Väärä koodi!");
898        }
899
900
901   
902    }
903}             
Note: See TracBrowser for help on using the repository browser.