source: 2012/23/LeoS/leoS/leoS/leoS.cs @ 2818

Revision 2818, 7.5 KB checked in by lesanton, 11 years ago (diff)

Uusi käänteispainovoimataso,taustamusiikki ja muuta sälää

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class LeoS : PhysicsGame
10{
11
12
13    PhysicsObject pelaaja;
14    bool pelaajaIlmassa = false;
15
16
17
18    public override void Begin()
19    {
20        MultiSelectWindow valikko = new MultiSelectWindow("Päävalikko",
21            "Kenttä1", "Kenttä2", "Kenttä3", "kentta4", "Lopeta"); valikko.ItemSelected += PainettiinValikonNappia;
22        Add(valikko);
23
24
25    }
26
27
28
29    void AloitaPeli(string levelFile)
30    {
31
32       
33       ClearAll();
34       LataaKentta(levelFile);
35       
36
37        Level.Background.CreateGradient(Color.Teal, Color.Ruby);
38        Gravity = new Vector(0, -400);
39
40        MediaPlayer.Play("Tausta");
41
42        Surface alareuna = Surface.CreateBottom(Level);
43        alareuna.IsVisible = false;
44        alareuna.Tag = "reuna";
45        Add(alareuna);
46
47        Surface oikeareuna = Surface.CreateRight(Level);
48        oikeareuna.IsVisible = false;
49        oikeareuna.Tag = "muuri";
50        Add(oikeareuna);
51        AsetaOhjaimet();
52       
53        Camera.Follow(pelaaja);
54
55    }
56
57
58    void PainettiinValikonNappia(int valinta)
59    {
60        switch (valinta)
61        {
62            case 0:
63                AloitaPeli("kentta1");
64                break;
65            case 1:
66                AloitaPeli("kentta2");
67                break;
68            case 2:
69                AloitaPeli("kentta3");
70                break;
71            case 3:
72                AloitaPeli2("kentta4");
73                break;
74            case 4:
75                Exit();
76                break;
77
78        }
79    }
80
81
82
83    void LuoKentta(string levelFile)
84    {
85
86    }
87
88    void LataaKentta(string levelFile)
89    {
90        TileMap ruudut = TileMap.FromLevelAsset(levelFile);
91        ruudut.SetTileMethod('P', LuoPelaaja);
92        ruudut.SetTileMethod('#', LuoPalikka);
93        ruudut.SetTileMethod('*', LuoEste);
94        ruudut.SetTileMethod('T', LuoTykki);
95
96
97        ruudut.Execute(20, 20);
98    }
99
100    void LuoPelaaja(Vector paikka, double leveys, double korkeus)
101    {
102        pelaaja = new PhysicsObject(leveys, korkeus);
103        pelaaja.Shape = Shape.Hexagon;
104        pelaaja.Color = Color.HotPink;
105        pelaaja.Position = paikka;
106        pelaaja.Mass = 10;
107        AddCollisionHandler(pelaaja, delegate(PhysicsObject p, PhysicsObject o) { pelaajaIlmassa = false; });
108        AddCollisionHandler(pelaaja, "reuna", PelaajaOsuiReunaan);
109        AddCollisionHandler(pelaaja, "muuri", PelaajaOsuiMuuriin);
110        AddCollisionHandler(pelaaja, "tahti", PelaajaOsuiTahtiin);
111        pelaaja.Restitution = 100.00;
112        Add(pelaaja);
113    }
114
115    void PelaajaOsuiReunaan(PhysicsObject tormaaja, PhysicsObject kohde)
116    {
117        tormaaja.Destroy();
118        Explosion rajahdys = new Explosion(600.0);
119        rajahdys.Position = pelaaja.Position;
120        Add(rajahdys);
121        Label tekstikentta = new Label("teksti");
122        tekstikentta.Text = "Hävisit Pelin";
123        tekstikentta.TextColor = Color.Black;
124        Add(tekstikentta);
125       
126       
127        tekstikentta.Font = Font.DefaultLarge;
128        LuoAikaLaskuri();
129
130
131    }
132
133    void LuoPalikka(Vector paikka, double leveys, double korkeus)
134    {
135        PhysicsObject taso = PhysicsObject.CreateStaticObject(
136          leveys, korkeus, Shape.Rectangle);
137        taso.Position = paikka;
138        taso.Color = Color.Green;
139        Add(taso);
140    }
141
142    void LuoEste(Vector paikka, double leveys, double korkeus)
143    {
144        PhysicsObject este = PhysicsObject.CreateStaticObject(
145            leveys, korkeus, Shape.Star);
146        este.Position = paikka;
147        este.Color = Color.DarkMagenta;
148        este.Tag = "tahti";
149        Add(este);
150    }
151    void AsetaOhjaimet()
152    {
153        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Poistu");
154        Keyboard.Listen(Key.Right, ButtonState.Pressed, Etene, "Pelaaja 1: hyppää", pelaaja);
155        Keyboard.Listen(Key.Up, ButtonState.Pressed, Hyppy, "Pelaaja 1: Liiku", pelaaja);
156        Keyboard.Listen(Key.Down, ButtonState.Pressed, Hyppy2, "Hyppää alas", pelaaja);
157
158    }
159
160    void Etene(PhysicsObject pelaaja)
161    {
162        Vector nopeus = new Vector(200, 0);
163        pelaaja.Velocity = nopeus;
164    }
165   
166    void Hyppy(PhysicsObject pelaaja)
167    {
168        if (pelaajaIlmassa) return;
169        Vector nopeus = new Vector(0, 200);
170        pelaaja.Velocity = nopeus;
171        pelaajaIlmassa = true;
172    }
173    void PelaajaOsuiMuuriin(PhysicsObject tormaaja, PhysicsObject kohde)
174    {
175        Label tekstikentta = new Label("teksti");
176        tekstikentta.Text = "Voitit Pelin";
177        tekstikentta.Color = Color.Aqua;
178        tekstikentta.TextColor = Color.Red;
179        Add(tekstikentta);
180        tekstikentta.Font = Font.DefaultLargeBold;
181        pelaaja.Destroy();
182        LuoAikaLaskuri();
183    }
184    void PelaajaOsuiTahtiin(PhysicsObject tormaaja, PhysicsObject kohde)
185    {
186
187        pelaaja.Destroy();
188        Explosion rajahdys = new Explosion(600.0);
189        rajahdys.Position = pelaaja.Position;
190        Add(rajahdys);
191        Label tekstikentta = new Label("teksti");
192        tekstikentta.Text = "Osuit Tähteen";
193        tekstikentta.Color = Color.Yellow;
194        tekstikentta.TextColor = Color.Red;
195        tekstikentta.Font = Font.DefaultLargeBold;
196        Add(tekstikentta);
197        LuoAikaLaskuri();
198
199    }
200
201
202    void LuoTykki(Vector paikka, double leveys, double korkeus)
203    {
204        Cannon ase = new Cannon(50, 10);
205        ase.Tag = "kanuuna";
206        ase.Angle = Angle.FromDegrees(90);
207        ase.Power.DefaultValue = 9000;
208        ase.ProjectileCollision += AmmusOsuiPelaajaan;
209        ase.MaxAmmoLifetime = TimeSpan.FromSeconds(1.0);
210        ase.Position = paikka;
211        ase.AttackSound = null;
212        Add(ase);
213        Timer ampumisAjastin = new Timer();
214        ampumisAjastin.Interval = 1.2;
215        ampumisAjastin.Start();
216        ampumisAjastin.Timeout += delegate { ase.Shoot(); };
217
218    }
219
220    void AmmusOsuiPelaajaan(PhysicsObject ammus, PhysicsObject kohde)
221    {
222
223        Label tekstikentta = new Label("teksti");
224        tekstikentta.Text = "Cannon Destroyed You";
225        tekstikentta.Color = Color.Yellow;
226        tekstikentta.TextColor = Color.Red;
227        tekstikentta.Font = Font.DefaultLargeBold;
228        tekstikentta.X = Screen.Left + 0;
229        tekstikentta.Y = Screen.Top + 300;
230        Add(tekstikentta);
231        kohde.Destroy();
232        LuoAikaLaskuri();
233    }
234    void AloitaPeli2(string levelFile)
235    {
236
237
238        LataaKentta(levelFile);
239        Level.Background.CreateGradient(Color.Teal, Color.Ruby);
240        Gravity = new Vector(0, 400);
241
242        MediaPlayer.Play("Tausta2");
243
244        Surface yläreuna = Surface.CreateTop(Level);
245        yläreuna.IsVisible = false;
246        yläreuna.Tag = "reuna";
247        Add(yläreuna);
248
249        Surface oikeareuna = Surface.CreateRight(Level);
250        oikeareuna.IsVisible = false;
251        oikeareuna.Tag = "muuri";
252        Add(oikeareuna);
253        AsetaOhjaimet();
254        Camera.Follow(pelaaja);
255
256    }
257    void Hyppy2(PhysicsObject pelaaja)
258    {
259        if (pelaajaIlmassa) return;
260        Vector nopeus = new Vector(0, -200);
261        pelaaja.Velocity = nopeus;
262        pelaajaIlmassa = true;
263
264
265
266
267    }
268  void LuoAikaLaskuri()
269{
270    Timer aikaLaskuri = new Timer();
271    aikaLaskuri.Interval = 3;
272    aikaLaskuri.Timeout += delegate { Begin(); };
273    aikaLaskuri.Start(1);
274   
275}
276}
277
278
279
280
281
282
Note: See TracBrowser for help on using the repository browser.