source: 2010/31/vinekova/Tankkipeli1/Peli.cs @ 1560

Revision 1560, 1.6 KB checked in by paaaanro, 13 years ago (diff)
Line 
1using System;
2using Jypeli;
3using Jypeli.Widgets;
4using Jypeli.Assets;
5
6public class Tankkipeli : PhysicsGame
7{
8    Tank tankki;
9
10    protected override void Begin()
11    {
12        LuoKentta();
13        AsetaOhjaimet();
14
15    }
16
17    void LuoKentta()
18    {
19        Gravity = new Vector(0, -400);
20        Level.CreateBorders();
21        LuoTankki();
22        Camera.ZoomToLevel();
23    }
24
25    void LuoTankki()
26    {
27        tankki = new Tank(100, 40);
28        tankki.Y = Level.Bottom + 40;
29        Add(tankki);
30    }
31
32    void AsetaOhjaimet()
33    {
34        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
35        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
36        Keyboard.Listen(Key.Left, ButtonState.Down, Aja, "Liiku vasemmalle", tankki, 1.0);
37        Keyboard.Listen(Key.Right, ButtonState.Down, Aja, "Liiku oikealle", tankki, -1.0);
38        Keyboard.Listen(Key.Up, ButtonState.Down, KaannaPutkea, "Käännä putkea vastapäivään", tankki, Angle.Degrees(1));
39        Keyboard.Listen(Key.Down, ButtonState.Down, KaannaPutkea, "Käännä putkea myötäpäivään", tankki, Angle.Degrees(-1));
40
41
42       
43    }
44
45    void Aja(Tank t, double vaanto)
46    {
47        t.Accelerate(vaanto);
48    }
49    void KaannaPutkea(Tank t, Angle kaanto)
50    {
51        t.Cannon.Angle += kaanto;
52    }
53
54    void KuulaOsuu(PhysicsObject kuula, PhysicsObject toinen)
55    {
56        kuula.Destroy();
57        Explosion rajahdys = new Explosion(40);
58        rajahdys.Position = kuula.Position;
59        Add(rajahdys);
60    }
61
62}
Note: See TracBrowser for help on using the repository browser.