1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | public class Lentokone : PhysicsGame |
---|
10 | { |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | //Image pommi = LoadImage("pommi"); |
---|
15 | |
---|
16 | Image maisema = LoadImage("havutausta"); |
---|
17 | Image havusauruskuva = LoadImage("havusauruskuva"); |
---|
18 | Vector nopeusYlos = new Vector(0, 1000); |
---|
19 | Vector nopeusAlas = new Vector(0, -1000); |
---|
20 | PhysicsObject pelaaja; |
---|
21 | //PhysicsObject pommi; |
---|
22 | |
---|
23 | |
---|
24 | private Animation sauruksenLento; |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | public override void Begin() |
---|
29 | { |
---|
30 | sauruksenLento = LoadAnimation("animaatio"); |
---|
31 | Level.Width = 1920; |
---|
32 | Level.Height = 1080; |
---|
33 | //SetWindowSize(1024, 800, false); |
---|
34 | |
---|
35 | Gravity = new Vector(0.0, -500); |
---|
36 | //MediaPlayer.Play(" |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | //kissat on koiria |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | LuoKentta(); |
---|
46 | LuoPelaaja(); |
---|
47 | |
---|
48 | pelaaja.Animation = sauruksenLento; |
---|
49 | pelaaja.Animation.Start(); |
---|
50 | pelaaja.Animation.FPS = 3; |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | Camera.ZoomToLevel(); |
---|
55 | //TiputaPommi(); |
---|
56 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
57 | |
---|
58 | pelaaja.Animation = sauruksenLento; |
---|
59 | pelaaja.Animation.Start(); |
---|
60 | pelaaja.Animation.FPS = 3; |
---|
61 | |
---|
62 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
63 | |
---|
64 | Keyboard.Listen(Key.Left, ButtonState.Down, |
---|
65 | HidastaPelaajaa, null); |
---|
66 | Keyboard.Listen(Key.Right, ButtonState.Down, |
---|
67 | LiikutaPelaajaa, null, 1); |
---|
68 | Keyboard.Listen(Key.Up, ButtonState.Down, |
---|
69 | KaannaPelaajaa, null, 1.0); |
---|
70 | Keyboard.Listen(Key.Up, ButtonState.Released, |
---|
71 | KaannaPelaajaa, null, 0.0); |
---|
72 | Keyboard.Listen(Key.Down, ButtonState.Down, |
---|
73 | KaannaPelaajaa, null, -1.0); |
---|
74 | Keyboard.Listen(Key.Down, ButtonState.Released, |
---|
75 | KaannaPelaajaa, null, 0.0); |
---|
76 | Keyboard.Listen(Key.Space, ButtonState.Down, TiputaPommi, "Ammu"); |
---|
77 | } |
---|
78 | void TiputaPommi() |
---|
79 | { |
---|
80 | |
---|
81 | } |
---|
82 | void KaannaPelaajaa(double kaannos) |
---|
83 | { |
---|
84 | pelaaja.AngularVelocity = kaannos; |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | protected override void Update(Time time) |
---|
90 | { |
---|
91 | base.Update(time); |
---|
92 | if (pelaaja != null) |
---|
93 | { |
---|
94 | if (pelaaja.Position.X > Level.Right) pelaaja.Position = new Vector(Level.Left, pelaaja.Position.Y); |
---|
95 | if (pelaaja.Position.X < Level.Left) pelaaja.Position = new Vector(Level.Right, pelaaja.Position.Y); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | void HidastaPelaajaa() |
---|
100 | { |
---|
101 | pelaaja.Velocity = new Vector(pelaaja.Velocity.X * 0.95, pelaaja.Velocity.Y); |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
106 | { |
---|
107 | |
---|
108 | } |
---|
109 | void LiikutaPelaajaa(int suunta) |
---|
110 | { |
---|
111 | |
---|
112 | pelaaja.Push(Vector.FromLengthAndAngle(3000*suunta, pelaaja.Angle)); |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | void LuoKentta() |
---|
118 | { |
---|
119 | Level.Background.Image = maisema; |
---|
120 | Level.Background.FitToLevel(); |
---|
121 | Surface alareuna = new Surface(Level.Width, 30, 50, 60, 10); |
---|
122 | alareuna.Color = Color.Green; |
---|
123 | alareuna.Bottom = Level.Bottom; |
---|
124 | Add(alareuna); |
---|
125 | |
---|
126 | } |
---|
127 | void LuoPelaaja() |
---|
128 | { |
---|
129 | pelaaja = new PhysicsObject(150.0, 190.0); |
---|
130 | pelaaja.Shape = Shape.FromImage(havusauruskuva); |
---|
131 | pelaaja.Image = havusauruskuva; |
---|
132 | pelaaja.LinearDamping = 0.99; |
---|
133 | |
---|
134 | //pelaaja.MirrorImage(); |
---|
135 | Add(pelaaja); |
---|
136 | AddCollisionHandler(pelaaja, CollisionHandler.ExplodeBoth(200, true)); |
---|
137 | pelaaja.MaxVelocity = 600; |
---|
138 | Timer ajastin = new Timer(); |
---|
139 | ajastin.Interval = 0.1; |
---|
140 | ajastin.Timeout += KaannaKohtiMaata; |
---|
141 | ajastin.Start(); |
---|
142 | } |
---|
143 | |
---|
144 | void KaannaKohtiMaata() |
---|
145 | { |
---|
146 | if((pelaaja.Angle.Degrees > 70) && (pelaaja.Angle.Degrees < 110)) |
---|
147 | return; |
---|
148 | if ((pelaaja.Angle.Degrees >= 110) || (pelaaja.Angle.Degrees <= -90)) |
---|
149 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 0.4); |
---|
150 | else |
---|
151 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees - 0.4); |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | } |
---|