1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.ScreenObjects; |
---|
5 | using Jypeli.Assets; |
---|
6 | |
---|
7 | public class Peli : PhysicsGame |
---|
8 | { |
---|
9 | PhysicsObject kone1; |
---|
10 | |
---|
11 | int Pelaaja1NosteenSuunta = 1; |
---|
12 | |
---|
13 | protected override void Begin() |
---|
14 | { |
---|
15 | LuoKentta(); |
---|
16 | } |
---|
17 | |
---|
18 | void LuoKentta() |
---|
19 | { |
---|
20 | Level.BackgroundColor = Color.LightBlue; |
---|
21 | Gravity = new Vector(0.0, -50.0); |
---|
22 | Camera.ZoomToLevel(); |
---|
23 | //Level.CreateBottomBorder(); |
---|
24 | Level.CreateGround(100, 1.0, 3, Color.LightGreen); |
---|
25 | kone1 = TeeLentokone(true); |
---|
26 | TeeOhjaimet(); |
---|
27 | Add(kone1); |
---|
28 | |
---|
29 | Timer ajastin = new Timer(); |
---|
30 | ajastin.Interval = 0.1; |
---|
31 | ajastin.Trigger += PaivitaNoste; |
---|
32 | Add(ajastin); |
---|
33 | ajastin.Start(); |
---|
34 | |
---|
35 | } |
---|
36 | PhysicsObject TeeLentokone(bool ihminen) |
---|
37 | { |
---|
38 | PhysicsObject kone = new PhysicsObject(20, 7); |
---|
39 | kone.Color = Color.Black; |
---|
40 | kone.IgnoresGravity = false; |
---|
41 | kone.LinearDamping = 0.99; |
---|
42 | return kone; |
---|
43 | } |
---|
44 | |
---|
45 | void TeeOhjaimet() |
---|
46 | { |
---|
47 | Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null, kone1, 0); |
---|
48 | Keyboard.Listen(Key.Right, ButtonState.Down, KaannaPelaajaa, null, kone1, -1); |
---|
49 | Keyboard.Listen(Key.Left, ButtonState.Down, KaannaPelaajaa, null, kone1, 1); |
---|
50 | Keyboard.Listen(Key.Right, ButtonState.Up, KaannaPelaajaa, null, kone1, 0); |
---|
51 | Keyboard.Listen(Key.Left, ButtonState.Up, KaannaPelaajaa, null, kone1, 0); |
---|
52 | Keyboard.Listen(Key.Down, ButtonState.Pressed, PyoritaPelaajaa1, null, 0); |
---|
53 | } |
---|
54 | |
---|
55 | void LiikutaPelaajaa(PhysicsObject pelaaja, int nopeus) |
---|
56 | { |
---|
57 | pelaaja.Push(Vector.FromLengthAndAngle(200, kone1.Angle)); |
---|
58 | } |
---|
59 | void KaannaPelaajaa(PhysicsObject pelaaja, int nopeus) |
---|
60 | { |
---|
61 | pelaaja.AngularVelocity = nopeus; |
---|
62 | } |
---|
63 | |
---|
64 | void PaivitaNoste(Timer sender) //päivittää siipien aiheuttaman nosteen, riippuu nopeudesta |
---|
65 | { |
---|
66 | kone1.Push(Vector.FromLengthAndAngle((kone1.Velocity.Magnitude * 2), (kone1.Angle + Angle.RightAngle)* Pelaaja1NosteenSuunta)); |
---|
67 | kone1.Push(Vector.FromLengthAndAngle(10, kone1.Angle)); //tyhjäkäynti |
---|
68 | } |
---|
69 | |
---|
70 | void PyoritaPelaajaa1(int nopeus) |
---|
71 | { |
---|
72 | Pelaaja1NosteenSuunta = Pelaaja1NosteenSuunta * -1; |
---|
73 | } |
---|
74 | } |
---|