1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | public class HelicopterHavoc : PhysicsGame |
---|
7 | { |
---|
8 | PhysicsObject helikopteri; |
---|
9 | Vector nopeusYlos = new Vector(0, 16000); |
---|
10 | Vector nopeusSivulle = new Vector(12000, 0); |
---|
11 | Image olionkuva = LoadImage("helikopteri"); |
---|
12 | Image olionkuvaPeilattu; |
---|
13 | |
---|
14 | |
---|
15 | AssaultRifle pyssy; |
---|
16 | |
---|
17 | |
---|
18 | protected override void Begin() |
---|
19 | { |
---|
20 | olionkuvaPeilattu = Image.Mirror(olionkuva); |
---|
21 | |
---|
22 | LuoKenttä(); |
---|
23 | LisääHelikopteri(); |
---|
24 | LisääOhjaimet(); |
---|
25 | } |
---|
26 | |
---|
27 | void LuoKenttä() |
---|
28 | { |
---|
29 | Level.CreateBorders(1.0, true); |
---|
30 | Gravity = new Vector(0.0, -500.0); |
---|
31 | |
---|
32 | } |
---|
33 | |
---|
34 | void LisääHelikopteri() |
---|
35 | { |
---|
36 | helikopteri = new PhysicsObject(300.0, 100.0); |
---|
37 | helikopteri.Mass = 3.0; |
---|
38 | helikopteri.Image = olionkuva; |
---|
39 | helikopteri.LinearDamping = 0.8; |
---|
40 | helikopteri.CanRotate = false; |
---|
41 | Add(helikopteri); |
---|
42 | |
---|
43 | pyssy = new AssaultRifle(100, 20); |
---|
44 | helikopteri.Add(pyssy); |
---|
45 | pyssy.Position = new Vector(helikopteri.X + 120, helikopteri.Y-50); |
---|
46 | pyssy.IsVisible = false; |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | void LisääOhjaimet() |
---|
54 | { |
---|
55 | Keyboard.Listen(Key.A, ButtonState.Down, LiikutaPelaajaa, null, -nopeusSivulle); |
---|
56 | Keyboard.Listen(Key.D, ButtonState.Down, LiikutaPelaajaa, null, nopeusSivulle); |
---|
57 | Keyboard.Listen(Key.W, ButtonState.Down, LiikutaPelaajaa, null, nopeusYlos); |
---|
58 | Keyboard.Listen(Key.S, ButtonState.Down, LiikutaPelaajaa, null, -nopeusYlos); |
---|
59 | Keyboard.Listen(Key.Q, ButtonState.Down, KallistaHelikopteria, null, 2.0); |
---|
60 | Keyboard.Listen(Key.E, ButtonState.Down, KallistaHelikopteria, null, -2.0); |
---|
61 | Keyboard.Listen(Key.Space, ButtonState.Down, Ammu, "Ammu"); |
---|
62 | } |
---|
63 | |
---|
64 | void Ammu() |
---|
65 | { |
---|
66 | PhysicsObject ammus = pyssy.Shoot(); |
---|
67 | if (ammus != null) |
---|
68 | { |
---|
69 | ammus.Size = new Vector(20, 4); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | void LiikutaPelaajaa(Vector vektori) |
---|
74 | { |
---|
75 | helikopteri.Push(vektori); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | protected override void Update(Time time) |
---|
84 | { |
---|
85 | if (helikopteri.Velocity.X < 0) |
---|
86 | { |
---|
87 | helikopteri.Image = olionkuvaPeilattu; |
---|
88 | } |
---|
89 | if (helikopteri.Velocity.X > 0) |
---|
90 | { |
---|
91 | helikopteri.Image = olionkuva; |
---|
92 | } |
---|
93 | base.Update(time); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | void KallistaHelikopteria(double kaanto) |
---|
98 | { |
---|
99 | helikopteri.Angle = Angle.Degrees(helikopteri.Angle.Degree + kaanto); |
---|
100 | } |
---|
101 | |
---|
102 | } |
---|