source: 2016/27/PaavoH/UltimateAdventure/UltimateAdventure/UltimateAdventure/UltimateAdventure.cs @ 8609

Revision 8609, 25.8 KB checked in by npo17_0, 6 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8using System.IO;
9
10public class UltimateAdventure : PhysicsGame
11{
12    double nopeus = 200;
13    const double JumpSpeed = 750;
14    const int RUUDUN_KOKO = 40;
15    IntMeter Pommit = new IntMeter(50);
16    Double Painovoima = -1000;
17    DoubleMeter DrownTime = new DoubleMeter (0.5);
18    bool saapiiskata = true;
19    bool saapommittaa = true;
20    PushButton TextureButton;
21    DoubleMeter aani = new DoubleMeter(0, 0, 1);
22    private IntMeter OxygenMeter;
23    List<string> destroybleThings = new List<string>(new string[]{ "PhysicsBlock", "moonstone", "turret", "snake", "silmamob","wizard","Ninja"});
24
25    PlatformCharacter pelaaja1;
26    IntMeter elamaLaskuri;
27
28    Image tahtiKuva = LoadImage("tahti");
29    Image Bpimage = LoadImage("stoneplatform");
30    Image silmamobimage = LoadImage("silmamob");
31    Image veripartikkeli = LoadImage("veripartikkeli");
32    Image playerhealth = LoadImage("playerhealth");
33    Image Bomb = LoadImage("bomb");
34    Image Arrow = LoadImage("Arrow");
35    Image PhysicBlockImage = LoadImage("PhysicBlockTexture");
36    Image TurretImage = LoadImage("TurretTextureV1");
37    Image Snake = LoadImage("snake");
38    Image Player = LoadImage("PlayerV2");
39    Image SpeedShoeImage = LoadImage("SpeedShoe");
40    //Image MoonstoneImage = LoadImage("Moonstone");
41    Image WizardrWand = LoadImage("WizardingWandV3");
42    Image LogoImage = LoadImage("LogoV1");
43    Image NinjaImage = LoadImage("Ninja");
44    Image Ninjathings = LoadImage("NinjaThings");
45    Image WizParticle = LoadImage("WizardingParticle");
46    Image AchivementBottom = LoadImage("AchivementBottom");
47    //Image marsstone = LoadImage("marsstone");
48    Image OxygenBottleImage = LoadImage("OxygenBottle");
49    Image NinjaStarImage = LoadImage("Shurigen");
50    Image Empty = LoadImage("Empty");
51
52    SoundEffect maaliAani = LoadSoundEffect("maali");
53    SoundEffect WizardZap = LoadSoundEffect("WizardZap");
54    Animation Ruoskanimaatio;
55    Animation Snakiitio;
56
57    GameObject Logo;
58
59    double aanenvoimakkuus = 0.1;
60
61    public override void Begin()
62    {
63        Snakiitio = LoadAnimation("SnakeV2");
64        Ruoskanimaatio = LoadAnimation("ruoska");
65        DataSave tulos = null;
66        tulos = DataStorage.Load<DataSave>(tulos, "Options.xml");
67        SmoothTextures = tulos.IsSmoothTex;
68        aani.Value = tulos.Volume;
69        LuoAlkuValikko();
70
71
72    }
73
74    void LuoAlkuValikko()
75    {
76        ClearAll();
77        LuoLogo();
78        MultiSelectWindow alkuValikko = new MultiSelectWindow("UltimateAdventure", "Aloita peli", "Options", "Avaa valittu kenttä","Trophies","Lopeta");
79
80        alkuValikko.AddItemHandler(0, AloitaPeli);
81        alkuValikko.AddItemHandler(1, MenuOptions);
82        alkuValikko.AddItemHandler(2, SelectLevel);
83        alkuValikko.AddItemHandler(3, Achivement);
84        alkuValikko.AddItemHandler(4, Exit);
85
86        Add(alkuValikko);
87    }
88    void LuoPeliValikko()
89    {
90        MultiSelectWindow Pelivalikko = new MultiSelectWindow(" ", "Jatka peliä", "Options", "Lopeta");
91
92        //Pelivalikko.AddItemHandler(0, AloitaPeli);
93        Pelivalikko.AddItemHandler(1, PeliOptions);
94        Pelivalikko.AddItemHandler(2, Exit);
95
96        Add(Pelivalikko);
97    }
98
99    void LuoLogo()
100    {
101        Logo = new GameObject(1000,120);
102        Logo.Y = Level.Top-100;
103        Logo.Image = LogoImage;
104        Add(Logo);
105    }
106    void AloitaPeli()
107    {
108        StartLevel("kentta1");
109
110    }
111
112    void Achivement()
113    {
114        GameObject Achivementbottom = new GameObject(300,70);
115        int Acloop = 0;
116        while (Acloop < 11)
117        {
118            Achivementbottom.Y = Level.Top - 100 * Acloop;
119            Acloop = Acloop + 1;
120        }
121        Achivementbottom.Image = AchivementBottom;
122        Add(Achivementbottom);
123        BackButton();
124        Logo.Destroy();
125        IsMouseVisible = true;
126    }
127    void StartLevel(String LevelName)
128    {
129        ClearAll();
130        Gravity = new Vector(0, Painovoima);
131
132        AddLevel(LevelName);
133        LisaaNappaimet();
134        LuoElamaLaskuri();
135        CreateOxygenMeter();
136        Camera.Follow(pelaaja1);
137        Camera.ZoomFactor = 2.8;
138        Camera.StayInLevel = true;
139
140        Label PommienMaara = new Label(Pommit);
141        PommienMaara.X = Screen.Right - 150;
142        PommienMaara.Y = Screen.Top - 150;
143        Add(PommienMaara);
144
145    }
146
147
148    void MenuOptions()
149    {
150        Options();
151        BackButton();
152    }
153    void Options()
154    {
155        Mouse.IsCursorVisible = true;
156        Slider liukusaadin = LuoSlider();
157        Add(liukusaadin);
158        TeeTextureButton();
159    }
160
161    void SelectLevel()
162    {
163        InputWindow AskWindow = new InputWindow("What level you want to play.");
164        AskWindow.TextEntered += ProcessInput;
165        Add(AskWindow);
166        BackButton();
167    }
168
169    void ProcessInput(InputWindow window)
170    {
171        string answer = window.InputBox.Text;
172        if (answer == null || answer == "") return;
173        FileStream stream = null;
174        bool success = true;
175        try 
176        {
177            stream = File.Open("Content\\" + answer+".xnb", FileMode.Open);
178        }
179        catch (FileNotFoundException f)
180        {
181            success = false;
182        }
183        finally
184        {
185            if(stream != null)
186                stream.Close();
187        }
188        if (success)
189            StartLevel(answer);
190        else
191            SelectLevel();
192    }
193   
194
195    void PeliOptions()
196    {
197        Options();
198        TeeSuljePeliOptions();
199    }
200    void TeeTextureButton()
201    {
202        TextureButton = new PushButton("" + SmoothTextures);
203        TextureButton.Y = -100;
204        TextureButton.Clicked += PaivitaTextureButton;
205        TextureButton.Tag = "Options";
206
207        Add(TextureButton);
208    }
209    void PaivitaTextureButton()
210    {
211        SmoothTextures = !SmoothTextures;
212        TextureButton.Text = "" + SmoothTextures;
213    }
214    Slider LuoSlider()
215    {
216
217        aani.Changed += MuutaAanenvoimakuutta;
218
219        Slider liukusaadin = new Slider(200, 20);
220        liukusaadin.BindTo(aani);
221        liukusaadin.Tag = "Options";
222        liukusaadin.X = 0;
223        liukusaadin.Y = 0;
224
225        liukusaadin.Color = Color.GreenYellow;
226        liukusaadin.Knob.Image = tahtiKuva;
227        liukusaadin.Track.Color = Color.Black;
228        liukusaadin.BorderColor = Color.LightBlue;
229
230        return liukusaadin;
231
232    }
233    void BackButton()
234    {
235        PushButton BackNappain = new PushButton("Back");
236        BackNappain.Y = -300;
237        BackNappain.Clicked += SaveOptions;
238        BackNappain.Clicked += LuoAlkuValikko;
239
240        Add(BackNappain);
241    }
242
243    void SaveOptions()
244    {
245        DataSave save = new DataSave();
246        save.IsSmoothTex = SmoothTextures;
247        save.Volume = aani.Value;
248        DataStorage.Save<DataSave>(save, "Options.xml");
249       
250
251    }
252    void TeeSuljePeliOptions()
253    {
254        PushButton SuljePeliOptions = new PushButton("Back");
255        SuljePeliOptions.Y = -300;
256        SuljePeliOptions.Tag = "Options";
257        SuljePeliOptions.Clicked += SaveOptions;
258        SuljePeliOptions.Clicked += JatkaPelia;
259
260        Add(SuljePeliOptions);
261    }
262
263    void JatkaPelia()
264    {
265        List<GameObject> Oliot = GetObjectsWithTag("Options");
266        foreach (GameObject item in Oliot)
267        {
268            item.Destroy();
269        }
270        IsMouseVisible = false;
271    }
272    void MuutaAanenvoimakuutta(double vanhaArvo, double uusiArvo)
273    {
274        aanenvoimakkuus = uusiArvo;
275        MessageDisplay.Add(aanenvoimakkuus.ToString());
276    }
277
278    void AddLevel(String LevelName)
279    {
280         TileMap level = TileMap.FromLevelAsset(LevelName);
281        level.SetTileMethod('#', LisaaSolid);
282        level.SetTileMethod('&', LisaaBp);
283        level.SetTileMethod('*', LisaaHealt);
284        level.SetTileMethod('o', LisaaPelaaja);
285        level.SetTileMethod('0', LisaaSilmamob);
286        level.SetTileMethod('5', LisaaSnakemob);
287        level.SetTileMethod('>', LisaaTurret);
288        level.SetTileMethod('☂', PhysicBlock);
289        level.SetTileMethod('7', LisaaSpeedBoots);
290        level.SetTileMethod('O', LisaaPommipakkaus);
291        level.SetTileMethod('U', Water);
292        level.SetTileMethod('W', Wizard);
293        level.SetTileMethod('C', Moonstone);
294        level.SetTileMethod('N', Ninja);
295        level.SetTileMethod('H', OxygenBottle);
296        level.Execute(RUUDUN_KOKO, RUUDUN_KOKO);
297        Level.CreateBorders();
298        Level.Background.CreateGradient(Color.SkyBlue, Color.SkyBlue);
299    }
300
301    void LisaaSolid(Vector paikka, double leveys, double korkeus)
302    {
303        PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus);
304        taso.Position = paikka;
305        taso.Color = RandomGen.NextColor();
306        Add(taso);
307    }
308
309    void LisaaBp(Vector paikka, double leveys, double korkeus)
310    {
311        PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus);
312        taso.Position = paikka;
313        taso.Image = Bpimage;
314        taso.Tag = "PhysicsBlock";
315        Add(taso);
316    }
317
318    void LisaaTurret(Vector paikka, double leveys, double korkeus)
319    {
320        PhysicsObject Turret = PhysicsObject.CreateStaticObject(leveys, korkeus);
321        Turret.Position = paikka;
322        Turret.Image = TurretImage;
323        Turret.Tag = "turret";
324        Add(Turret);
325
326
327        Timer ajastin = new Timer();
328        ajastin.Interval = 0.1;
329        ajastin.Timeout += delegate
330        {
331            if (pelaaja1.X > Turret.X && Math.Abs(pelaaja1.Y - Turret.Y) < 20)
332            {
333                PhysicsObject nuoli = new PhysicsObject(30, 5);
334                nuoli.Position = Turret.Position;
335                nuoli.Velocity = new Vector(1700, 0);
336                Add(nuoli);
337                nuoli.Image = Arrow;
338                nuoli.Tag = "nuoli";
339                //AddCollisionHandler(nuoli, CollisionHandler.DestroyObject);
340                ajastin.Stop();
341            }
342        };
343        ajastin.Start();
344    }
345
346    void PhysicBlock(Vector paikka, double leveys, double korkeus)
347    {
348        PhysicsObject PhysicBlock = new PhysicsObject(leveys, korkeus);
349        PhysicBlock.Position = paikka;
350        PhysicBlock.Image = PhysicBlockImage;
351        PhysicBlock.Mass = 200.0;
352        Add(PhysicBlock);
353    }
354
355    void Moonstone(Vector paikka, double leveys, double korkeus)
356    {
357        PhysicsObject Moonstone = PhysicsObject.CreateStaticObject(leveys, korkeus);
358        Moonstone.Position = paikka;
359        //Moonstone.Image = MoonstoneImage;
360        Moonstone.Tag = "moonstone";
361        Add(Moonstone);
362    }
363
364
365    void Water(Vector paikka, double leveys, double korkeus)
366    {
367        GameObject Water = new GameObject(leveys, korkeus);
368        Water.Position = paikka;
369        Water.Color = new Color(0, 0, 100, 55);
370        Add(Water, 2);
371        Water.Tag = "Water";
372
373        Timer ajastin = new Timer();
374        ajastin.Interval = 0.1;
375        ajastin.Timeout += delegate
376        {
377            int palikoitaVasemmalla = GetObjectsAt(Water.Position + new Vector(-leveys, 0)).Count;
378            int palikoitaOikealla = GetObjectsAt(Water.Position + new Vector(leveys, 0)).Count;
379            int palikoitaAlhaalla = GetObjectsAt(Water.Position + new Vector(0, -korkeus)).Count;
380
381            if (palikoitaOikealla + palikoitaVasemmalla + palikoitaAlhaalla < 6)
382            {
383                Water.Destroy();
384                ajastin.Stop();
385            }
386        };
387        ajastin.Start();
388    }
389
390
391
392    void LisaaHealt(Vector paikka, double leveys, double korkeus)
393    {
394        PhysicsObject healt = PhysicsObject.CreateStaticObject(leveys, korkeus);
395        healt.IgnoresCollisionResponse = true;
396        healt.Position = paikka;
397        healt.Image = tahtiKuva;
398        healt.Tag = "healt";
399        Add(healt);
400    }
401
402    void LisaaPommipakkaus(Vector paikka, double leveys, double korkeus)
403    {
404        PhysicsObject Pommipakkaus = PhysicsObject.CreateStaticObject(leveys, korkeus);
405        Pommipakkaus.IgnoresCollisionResponse = true;
406        Pommipakkaus.Position = paikka;
407        //Pommipakkaus.Image = tahtiKuva;
408        Pommipakkaus.Tag = "Pommipakkaus";
409        Add(Pommipakkaus);
410    }
411    void LisaaSpeedBoots(Vector paikka, double leveys, double korkeus)
412    {
413        PhysicsObject SpeedShoe = PhysicsObject.CreateStaticObject(leveys, korkeus);
414        SpeedShoe.IgnoresCollisionResponse = true;
415        SpeedShoe.Position = paikka;
416        SpeedShoe.Tag = "SpeedBoots";
417        SpeedShoe.Image = SpeedShoeImage;
418        Add(SpeedShoe);
419    }
420    void LisaaPelaaja(Vector paikka, double leveys, double korkeus)
421    {
422        pelaaja1 = new PlatformCharacter(leveys, korkeus);
423        pelaaja1.Position = paikka;
424        pelaaja1.Mass = 4.0;
425        pelaaja1.Image = Player;
426        pelaaja1.Tag = "pelaaja";
427        pelaaja1.Mass = 100.0;
428        AddCollisionHandler(pelaaja1, "healt", TormaaHealtiin);
429        AddCollisionHandler(pelaaja1, "silmamob", TormaaSilmaMobiin);
430        AddCollisionHandler(pelaaja1, "snake", TormaaSnakeen);
431        AddCollisionHandler(pelaaja1, "nuoli", TormaaNuoleen);
432        AddCollisionHandler(pelaaja1, "SpeedBoots", TormaaSpeedBootsiin);
433        AddCollisionHandler(pelaaja1, "Pommipakkaus", TormaaPommipakkaukseen);
434        AddCollisionHandler(pelaaja1, "Ammo", AmmoTormaus);
435        AddCollisionHandler(pelaaja1, "OxygenBottle", OxygenBotle);
436        Add(pelaaja1);
437    }
438
439    void OxygenBottle(Vector paikka, double leveys, double korkeus)
440    {
441        PhysicsObject OxygenBottle = PhysicsObject.CreateStaticObject(leveys / 2, korkeus / 2);
442        OxygenBottle.IgnoresCollisionResponse = true;
443        OxygenBottle.Position = paikka;
444        OxygenBottle.Tag = "OxygenBottle";
445        OxygenBottle.Image = OxygenBottleImage;
446        Add(OxygenBottle);
447    }
448
449
450    void LisaaSilmamob(Vector paikka, double leveys, double korkeus)
451    {
452        PlatformCharacter SilmaMob = new PlatformCharacter(leveys, korkeus);
453        PlatformWandererBrain SilmaMobAivot = new PlatformWandererBrain();
454        SilmaMob.Position = paikka; 
455        SilmaMobAivot.Speed = 100;
456        SilmaMob.Tag = "silmamob";
457        SilmaMob.Image = silmamobimage;
458        SilmaMob.Brain = SilmaMobAivot;
459        Add(SilmaMob);
460    }
461
462    void LisaaSnakemob(Vector paikka, double leveys, double korkeus)
463    {
464        PlatformCharacter Snake = new PlatformCharacter(leveys, korkeus);
465        PlatformWandererBrain Snakeaivot = new PlatformWandererBrain();
466        Snakeaivot.Speed = 100;
467        Snake.Position = paikka;
468        Snake.Tag = "snake";
469        Snake.Brain = Snakeaivot;
470        Snake.Animation = new Animation(Snakiitio);
471        Snake.Animation.Start();
472
473        Add(Snake);
474        }
475
476        void Wizard(Vector paikka, double leveys, double korkeus)
477        {
478            PlatformCharacter Wizard = new PlatformCharacter(leveys, korkeus);
479            Wizard.Position = paikka;
480            Wizard.Image = Player;
481            Wizard.Tag = "Wizard";
482
483            FollowerBrain WizardBrain = new FollowerBrain(pelaaja1);
484            PlatformWandererBrain toisetAivot = new PlatformWandererBrain();
485            WizardBrain.FarBrain = toisetAivot;
486            Wizard.Brain = WizardBrain;
487            WizardBrain.DistanceClose = 10 * RUUDUN_KOKO;
488
489
490            Wizard.Weapon = new AssaultRifle(10, 10);
491            Wizard.Weapon.Position = new Vector(10, 0);
492            Wizard.Weapon.AttackSound = WizardZap;
493            Wizard.Weapon.Power.DefaultValue = 200;
494
495            Wizard.Weapon.Image = WizardrWand;
496            //Wizard.Weapon.Image = WizardrWand; Ammuksen kuvaksi
497            Add(Wizard);
498
499            const double ampumisEtaisyys = 10 * RUUDUN_KOKO;
500            WizardBrain.TargetClose += delegate
501            {
502                Timer shootingtimer = new Timer();
503                shootingtimer.Interval = 0.75;
504                shootingtimer.Timeout += delegate
505                {
506                    if (Vector.Distance(Wizard.Position, pelaaja1.Position) < ampumisEtaisyys)
507                    {
508                        PhysicsObject Ammus = Wizard.Weapon.Shoot();
509                        if (Ammus != null)
510                        {
511                            Ammus.Image = WizParticle;
512                            AddCollisionHandler(Ammus, CollisionHandler.DestroyObject);
513                            Ammus.Tag = "Ammo";
514                        }
515                    }
516                };
517                shootingtimer.Start();
518            };
519
520        }
521
522        void Ninja(Vector paikka, double leveys, double korkeus)
523     { 
524        PlatformCharacter Ninja = new PlatformCharacter(leveys /8 *3, korkeus);
525        Ninja.Position = paikka;
526        Ninja.Image = NinjaImage;
527        Ninja.Tag = "Ninja";
528        GameObject NinjaThings = new GameObject(leveys, korkeus);
529        NinjaThings.Image = Ninjathings;
530        Ninja.Add(NinjaThings);
531
532        FollowerBrain NinjaBrain = new FollowerBrain(pelaaja1);
533        PlatformWandererBrain toisetAivot = new PlatformWandererBrain();
534        NinjaBrain.FarBrain = toisetAivot;
535        Ninja.Brain = NinjaBrain;
536        NinjaBrain.DistanceClose = 10 * RUUDUN_KOKO;
537
538
539        Ninja.Weapon = new AssaultRifle(10, 10);
540        Ninja.Weapon.AttackSound = null;
541        Ninja.Weapon.Power.Value = 20;
542        Ninja.Weapon.Power.DefaultValue = 20;
543
544        Ninja.Weapon.Image = Empty;
545        Add(Ninja);
546
547        const double ampumisEtaisyys = 10 * RUUDUN_KOKO;
548        NinjaBrain.TargetClose += delegate
549        {
550            Timer shootingtimer = new Timer();
551            shootingtimer.Interval = 5;
552            shootingtimer.Timeout += delegate
553            {
554                if (Vector.Distance(Ninja.Position, pelaaja1.Position) < ampumisEtaisyys)
555                {
556                    PhysicsObject Ammus = Ninja.Weapon.Shoot();
557                    if (Ammus != null)
558                    {
559                        Ammus.Image = NinjaStarImage;
560                        AddCollisionHandler(Ammus, CollisionHandler.DestroyObject);
561                        Ammus.Tag = "Ammo";
562                    }
563                }
564            };
565            shootingtimer.Start();
566        };
567    }
568
569
570    void LisaaNappaimet()
571    {
572        //Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
573        Keyboard.Listen(Key.Escape, ButtonState.Pressed, LuoPeliValikko, "Lopeta peli");
574
575        Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, "", pelaaja1, -1.0);
576        Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, "", pelaaja1, 1.0);
577        Keyboard.Listen(Key.W, ButtonState.Pressed, Hyppaa, "", pelaaja1, JumpSpeed);
578        Keyboard.Listen(Key.W, ButtonState.Down, Ui, "", pelaaja1);
579
580        Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Lyo, "Pelaaja Lyö", pelaaja1);
581        Mouse.Listen(MouseButton.Right, ButtonState.Pressed, HeitaPommi, "Pelaaja heittää pommin", pelaaja1);
582
583        ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä");
584
585        ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, "Liikuta pelaajaa tattia pyörittämällä.");
586        ControllerOne.Listen(Button.A, ButtonState.Pressed, Hyppaa, "", pelaaja1, JumpSpeed);
587        ControllerOne.Listen(Button.A, ButtonState.Down, Ui, "", pelaaja1);
588        ControllerOne.Listen(Button.RightShoulder, ButtonState.Pressed, HeitaPommi, "Pelaaja heittää pommin", pelaaja1);
589        ControllerOne.Listen(Button.LeftShoulder, ButtonState.Pressed, Lyo, "Pelaaja Lyö", pelaaja1);
590    }
591
592    void LiikutaPelaajaa(AnalogState tatinTila)
593    {
594        Vector tatinAsento = tatinTila.StateVector;
595        pelaaja1.Walk(tatinAsento.X * nopeus);
596    }
597    void Lyo(PlatformCharacter hahmo)
598    {
599        if (saapiiskata == false)
600            return;
601
602        saapiiskata = false;
603
604        PhysicsObject temp = new PhysicsObject(50, 20);
605        //temp.IsVisible = false;
606        temp.IgnoresGravity = true;
607        temp.IgnoresCollisionResponse = true;
608        temp.Destroyed += delegate { saapiiskata = true; };
609        Add(temp);
610        temp.Animation = new Animation(Ruoskanimaatio);
611        temp.Animation.Start();
612
613        AddCollisionHandler(temp, "silmamob", CollisionHandler.DestroyTarget);
614        AddCollisionHandler(temp, "snake", CollisionHandler.DestroyTarget);
615
616        Timer.SingleShot(1, temp.Destroy);
617
618        Timer ajastin = new Timer();
619        ajastin.Interval = 0.01;
620        ajastin.Timeout += delegate
621        {
622            if (hahmo.FacingDirection == Direction.Left)
623            {
624                temp.TextureWrapSize = new Vector(-1, 1);
625                temp.Position = new Vector((hahmo.Position.X - (hahmo.Width / 2) - (temp.Width * .35)), hahmo.Position.Y);
626            }
627            else
628            {
629                temp.TextureWrapSize = new Vector(1, 1);
630                temp.Position = new Vector((hahmo.Position.X + (hahmo.Width / 2) + (temp.Width * .35)), hahmo.Position.Y);
631            }
632        };
633        ajastin.Start();
634    }
635    void HeitaPommi(PlatformCharacter hahmo)
636    {
637        if (saapommittaa == false || Pommit.Value <= 0)
638            return;
639        Pommit.Value--;
640
641        saapommittaa = false;
642
643        Grenade Pommi = new Grenade(10.0);
644        for (int i = 0; i < destroybleThings.Count; i++)
645        {
646         Pommi.Explosion.AddShockwaveHandler(destroybleThings[i], DestroyCube);
647        }
648        Pommi.Explosion.AddShockwaveHandler(pelaaja1, PalyerTouchingExplo);
649        hahmo.Throw(Pommi, Angle.FromDegrees(30), 10000);
650        Pommi.Image = Bomb;
651
652        Timer.SingleShot(.2, delegate { saapommittaa = true; });
653    }
654
655    void Liikuta(PlatformCharacter hahmo, double suunta)
656    {
657        hahmo.Walk(nopeus * suunta);
658    }
659
660    void Hyppaa(PlatformCharacter hahmo, double nopeus)
661    {
662        hahmo.Jump(nopeus);
663    }
664
665    void Ui (PlatformCharacter hahmo)
666    {
667        GameObject alla = GetObjectAt(hahmo.Position - new Vector(0, RUUDUN_KOKO / 2 + 2));
668        if (alla != null && alla.Tag ==  "Water")
669        {
670            hahmo.Velocity = new Vector(0, 100);
671        }
672    }
673
674    void TormaaHealtiin(PhysicsObject hahmo, PhysicsObject healt)
675    {
676        maaliAani.Play(aanenvoimakkuus, 0.0, 0.0);
677        healt.Destroy();
678        elamaLaskuri.Value += 5;
679    }
680
681    void LuoElamaLaskuri()
682    {
683        elamaLaskuri = new IntMeter(10);
684        elamaLaskuri.MaxValue = 99;
685        elamaLaskuri.LowerLimit += ElamaLoppui;
686
687        Label ElamaKuva = new Label(playerhealth);
688        ElamaKuva.Size = new Vector(80, 80);
689        Add(ElamaKuva);
690
691        Label pisteNaytto = new Label();
692        pisteNaytto.X = Screen.Left + 100;
693        pisteNaytto.Y = Screen.Top - 100;
694        pisteNaytto.TextColor = Color.Black;
695        pisteNaytto.Color = Color.Red;
696        pisteNaytto.BindTo(elamaLaskuri);
697        Add(pisteNaytto);
698
699        ElamaKuva.X = pisteNaytto.X;
700        ElamaKuva.Y = pisteNaytto.Y;
701
702
703
704    }
705
706    void CreateOxygenMeter()
707    {
708        OxygenMeter = new IntMeter(10, 0, 10);
709        //OxygenMeter.LowerLimit += ElamaLoppui;
710
711        ProgressBar OxygenBar = new ProgressBar(500, 20);
712        OxygenBar.X = 0;
713        OxygenBar.Y = Screen.Top - 20;
714        OxygenBar.BindTo(OxygenMeter);
715        OxygenBar.Color = Color.MidnightBlue;
716        OxygenBar.BarColor = Color.LightBlue;
717        Add(OxygenBar);
718
719        Timer DrowningTimer = new Timer();
720        DrowningTimer.Interval = DrownTime;
721        DrowningTimer.Timeout += CheckDrowning;
722        DrowningTimer.Start();
723    }
724
725    void CheckDrowning()
726    {
727        GameObject Water = GetObjectAt(pelaaja1.Position, "Water", 1);
728        if (Water == null)
729        {
730            OxygenMeter.Value++;
731        }
732        else
733        {
734            OxygenMeter.Value--;
735
736            if (OxygenMeter.Value == 0)
737            {
738                elamaLaskuri.Value--;
739            }
740        }
741    }
742
743
744
745    void ElamaLoppui()
746    {
747        pelaaja1.Destroy();
748        ExplosionSystem rajahdys = new ExplosionSystem(veripartikkeli, 100);
749        Add(rajahdys);
750        rajahdys.MaxScale = 1.0;
751        rajahdys.MaxVelocity = 20.0;
752        rajahdys.MinLifetime = 2.0;
753        int pMaara = 50;
754        Timer.SingleShot(3.0, ConfirmExit);
755
756
757
758        rajahdys.AddEffect(pelaaja1.X, pelaaja1.Y, pMaara);
759        //rajahdys.X = pelaaja1.X;
760        //rajahdys.Y = pelaaja1.Y;
761    }
762    void TormaaSilmaMobiin(PhysicsObject hahmo, PhysicsObject silmamob)
763    {
764        elamaLaskuri.Value -= 1;
765    }
766
767    void TormaaSnakeen(PhysicsObject hahmo, PhysicsObject silmamob)
768    {
769        elamaLaskuri.Value -= 1;
770    }
771
772    void AmmoTormaus(PhysicsObject hahmo, PhysicsObject silmamob)
773    {
774        elamaLaskuri.Value -= 9;
775    }
776
777    void TormaaNuoleen(PhysicsObject hahmo, PhysicsObject nuoli)
778    {
779        elamaLaskuri.Value -= 2;
780
781    }
782
783    void TormaaSpeedBootsiin(PhysicsObject hahmo, PhysicsObject SpeedBoots)
784    {
785        nopeus *= 2;
786        SpeedBoots.Destroy();
787        Timer.SingleShot(5.0, delegate { nopeus /= 2; });
788
789    }
790
791    void TormaaPommipakkaukseen(PhysicsObject hahmo, PhysicsObject Pommipakkaus)
792    {
793        Pommit.Value += 5;
794        Pommipakkaus.Destroy();
795    }
796
797    void OxygenBotle(PhysicsObject hahmo, PhysicsObject OxygenBottle)
798    {
799        DrownTime.Value+= 0.5;
800        OxygenBottle.Destroy();
801    }
802
803    void DestroyCube(IPhysicsObject destroyable, Vector v  )
804    {
805        destroyable.Destroy();
806    }
807    void PalyerTouchingExplo(IPhysicsObject pelaaja1, Vector v)
808    {
809        elamaLaskuri.Value -= 5;
810    }
811
812    void WizardRage()
813    {
814   
815    }
816}
Note: See TracBrowser for help on using the repository browser.