source: 2013/30/VilleF/Lentokone/Lentokone/Lentokone/Lentokone.cs @ 4652

Revision 4652, 9.5 KB checked in by viosfilp, 10 years ago (diff)

Talletus.

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Lentokone : PhysicsGame
10{
11    private Animation rasa;
12
13    private Animation sauruksenLento;
14    private Animation juusto;
15    private Animation miesa;
16    //IntMeter Pisteaskuri;
17    Image ukkeliPi = LoadImage("ukkeli");
18    Image pommik = LoadImage("pommi");
19    Image maisema = LoadImage("havutausta");
20    Image havusaurus = LoadImage("havusauruskuva");
21    Vector nopeusYlos = new Vector(0, 1000);
22    Vector nopeusAlas = new Vector(0, -1000);
23    PhysicsObject pelaaja;
24    PhysicsObject pommi;
25    PhysicsObject Rasa;
26
27    Timer komboLaskurinAjastin;
28
29    IntMeter pisteLaskuri;
30    IntMeter KomboLaskuri;
31
32
33    public override void Begin()
34    {
35        Label tekstikentta = new Label("Havupommitus V 0.1");
36        tekstikentta.X = Screen.Left + 105;
37        tekstikentta.Y = Screen.Top - 10;
38        Add(tekstikentta);
39        LuoPistelaskuri();
40        miesa = LoadAnimation("blingbling");
41        juusto = LoadAnimation("ukkeli");
42        sauruksenLento = LoadAnimation("animaatio");
43        rasa = LoadAnimation("rasanen");
44
45        Level.Width = 1920;
46        Level.Height = 1080;
47        Gravity = new Vector(0.0, -500);
48        //MediaPl-ayer.Play("
49        LuoKomboLaskuri();
50        LuoPelaaja();
51        LuoKentta();
52        LisaaVihollinen();
53        LisaaVihollinen();
54        pelaaja.Animation = sauruksenLento;
55        pelaaja.Animation.Start();
56        pelaaja.Animation.FPS = 3;
57        Camera.ZoomToLevel();
58        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
59        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
60        Keyboard.Listen(Key.Left, ButtonState.Down, HidastaPelaajaa, null);
61        Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, 1);
62        Keyboard.Listen(Key.Up, ButtonState.Down, KaannaPelaajaa, null, 3.0);
63        Keyboard.Listen(Key.Up, ButtonState.Released, KaannaPelaajaa, null, 0.0);
64        Keyboard.Listen(Key.Down, ButtonState.Down, KaannaPelaajaa, null, -3.0);
65        Keyboard.Listen(Key.Down, ButtonState.Released, KaannaPelaajaa, null, 0.0);
66        Keyboard.Listen(Key.Space, ButtonState.Released, TiputaPommi, "Ammu");
67        Keyboard.Listen(Key.R, ButtonState.Released, LuoPelaaja, "Ammu");
68        Keyboard.Listen(Key.V, ButtonState.Released, LisaaVihollinen, "Ammu");
69        Keyboard.Listen(Key.P, ButtonState.Pressed, Pause, "Pysäyttää pelin");
70
71        Keyboard.Listen(Key.B, ButtonState.Released, tiputamuu, "Pysäyttää pelin");
72    }
73    void tiputamuu()
74    {
75
76        Rasa = new PhysicsObject(100, 100);
77        //pommi.Shape = Shape.FromImage("pommik");
78        Rasa.Position = pelaaja.Position;
79        Rasa.Animation = rasa;
80        Rasa.Animation.Start();
81        Rasa.Animation.FPS = 3;
82        Add(Rasa);
83       
84    }
85    void LuoPistelaskuri()
86    {
87        pisteLaskuri = new IntMeter(0);
88
89        Label pisteNaytto = new Label();
90        pisteNaytto.X = Screen.Right - 100;
91        pisteNaytto.Y = Screen.Top - 100;
92        pisteNaytto.TextColor = Color.Green;
93        //pisteNaytto.Color = Color.White;
94        pisteNaytto.IntFormatString = "Pisteitä: {0:D1}";
95        pisteNaytto.BindTo(pisteLaskuri);
96        Add(pisteNaytto);
97    }
98    void LuoKomboLaskuri()
99    {
100        KomboLaskuri = new IntMeter(0);
101
102        Label komboNaytto = new Label();
103        komboNaytto.X = Screen.Right - 200;
104        komboNaytto.Y = Screen.Top - 200;
105        komboNaytto.TextColor = Color.Green;
106        //pisteNaytto.Color = Color.White;
107        komboNaytto.IntFormatString = "COMBO: {0:D1}";
108        komboNaytto.BindTo(KomboLaskuri);
109        Add(komboNaytto);
110
111        komboLaskurinAjastin = new Timer();
112        komboLaskurinAjastin.Interval = 5;
113        komboLaskurinAjastin.Timeout += delegate { KomboLaskuri.Reset(); };
114        komboLaskurinAjastin.Start();
115
116        KomboLaskuri.Changed += delegate { Kombot(); };
117
118
119
120
121    }
122    void Kombot()
123    {
124        if (KomboLaskuri.Value == 3)
125        {
126            Label tekstikentta = new Label("kombo");
127            Add(tekstikentta);
128            //   PommiOsuu(100);
129
130        }
131
132        if (KomboLaskuri.Value > 6) { }
133
134
135    }
136
137    void LisaaVihollinen()
138    {
139        int n = 0;
140        while (n < 10)
141        {
142
143
144            double x = RandomGen.NextDouble(Level.Right, Level.Left);
145            PhysicsObject ukkeli1 = new PhysicsObject(40, 60);
146            //ukkeli1.Shape = Shape.FromImage("ukkeliP");
147            ukkeli1.Animation = RandomGen.SelectOne(juusto, miesa);
148            ukkeli1.Animation.Start();
149            ukkeli1.Animation.FPS = 5;
150            ukkeli1.Tag = "vihollinen";
151            //PhysicsObject mies = new PhysicsObject(40, 60);
152            //mies.Animation = miesa;
153            //mies.Animation.Start();
154            //mies.Animation.FPS = 4;
155            //mies.Tag = "vihollinen";
156            ukkeli1.X = x;
157            //mies.X = x;
158            ukkeli1.Y = Level.Bottom + 80;
159            //mies.Y = Level.Bottom + 80;
160
161            Add(ukkeli1);
162
163            //Add(RandomGen.SelectOne (mies, ukkeli1));
164            n++;
165
166            Timer ajastin = new Timer();
167            ajastin.Interval = RandomGen.NextDouble(0.2, 2);
168            ajastin.Timeout += delegate
169            {
170
171                ukkeli1.Velocity = new Vector(RandomGen.SelectOne(-200, 200), 0);
172            };
173            ajastin.Start();
174        }
175    }
176
177    void TiputaPommi()
178    {
179
180        pommi = new PhysicsObject(50, 50);
181        //pommi.Shape = Shape.FromImage("pommik");
182        pommi.Image = pommik;
183        pommi.Position = pelaaja.Position;
184
185        pommi.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup;
186
187
188        Add(pommi);
189
190        AddCollisionHandler(pommi, PommiOsuu);
191    }
192
193    void PommiOsuu(PhysicsObject pommi, PhysicsObject kohde)
194    {
195        //Int k = 0;
196
197        if (kohde.Tag.Equals("vihollinen"))
198        {
199            kohde.Destroy();
200            pisteLaskuri.Value += 1;
201            KomboLaskuri.Value += 1;
202            komboLaskurinAjastin.Reset();
203
204        }
205        if (KomboLaskuri > 3)
206        {
207
208            Explosion e = new Explosion(600);
209            e.Position = pommi.Position;
210            pommi.Destroy();
211            Add(e);
212            e.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) { if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); };
213        }
214        else
215        {
216            Explosion e = new Explosion(60);
217            e.Position = pommi.Position;
218            pommi.Destroy();
219            Add(e);
220            e.ShockwaveReachesObject += delegate(IPhysicsObject rKohde, Vector v) { if (rKohde.Tag.Equals("vihollinen")) rKohde.Destroy(); };
221            //pisteet++;}
222        }
223
224    }
225    void Rajahdys()
226    {
227
228    }
229
230    void KaannaPelaajaa(double kaannos)
231    {
232        pelaaja.AngularVelocity = kaannos;
233    }
234
235
236
237    protected override void Update(Time time)
238    {
239        base.Update(time);
240        if (pelaaja != null)
241        {
242            if (pelaaja.Position.X > Level.Right) pelaaja.Position = new Vector(Level.Left, pelaaja.Position.Y);
243            if (pelaaja.Position.X < Level.Left) pelaaja.Position = new Vector(Level.Right, pelaaja.Position.Y);
244        }
245    }
246
247    void HidastaPelaajaa()
248    {
249        pelaaja.Velocity = new Vector(pelaaja.Velocity.X * 0.95, pelaaja.Velocity.Y);
250
251    }
252
253    void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde)
254    {
255
256    }
257    void LiikutaPelaajaa(int suunta)
258    {
259        pelaaja.Push(Vector.FromLengthAndAngle(3000 * suunta, pelaaja.Angle));
260    }
261
262
263    void LuoKentta()
264    {
265        Level.Background.Image = maisema;
266        Level.Background.FitToLevel();
267        Surface alareuna = new Surface(Level.Width, 50, 20, 60, 60);
268        alareuna.Color = Color.Green;
269        alareuna.Bottom = Level.Bottom;
270        Add(alareuna);
271
272        PhysicsObject oikeaReuna = Level.CreateRightBorder();
273        oikeaReuna.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup;
274
275        PhysicsObject vasenReuna = Level.CreateLeftBorder();
276        vasenReuna.CollisionIgnoreGroup = pelaaja.CollisionIgnoreGroup;
277
278
279    }
280
281
282
283
284
285
286    void LuoPelaaja()
287    {
288        pelaaja = new PhysicsObject(100.0, 120.0);
289        pelaaja.Shape = Shape.FromImage(havusaurus);
290        pelaaja.Image = havusaurus;
291        pelaaja.LinearDamping = 0.99;
292        pelaaja.CollisionIgnoreGroup = 2;
293        //pelaaja.MirrorImage();
294        pelaaja.Animation = sauruksenLento;
295        pelaaja.Animation.Start();
296        pelaaja.Animation.FPS = 3;
297        Add(pelaaja);
298        AddCollisionHandler(pelaaja, CollisionHandler.ExplodeObject(200, true));
299        AddCollisionHandler(pelaaja, "vihollinen", CollisionHandler.ExplodeTarget(50, true));
300        pelaaja.MaxVelocity = 600;
301        Timer ajastin = new Timer();
302        ajastin.Interval = 0.1;
303        ajastin.Timeout += KaannaKohtiMaata;
304        ajastin.Start();
305        pisteLaskuri.Value = -10;
306    }
307
308    void KaannaKohtiMaata()
309    {
310        if ((pelaaja.Angle.Degrees > 70) && (pelaaja.Angle.Degrees < 110))
311            return;
312        if ((pelaaja.Angle.Degrees >= 110) || (pelaaja.Angle.Degrees <= -90))
313            pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 0.4);
314        else
315            pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees - 0.4);
316    }
317
318
319}
Note: See TracBrowser for help on using the repository browser.