source: 2017/30/MainiI/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1.cs @ 9217

Revision 9217, 6.2 KB checked in by npo17_55, 6 years ago (diff)

Neliikkuu itekseen :D

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class FysiikkaPeli1 : PhysicsGame
10{
11    Image kenttaKuva = LoadImage("Kentta");
12    Image Pahankuva = LoadImage("Pahis");
13    Pelaaja OlioH;
14    SoundEffect NamAani = LoadSoundEffect("BOING1");
15    IntMeter PisteLaskuri;
16    Image taustakuva = LoadImage("Voittokuva");
17
18    public override void Begin()
19    {
20        Luokenttä();
21        SmoothTextures = false;
22        Mouse.IsCursorVisible = true;
23        LuoOhjaimet();
24
25        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
26        Camera.ZoomToLevel();
27
28    }
29    void Luokenttä()
30    {
31        ColorTileMap ruudut = ColorTileMap.FromLevelAsset("Kentta");
32
33        ruudut.SetTileMethod(Color.Gold, LuoOlioH);
34        ruudut.SetTileMethod(Color.Black, LuoTaso);
35        ruudut.SetTileMethod(Color.Red, LuoOlioP);
36        ruudut.SetTileMethod(Color.Rose, LuoHerkut);
37
38        ruudut.Execute(50, 50);
39
40        Level.Background.Color = Color.White;
41
42        Label pisteNaytto = new Label();
43        pisteNaytto.X = Screen.Left + 100;
44        pisteNaytto.Y = Screen.Top - 100;
45        pisteNaytto.TextColor = Color.Black;
46        pisteNaytto.Color = Color.White;
47
48        pisteNaytto.BindTo(OlioH.ElamaLaskuri);
49        Add(pisteNaytto);
50
51        PisteLaskuri = new IntMeter(0);
52
53        Label pisteNaytto2 = new Label();
54        pisteNaytto2.X = Screen.Right - 100;
55        pisteNaytto2.Y = Screen.Top - 100;
56        pisteNaytto2.TextColor = Color.Black;
57        pisteNaytto2.Color = Color.White;
58
59        pisteNaytto2.BindTo(PisteLaskuri);
60        Add(pisteNaytto2);
61
62
63
64    }
65    void LuoOlioH(Vector paikka, double leveys, double korkeus)
66    {
67        OlioH = new Pelaaja(leveys, korkeus);
68        OlioH.Position = paikka;
69        AddCollisionHandler(OlioH, "Pahis", TormaaVihuun); 
70        Add(OlioH);
71        OlioH.Color = Color.Gold;
72        OlioH.Shape = Shape.Circle;
73
74        AddCollisionHandler(OlioH, "Herkku", OlioSyo);
75    }
76    void TormaaVihuun(PhysicsObject Tormaaja,PhysicsObject KukaTormaa)
77    {
78        Pelaaja P = (Pelaaja)Tormaaja;
79        P.ElamaLaskuri.AddValue(-1);
80    }
81    void LuoTaso(Vector paikka, double leveys, double korkeus)
82    {
83        PhysicsObject seina = PhysicsObject.CreateStaticObject(leveys, korkeus);
84        seina.Position = paikka;
85        seina.Color = Color.Black;
86        seina.CollisionIgnoreGroup = 1;
87        Add(seina);
88        seina.Tag = "Seina";
89    }
90    void LuoHerkut(Vector paikka, double leveys, double korkeus)
91    {
92        PhysicsObject Herkku = new PhysicsObject(20.0, 20.0);
93        Add(Herkku);
94        Herkku.Shape = Shape.Circle;
95        Herkku.Color = Color.LimeGreen;
96        Herkku.Position = paikka;
97        Herkku.Tag = "Herkku";   
98    }
99    void OlioSyo(PhysicsObject tormaaja, PhysicsObject kohde)
100    {
101        //NamAani.Play();
102        kohde.Destroy();
103        PisteLaskuri.AddValue(1);
104        if (PisteLaskuri.Value == 1)
105        {
106            MessageDisplay.Add("Jeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee Voitit :3");
107            Level.Background.Image = taustakuva;
108
109            Level.Background.ScaleToLevelByHeight();
110
111        }
112       
113
114    }
115    void LuoOlioP(Vector paikka, double leveys, double korkeus)
116    {
117        PhysicsObject OlioP = new PhysicsObject(leveys, korkeus);
118        OlioP.IgnoresCollisionResponse = true;
119        OlioP.Position = paikka;
120        OlioP.Tag = "Pahis";
121        Add(OlioP, 1);
122        OlioP.Color = Color.Red;
123        OlioP.Shape = Shape.Circle;
124
125        LabyrinthWandererBrain tekoaivot = new LabyrinthWandererBrain(50.0, 150.0, "Seina");
126        OlioP.Brain = tekoaivot;
127        tekoaivot.Active = true;
128
129       //PathFollowerBrain polkuAivot = new PathFollowerBrain(100);
130
131       // OlioP.Brain = polkuAivot;
132
133       // polkuAivot.Active = true;
134       // polkuAivot.TurnWhileMoving = true;
135       // polkuAivot.Speed = 150;
136
137        //List<Vector> polku = new List<Vector>();
138
139        //polku.Add(new Vector(0.0, 0.0));
140        //polku.Add(new Vector(-300, 0.0));
141        //polku.Add(new Vector(-300, 350));
142        //polku.Add(new Vector(50, 350));
143        //polku.Add(new Vector(50, -10));
144        //polku.Add(new Vector(-30, 0.0));
145        //polku.Add(new Vector(-30, -150));
146        //polku.Add(new Vector(215, -150));
147        //polku.Add(new Vector(215, 500));
148        //polku.Add(new Vector(-450, 500));
149        //polku.Add(new Vector(-450, 70));
150        //polku.Add(new Vector(-280, 70));
151        //polku.Add(new Vector(-280, 350));
152        //polku.Add(new Vector(35, 350));
153        //polku.Add(new Vector(35, 270));
154        //polku.Add(new Vector(200, 270));
155        //polku.Add(new Vector(200, -150));
156        //polku.Add(new Vector(-450, -150));
157        //polku.Add(new Vector(-450, 500));
158        //polku.Add(new Vector(-215, 500));
159        //polku.Add(new Vector(-215, 350));
160        //polku.Add(new Vector(-120, 350));
161        //polku.Add(new Vector(-120, 0.0));
162
163        //polkuAivot.Path = polku;
164        //polkuAivot.Loop = true;
165
166    }
167    void LuoOhjaimet()
168    {
169        Keyboard.Listen(Key.Left, ButtonState.Down,
170        LiikutaPelaajaa, null, new Vector(-29000, 0));
171        Keyboard.Listen(Key.Right, ButtonState.Down,
172        LiikutaPelaajaa, null, new Vector(29000, 0));
173        Keyboard.Listen(Key.Up, ButtonState.Down,
174        LiikutaPelaajaa, null, new Vector(0, 2000));
175        Keyboard.Listen(Key.Down, ButtonState.Down,
176        LiikutaPelaajaa, null, new Vector(0, -2000));
177
178    }
179    void LiikutaPelaajaa(Vector vektori)
180    {
181        OlioH.Push(vektori);
182    }
183
184}
185    class Pelaaja : PlatformCharacter
186    {
187
188    public int Elamat { get; set; }
189
190    private IntMeter elamaLaskuri = new IntMeter(3, 0, 3);
191    public IntMeter ElamaLaskuri { get { return elamaLaskuri; } }
192
193    public Pelaaja(double leveys, double korkeus)
194            : base(leveys, korkeus)
195        {
196            elamaLaskuri.LowerLimit += delegate
197            {
198                this.Destroy(); };
199        }
200    }
Note: See TracBrowser for help on using the repository browser.