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 LeoS : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject pelaaja; |
---|
12 | bool pelaajaIlmassa = false; |
---|
13 | SoundEffect hyppyAani = LoadSoundEffect("Jump"); |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | public override void Begin() |
---|
18 | { |
---|
19 | MediaPlayer.Play("Tausta"); |
---|
20 | Alustukset(); |
---|
21 | } |
---|
22 | |
---|
23 | void Alustukset() |
---|
24 | { |
---|
25 | ClearAll(); |
---|
26 | MultiSelectWindow valikko = new MultiSelectWindow("Menu", "Read This Before\nYou Start Game", "Level 1", "Level 2", "Level 3", |
---|
27 | "Level 4", "Level 5", "Exit Game"); valikko.ItemSelected += PainettiinValikonNappia; |
---|
28 | valikko.Color = Color.Gold; |
---|
29 | valikko.DefaultCancel = -1; |
---|
30 | Add(valikko); |
---|
31 | } |
---|
32 | |
---|
33 | void AloitaPeli(string levelFile) |
---|
34 | { |
---|
35 | LataaKentta(levelFile); |
---|
36 | Level.Background.CreateGradient(Color.Teal, Color.Ruby); |
---|
37 | Gravity = new Vector(0, -400); |
---|
38 | LuoAikaLaskuri3(); |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | Surface alareuna = Surface.CreateBottom(Level); |
---|
43 | alareuna.IsVisible = false; |
---|
44 | alareuna.Tag = "reuna"; |
---|
45 | Add(alareuna); |
---|
46 | |
---|
47 | Surface oikeareuna = Surface.CreateRight(Level); |
---|
48 | oikeareuna.IsVisible = false; |
---|
49 | oikeareuna.Tag = "muuri"; |
---|
50 | Add(oikeareuna); |
---|
51 | AsetaOhjaimet(); |
---|
52 | Camera.Follow(pelaaja); |
---|
53 | } |
---|
54 | |
---|
55 | void PainettiinValikonNappia(int valinta) |
---|
56 | { |
---|
57 | switch (valinta) |
---|
58 | { |
---|
59 | case 0: |
---|
60 | Ohjeet(); |
---|
61 | break; |
---|
62 | case 1: |
---|
63 | AloitaPeli("kentta1"); |
---|
64 | break; |
---|
65 | case 2: |
---|
66 | AloitaPeli("kentta2"); |
---|
67 | break; |
---|
68 | case 3: |
---|
69 | AloitaPeli("kentta3"); |
---|
70 | break; |
---|
71 | case 4: |
---|
72 | AloitaPeli("kentta4"); |
---|
73 | break; |
---|
74 | case 5: |
---|
75 | AloitaPeli2("kentta5"); |
---|
76 | break; |
---|
77 | case 6: |
---|
78 | Exit(); |
---|
79 | break; |
---|
80 | |
---|
81 | } |
---|
82 | } |
---|
83 | void LataaKentta(string levelFile) |
---|
84 | { |
---|
85 | TileMap ruudut = TileMap.FromLevelAsset(levelFile); |
---|
86 | ruudut.SetTileMethod('P', LuoPelaaja); |
---|
87 | ruudut.SetTileMethod('#', LuoPalikka); |
---|
88 | ruudut.SetTileMethod('*', LuoEste); |
---|
89 | ruudut.SetTileMethod('T', LuoTykki); |
---|
90 | ruudut.Execute(20, 20); |
---|
91 | } |
---|
92 | |
---|
93 | void LuoPelaaja(Vector paikka, double leveys, double korkeus) |
---|
94 | { |
---|
95 | pelaaja = new PhysicsObject(leveys, korkeus); |
---|
96 | pelaaja.Shape = Shape.Hexagon; |
---|
97 | pelaaja.Color = Color.HotPink; |
---|
98 | pelaaja.Position = paikka; |
---|
99 | pelaaja.Mass = 10; |
---|
100 | AddCollisionHandler(pelaaja, delegate(PhysicsObject p, PhysicsObject o) { pelaajaIlmassa = false; }); |
---|
101 | AddCollisionHandler(pelaaja, "reuna", PelaajaOsuiReunaan); |
---|
102 | AddCollisionHandler(pelaaja, "muuri", PelaajaOsuiMuuriin); |
---|
103 | AddCollisionHandler(pelaaja, "tahti", PelaajaOsuiTahtiin); |
---|
104 | pelaaja.Restitution = 100.00; |
---|
105 | pelaaja.Tag = "pelaaja"; |
---|
106 | Add(pelaaja); |
---|
107 | } |
---|
108 | |
---|
109 | void PelaajaOsuiReunaan(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
110 | { |
---|
111 | tormaaja.Destroy(); |
---|
112 | Explosion rajahdys = new Explosion(500.0); |
---|
113 | rajahdys.Position = pelaaja.Position; |
---|
114 | Add(rajahdys); |
---|
115 | Label tekstikentta = new Label("teksti"); |
---|
116 | tekstikentta.Text = "You Have Detonated"; |
---|
117 | tekstikentta.TextColor = Color.Black; |
---|
118 | Add(tekstikentta); |
---|
119 | tekstikentta.Font = Font.DefaultLarge; |
---|
120 | LuoAikaLaskuri(); |
---|
121 | } |
---|
122 | |
---|
123 | void LuoPalikka(Vector paikka, double leveys, double korkeus) |
---|
124 | { |
---|
125 | PhysicsObject taso = PhysicsObject.CreateStaticObject( |
---|
126 | leveys, korkeus, Shape.Rectangle); |
---|
127 | taso.Position = paikka; |
---|
128 | taso.Color = Color.Green; |
---|
129 | Add(taso); |
---|
130 | } |
---|
131 | |
---|
132 | void LuoEste(Vector paikka, double leveys, double korkeus) |
---|
133 | { |
---|
134 | PhysicsObject este = PhysicsObject.CreateStaticObject( |
---|
135 | leveys, korkeus, Shape.Star); |
---|
136 | este.Position = paikka; |
---|
137 | este.Color = Color.DarkMagenta; |
---|
138 | este.Tag = "tahti"; |
---|
139 | Add(este); |
---|
140 | } |
---|
141 | |
---|
142 | void AsetaOhjaimet() |
---|
143 | { |
---|
144 | Keyboard.Listen(Key.Escape, ButtonState.Down, Alustukset, "Poistu"); |
---|
145 | Keyboard.Listen(Key.Right, ButtonState.Pressed, Etene, "Pelaaja 1: hyppää", pelaaja); |
---|
146 | Keyboard.Listen(Key.Up, ButtonState.Pressed, Hyppy, "Pelaaja 1: Liiku", pelaaja); |
---|
147 | Keyboard.Listen(Key.Down, ButtonState.Pressed, Hyppy2, "Hyppää alas", pelaaja); |
---|
148 | } |
---|
149 | |
---|
150 | void Etene(PhysicsObject pelaaja) |
---|
151 | { |
---|
152 | Vector nopeus = new Vector(200, 0); |
---|
153 | pelaaja.Velocity = nopeus; |
---|
154 | } |
---|
155 | |
---|
156 | void Hyppy(PhysicsObject pelaaja) |
---|
157 | { |
---|
158 | if (pelaajaIlmassa) return; |
---|
159 | Vector nopeus = new Vector(0, 200); |
---|
160 | pelaaja.Velocity = nopeus; |
---|
161 | pelaajaIlmassa = true; |
---|
162 | hyppyAani.Play(); |
---|
163 | |
---|
164 | } |
---|
165 | void PelaajaOsuiMuuriin(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
166 | { |
---|
167 | Label tekstikentta = new Label("teksti"); |
---|
168 | tekstikentta.Text = "the End of Map Reached"; |
---|
169 | tekstikentta.Color = Color.Aqua; |
---|
170 | tekstikentta.TextColor = Color.Red; |
---|
171 | Add(tekstikentta); |
---|
172 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
173 | pelaaja.Destroy(); |
---|
174 | LuoAikaLaskuri(); |
---|
175 | } |
---|
176 | void PelaajaOsuiTahtiin(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
177 | { |
---|
178 | |
---|
179 | pelaaja.Destroy(); |
---|
180 | Explosion rajahdys = new Explosion(600.0); |
---|
181 | rajahdys.Position = pelaaja.Position; |
---|
182 | Add(rajahdys); |
---|
183 | Label tekstikentta = new Label("teksti"); |
---|
184 | tekstikentta.Text = "You Hit a Star"; |
---|
185 | tekstikentta.Color = Color.Yellow; |
---|
186 | tekstikentta.TextColor = Color.Red; |
---|
187 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
188 | Add(tekstikentta); |
---|
189 | LuoAikaLaskuri(); |
---|
190 | |
---|
191 | } |
---|
192 | |
---|
193 | void LuoTykki(Vector paikka, double leveys, double korkeus) |
---|
194 | { |
---|
195 | Cannon ase = new Cannon(50, 10); |
---|
196 | ase.Tag = "kanuuna"; |
---|
197 | ase.Angle = Angle.FromDegrees(90); |
---|
198 | ase.Power.DefaultValue = 9000; |
---|
199 | ase.ProjectileCollision += AmmusOsuiPelaajaan; |
---|
200 | ase.MaxAmmoLifetime = TimeSpan.FromSeconds(1.0); |
---|
201 | ase.Position = paikka; |
---|
202 | ase.AttackSound = null; |
---|
203 | Add(ase); |
---|
204 | Timer ampumisAjastin = new Timer(); |
---|
205 | ampumisAjastin.Interval = 1.2; |
---|
206 | ampumisAjastin.Start(); |
---|
207 | ampumisAjastin.Timeout += delegate { ase.Shoot(); }; |
---|
208 | } |
---|
209 | |
---|
210 | void AmmusOsuiPelaajaan(PhysicsObject ammus, PhysicsObject kohde) |
---|
211 | { |
---|
212 | |
---|
213 | Label tekstikentta = new Label("teksti"); |
---|
214 | tekstikentta.Text = "Cannon Destroyed You"; |
---|
215 | tekstikentta.Color = Color.Yellow; |
---|
216 | tekstikentta.TextColor = Color.Red; |
---|
217 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
218 | Add(tekstikentta); |
---|
219 | kohde.Destroy(); |
---|
220 | Explosion rajahdys = new Explosion(600.0); |
---|
221 | rajahdys.Position = pelaaja.Position; |
---|
222 | Add(rajahdys); |
---|
223 | LuoAikaLaskuri(); |
---|
224 | } |
---|
225 | void AloitaPeli2(string levelFile) |
---|
226 | { |
---|
227 | LataaKentta(levelFile); |
---|
228 | Level.Background.CreateGradient(Color.Teal, Color.Ruby); |
---|
229 | Gravity = new Vector(0, 400); |
---|
230 | |
---|
231 | Surface yläreuna = Surface.CreateTop(Level); |
---|
232 | yläreuna.IsVisible = false; |
---|
233 | yläreuna.Tag = "reuna"; |
---|
234 | Add(yläreuna); |
---|
235 | |
---|
236 | Surface oikeareuna = Surface.CreateRight(Level); |
---|
237 | oikeareuna.IsVisible = false; |
---|
238 | oikeareuna.Color = Color.Ultramarine; |
---|
239 | oikeareuna.Tag = "muuri"; |
---|
240 | Add(oikeareuna); |
---|
241 | AsetaOhjaimet(); |
---|
242 | Camera.Follow(pelaaja); |
---|
243 | LuoAikaLaskuri3(); |
---|
244 | |
---|
245 | } |
---|
246 | void Hyppy2(PhysicsObject pelaaja) |
---|
247 | { |
---|
248 | if (pelaajaIlmassa) return; |
---|
249 | Vector nopeus = new Vector(0, -200); |
---|
250 | pelaaja.Velocity = nopeus; |
---|
251 | pelaajaIlmassa = true; |
---|
252 | hyppyAani.Play(); |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | } |
---|
257 | void LuoAikaLaskuri() |
---|
258 | { |
---|
259 | Timer aikaLaskuri = new Timer(); |
---|
260 | aikaLaskuri.Interval = 2.5; |
---|
261 | aikaLaskuri.Timeout += delegate { Alustukset(); }; |
---|
262 | aikaLaskuri.Start(1); |
---|
263 | } |
---|
264 | void Ohjeet() |
---|
265 | { |
---|
266 | LuoAikaLaskuri2(); |
---|
267 | |
---|
268 | Label tekstikentta = new Label("teksti"); |
---|
269 | tekstikentta.Text = "Jump with UP-Button,Move forward with RIGHT-Button and Jump down with DOWN-Button, \nyou have 2 minutes to reach the goal,if you ran out of time,\nyou will automatically return to Menu"; |
---|
270 | |
---|
271 | tekstikentta.TextColor = Color.Red; |
---|
272 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
273 | Add(tekstikentta); |
---|
274 | |
---|
275 | Label tekstikentta2 = new Label("teksti"); |
---|
276 | tekstikentta2.Text = "This screen is readable about 5 seconds"; |
---|
277 | tekstikentta2.TextColor = Color.Yellow; |
---|
278 | tekstikentta2.Font = Font.DefaultLargeBold; |
---|
279 | tekstikentta2.X = 0.0; |
---|
280 | tekstikentta2.Y = -80.0; |
---|
281 | Add(tekstikentta2); |
---|
282 | } |
---|
283 | void LuoAikaLaskuri2() |
---|
284 | { |
---|
285 | Timer aikaLaskuri = new Timer(); |
---|
286 | aikaLaskuri.Interval = 5; |
---|
287 | aikaLaskuri.Timeout += delegate { Alustukset(); }; |
---|
288 | aikaLaskuri.Start(); |
---|
289 | |
---|
290 | } |
---|
291 | void LuoAikaLaskuri3() |
---|
292 | { |
---|
293 | Timer aikaLaskuri = new Timer(); |
---|
294 | aikaLaskuri.Interval = 120; |
---|
295 | aikaLaskuri.Timeout += delegate { AikaLoppui(); }; |
---|
296 | aikaLaskuri.Start(); |
---|
297 | Label aikaKentta = new Label(); |
---|
298 | aikaKentta.TextColor = Color.Red; |
---|
299 | aikaKentta.Color = Color.Yellow; |
---|
300 | aikaKentta.X = 0.0; |
---|
301 | aikaKentta.Y = -400.0; |
---|
302 | aikaKentta.BindTo(aikaLaskuri.SecondCounter); |
---|
303 | Add(aikaKentta); |
---|
304 | |
---|
305 | } |
---|
306 | void AikaLoppui() |
---|
307 | { |
---|
308 | ClearAll(); |
---|
309 | Label tekstikentta3 = new Label("teksti"); |
---|
310 | tekstikentta3.Text = "You are too slow"; |
---|
311 | tekstikentta3.TextColor = Color.Silver; |
---|
312 | Add(tekstikentta3); |
---|
313 | LuoAikaLaskuri4(); |
---|
314 | } |
---|
315 | void LuoAikaLaskuri4() |
---|
316 | { |
---|
317 | Timer aikaLaskuri = new Timer(); |
---|
318 | aikaLaskuri.Interval = 2; |
---|
319 | aikaLaskuri.Timeout += delegate { Alustukset(); }; |
---|
320 | aikaLaskuri.Start(); |
---|
321 | } |
---|
322 | |
---|
323 | |
---|
324 | |
---|
325 | } |
---|
326 | |
---|
327 | |
---|
328 | |
---|
329 | |
---|
330 | |
---|