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 PhysicsBall : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject Pelaaja4; |
---|
12 | PhysicsObject Tynnyri6; |
---|
13 | PhysicsObject este4; |
---|
14 | PhysicsObject aloitus1; |
---|
15 | PhysicsObject este3; |
---|
16 | PhysicsObject Pelaaja3; |
---|
17 | PhysicsObject este2; |
---|
18 | PhysicsObject Tynnyri1; |
---|
19 | PhysicsObject Este1; |
---|
20 | Image BLOCK = LoadImage("Este"); |
---|
21 | PhysicsObject Este; |
---|
22 | PhysicsObject Aloitus; |
---|
23 | Image Barrel = LoadImage("Kohde"); |
---|
24 | PhysicsObject Tynnyri; |
---|
25 | PhysicsObject Lava2; |
---|
26 | PhysicsObject Lava; |
---|
27 | Image Kuva = LoadImage("Tausta"); |
---|
28 | Image Laava = LoadImage("Lava"); |
---|
29 | PhysicsObject Pelaaja; |
---|
30 | PhysicsObject Maali; |
---|
31 | PhysicsObject Nappula; |
---|
32 | PhysicsObject Katoava; |
---|
33 | Image Pallo = LoadImage("Ball"); |
---|
34 | Image button = LoadImage("Nappula"); |
---|
35 | Image Tausta = LoadImage("Tausta"); |
---|
36 | Image Sahko = LoadImage("Warning"); |
---|
37 | Image Tausta2 = LoadImage("Tausta42"); |
---|
38 | SoundEffect maaliAani = LoadSoundEffect("maali"); |
---|
39 | Image startti = LoadImage("Aloitus1"); |
---|
40 | |
---|
41 | |
---|
42 | public override void Begin() |
---|
43 | { |
---|
44 | |
---|
45 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, |
---|
46 | LiikutaPelaajaa, null, new Vector(-300, 0), Pelaaja); |
---|
47 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, |
---|
48 | LiikutaPelaajaa, null, new Vector(300, 0), Pelaaja); |
---|
49 | ControllerOne.Listen(Button.A, ButtonState.Down, |
---|
50 | MuutaPainovoima, null); |
---|
51 | |
---|
52 | Level.Background.Image = Kuva; |
---|
53 | LuoKatoava(); |
---|
54 | |
---|
55 | LuoMaali(); |
---|
56 | AloitaKentta(); |
---|
57 | Pelaaja = new PhysicsObject(100, 100); |
---|
58 | Pelaaja.X = -400; |
---|
59 | Pelaaja.Y = -350; |
---|
60 | Pelaaja.Shape = Shape.Circle; |
---|
61 | Pelaaja.Color = Color.Lime; |
---|
62 | |
---|
63 | Add(Pelaaja); |
---|
64 | AddCollisionHandler(Pelaaja, KasittelePallonTormays); |
---|
65 | Level.CreateBorders(); |
---|
66 | Pelaaja.KineticFriction = 0.8; |
---|
67 | Pelaaja.Restitution = 0.2; |
---|
68 | Pelaaja.Image = Pallo; |
---|
69 | |
---|
70 | Gravity = new Vector(0, -700); |
---|
71 | Keyboard.Listen(Key.Space, ButtonState.Pressed, |
---|
72 | MuutaPainovoima, null); |
---|
73 | Keyboard.Listen(Key.A, ButtonState.Down, |
---|
74 | LiikutaPelaajaa, null, new Vector(-300, 0), Pelaaja); |
---|
75 | Keyboard.Listen(Key.D, ButtonState.Down, |
---|
76 | LiikutaPelaajaa, null, new Vector(300, 0), Pelaaja); |
---|
77 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
78 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
79 | Level.BackgroundColor = Color.Gray; |
---|
80 | Camera.Follow(Pelaaja); |
---|
81 | } |
---|
82 | |
---|
83 | void AloitaKentta() |
---|
84 | { |
---|
85 | |
---|
86 | } |
---|
87 | void LiikutaPelaajaa(Vector vektori, PhysicsObject pelaaja) |
---|
88 | { |
---|
89 | pelaaja.Push(vektori); |
---|
90 | } |
---|
91 | Object LuoMaali() |
---|
92 | { |
---|
93 | |
---|
94 | PhysicsObject Nappula = PhysicsObject.CreateStaticObject(50, 30); |
---|
95 | Nappula.X = -250; |
---|
96 | Nappula.Y = 330; |
---|
97 | Nappula.Color = Color.Red; |
---|
98 | PhysicsObject Maali = PhysicsObject.CreateStaticObject(400.0, 400.0); |
---|
99 | Maali.Image = Sahko; |
---|
100 | Maali.Shape = Shape.Rectangle; |
---|
101 | Maali.X = Level.Right; |
---|
102 | Maali.Y = Level.Bottom; |
---|
103 | Add(Maali); |
---|
104 | PhysicsObject Tynnyri = PhysicsObject.CreateStaticObject(100, 100); |
---|
105 | Tynnyri.X = 240; |
---|
106 | Tynnyri.Y = 75; |
---|
107 | Tynnyri.Tag = "tynnyri"; |
---|
108 | Add(Tynnyri); |
---|
109 | Tynnyri.Image = Barrel; |
---|
110 | |
---|
111 | return Maali; |
---|
112 | Nappula.Image = button; |
---|
113 | } |
---|
114 | void MuutaPainovoima() |
---|
115 | { |
---|
116 | Gravity = Gravity * (-1); |
---|
117 | if (Level.Background.Image == Tausta2) |
---|
118 | { |
---|
119 | Level.Background.Image = Tausta; |
---|
120 | } |
---|
121 | else |
---|
122 | Level.Background.Image = Tausta2; |
---|
123 | |
---|
124 | ControllerOne.Vibrate(0.5, 0.5, 0.0, 0.0, 0.1); |
---|
125 | } |
---|
126 | Object LuoKatoava() |
---|
127 | { |
---|
128 | PhysicsObject Katoava = PhysicsObject.CreateStaticObject(100, 50); |
---|
129 | Katoava.X = 240; |
---|
130 | Katoava.Y = 0; |
---|
131 | Katoava.Color = Color.Black; |
---|
132 | Add(Katoava); |
---|
133 | return Katoava; |
---|
134 | Katoava.Shape = Shape.Rectangle; |
---|
135 | } |
---|
136 | void KasittelePallonTormays(PhysicsObject Pelaaja, PhysicsObject kohde) |
---|
137 | { |
---|
138 | if (kohde == Nappula) |
---|
139 | { |
---|
140 | MessageDisplay.Add("Bump!"); |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | if (kohde.Tag.ToString() == "tynnyri") |
---|
145 | { |
---|
146 | |
---|
147 | kohde.Destroy(); |
---|
148 | MessageDisplay.Add("Tuhosit tynnyrin!"); |
---|
149 | maaliAani.Play(); |
---|
150 | |
---|
151 | PhysicsObject Pelaaja1 = new PhysicsObject(50, 50); |
---|
152 | Pelaaja1.X = -400; |
---|
153 | Pelaaja1.Y = -150; |
---|
154 | Pelaaja.Destroy(); |
---|
155 | Add(Pelaaja1); |
---|
156 | Pelaaja1.Image = Pallo; |
---|
157 | |
---|
158 | |
---|
159 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, |
---|
160 | LiikutaPelaajaa, null, new Vector(-300, 0), Pelaaja1); |
---|
161 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, |
---|
162 | LiikutaPelaajaa, null, new Vector(300, 0), Pelaaja1); |
---|
163 | |
---|
164 | Keyboard.Listen(Key.A, ButtonState.Down, |
---|
165 | LiikutaPelaajaa1, null, new Vector(-300, 0), Pelaaja1); |
---|
166 | Keyboard.Listen(Key.D, ButtonState.Down, |
---|
167 | LiikutaPelaajaa1, null, new Vector(300, 0), Pelaaja1); |
---|
168 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
169 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
170 | Level.BackgroundColor = Color.Gray; |
---|
171 | Camera.Follow(Pelaaja1); |
---|
172 | Camera.ZoomFactor = 1.0; |
---|
173 | AddCollisionHandler(Pelaaja1, KasittelePallonTormays2); |
---|
174 | AddCollisionHandler(Pelaaja1, KasittelePallonTormays3); |
---|
175 | |
---|
176 | Level2(); |
---|
177 | MessageDisplay.Add("Level2"); |
---|
178 | |
---|
179 | |
---|
180 | } |
---|
181 | |
---|
182 | } |
---|
183 | void LiikutaPelaajaa1(Vector vektori, PhysicsObject pelaaja) |
---|
184 | { |
---|
185 | pelaaja.Push(vektori); |
---|
186 | |
---|
187 | } |
---|
188 | void Level2() |
---|
189 | { |
---|
190 | Level.CreateBottomBorder(); |
---|
191 | PhysicsObject Lava = PhysicsObject.CreateStaticObject(800, 100); |
---|
192 | Lava.X = -100; |
---|
193 | Lava.Y = -300; |
---|
194 | Add(Lava); |
---|
195 | Lava.Image = Laava; |
---|
196 | Lava.Tag = "Magma"; |
---|
197 | |
---|
198 | PhysicsObject Aloitus = PhysicsObject.CreateStaticObject(200, 50); |
---|
199 | Add(Aloitus); |
---|
200 | Aloitus.X = -400; |
---|
201 | Aloitus.Y = -200; |
---|
202 | Aloitus.Image = startti; |
---|
203 | |
---|
204 | |
---|
205 | PhysicsObject Este = PhysicsObject.CreateStaticObject(50, 400); |
---|
206 | Add(Este); |
---|
207 | Este.X = -200; |
---|
208 | Este.Y = -200; |
---|
209 | Este.Image = BLOCK; |
---|
210 | Este.Tag = "ESTE1"; |
---|
211 | |
---|
212 | PhysicsObject Este1 = PhysicsObject.CreateStaticObject(700, 50); |
---|
213 | Add(Este1); |
---|
214 | Este1.X = -150; |
---|
215 | Este1.Y = 200; |
---|
216 | Este1.Image = BLOCK; |
---|
217 | Este1.Tag = "ESTE1"; |
---|
218 | |
---|
219 | PhysicsObject Tynnyri1 = PhysicsObject.CreateStaticObject(100, 100); |
---|
220 | Tynnyri1.X = 240; |
---|
221 | Tynnyri1.Y = 75; |
---|
222 | Tynnyri1.Tag = "tynnyri1"; |
---|
223 | Add(Tynnyri1); |
---|
224 | Tynnyri1.Image = Barrel; |
---|
225 | |
---|
226 | PhysicsObject este2 = PhysicsObject.CreateStaticObject(50, 450); |
---|
227 | este2.X = 200; |
---|
228 | este2.Y = 140; |
---|
229 | Add(este2); |
---|
230 | este2.Image = BLOCK; |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | } |
---|
236 | |
---|
237 | void KasittelePallonTormays2(PhysicsObject Pelaaja1, PhysicsObject kohde) |
---|
238 | { |
---|
239 | if (kohde.Tag.ToString() == "Magma") |
---|
240 | { |
---|
241 | Pelaaja1.X = -400; |
---|
242 | Pelaaja1.Y = -100; |
---|
243 | MessageDisplay.Add("Kuolit!"); |
---|
244 | |
---|
245 | } |
---|
246 | else if (kohde.Tag.ToString() == "ESTE1") |
---|
247 | { |
---|
248 | Pelaaja1.X = -400; |
---|
249 | Pelaaja1.Y = -100; |
---|
250 | MessageDisplay.Add("Kuolit!"); |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | } |
---|
256 | void KasittelePallonTormays3(PhysicsObject Pelaaja1, PhysicsObject kohde) |
---|
257 | { |
---|
258 | if (kohde.Tag.ToString() == "tynnyri1") |
---|
259 | { |
---|
260 | kohde.Destroy(); |
---|
261 | |
---|
262 | MessageDisplay.Add("Tuhosit Tynnyrin!"); |
---|
263 | MessageDisplay.Add("Level3"); |
---|
264 | |
---|
265 | Level3(); |
---|
266 | } |
---|
267 | } |
---|
268 | void Level3() |
---|
269 | { |
---|
270 | ClearGameObjects(); |
---|
271 | |
---|
272 | PhysicsObject Pelaaja3 = new PhysicsObject(50, 50); |
---|
273 | Camera.Follow(Pelaaja3); |
---|
274 | Add(Pelaaja3); |
---|
275 | Pelaaja3.X = -400; |
---|
276 | Pelaaja3.Y = -150; |
---|
277 | Pelaaja3.Image = Pallo; |
---|
278 | Camera.Follow(Pelaaja3); |
---|
279 | Camera.Zoom(1.0); |
---|
280 | |
---|
281 | Level.CreateBorders(); |
---|
282 | |
---|
283 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, |
---|
284 | LiikutaPelaajaa, null, new Vector(-300, 0), Pelaaja3); |
---|
285 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, |
---|
286 | LiikutaPelaajaa, null, new Vector(300, 0), Pelaaja3); |
---|
287 | |
---|
288 | Keyboard.Listen(Key.A, ButtonState.Down, |
---|
289 | LiikutaPelaajaa1, null, new Vector(-300, 0), Pelaaja3); |
---|
290 | Keyboard.Listen(Key.D, ButtonState.Down, |
---|
291 | LiikutaPelaajaa1, null, new Vector(300, 0), Pelaaja3); |
---|
292 | |
---|
293 | PhysicsObject Aloitus1 = PhysicsObject.CreateStaticObject(200, 50); |
---|
294 | Add(Aloitus1); |
---|
295 | Aloitus1.X = -400; |
---|
296 | Aloitus1.Y = -200; |
---|
297 | Aloitus1.Image = startti; |
---|
298 | |
---|
299 | PhysicsObject este5 = PhysicsObject.CreateStaticObject(1000, 50); |
---|
300 | Add(este5); |
---|
301 | este5.X = -10; |
---|
302 | este5.Y = 0; |
---|
303 | este5.Image = BLOCK; |
---|
304 | este5.Tag = "ESTE5"; |
---|
305 | |
---|
306 | PhysicsObject este3 = PhysicsObject.CreateStaticObject(40, 100); |
---|
307 | Add(este3); |
---|
308 | este3.X = -300; |
---|
309 | este3.Y = -200; |
---|
310 | este3.Image = BLOCK; |
---|
311 | este3.Tag = "ESTE3"; |
---|
312 | |
---|
313 | PhysicsObject este4 = PhysicsObject.CreateStaticObject(900, 50); |
---|
314 | Add(este4); |
---|
315 | este4.Tag = "ESTE4"; |
---|
316 | este4.X = -30; |
---|
317 | este4.Y = -250; |
---|
318 | este4.Image = BLOCK; |
---|
319 | |
---|
320 | |
---|
321 | PhysicsObject Tynnyri6 = PhysicsObject.CreateStaticObject(100, 100); |
---|
322 | Tynnyri6.X = 400; |
---|
323 | Tynnyri6.Y = -100; |
---|
324 | Tynnyri6.Tag = "tynnyri6"; |
---|
325 | Add(Tynnyri6); |
---|
326 | Tynnyri6.Image = Barrel; |
---|
327 | |
---|
328 | AddCollisionHandler(Pelaaja3, KasittelePallonTormays4); |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | } |
---|
333 | void KasittelePallonTormays4(PhysicsObject Pelaaja3, PhysicsObject kohde) |
---|
334 | { |
---|
335 | if (kohde.Tag.ToString() == "ESTE4") |
---|
336 | { |
---|
337 | Pelaaja3.X = -400; |
---|
338 | Pelaaja3.Y = -150; |
---|
339 | MessageDisplay.Add("Kuolit!"); |
---|
340 | } |
---|
341 | if (kohde.Tag.ToString() == "tynnyri6") |
---|
342 | { |
---|
343 | kohde.Destroy(); |
---|
344 | MessageDisplay.Add("Tuhosit tynnyrin!"); |
---|
345 | MessageDisplay.Add("Level4"); |
---|
346 | ClearGameObjects(); |
---|
347 | Level4(); |
---|
348 | } |
---|
349 | if (kohde.Tag.ToString() == "ESTE5") |
---|
350 | { |
---|
351 | Pelaaja3.X = -400; |
---|
352 | Pelaaja3.Y = -150; |
---|
353 | MessageDisplay.Add("Kuolit!"); |
---|
354 | } |
---|
355 | |
---|
356 | |
---|
357 | } |
---|
358 | void Level4() |
---|
359 | { |
---|
360 | |
---|
361 | Level.CreateBorders(); |
---|
362 | PhysicsObject Pelaaja4 = new PhysicsObject(30, 30); |
---|
363 | Add(Pelaaja4); |
---|
364 | Pelaaja4.X = -400; |
---|
365 | Pelaaja.Y = -150; |
---|
366 | Pelaaja4.Image = Pallo; |
---|
367 | Camera.Follow(Pelaaja4); |
---|
368 | Camera.ZoomFactor = 2.0; |
---|
369 | |
---|
370 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, |
---|
371 | LiikutaPelaajaa4, null, new Vector(-300, 0), Pelaaja4); |
---|
372 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, |
---|
373 | LiikutaPelaajaa4, null, new Vector(300, 0), Pelaaja4); |
---|
374 | |
---|
375 | Keyboard.Listen(Key.A, ButtonState.Down, |
---|
376 | LiikutaPelaajaa4, null, new Vector(-300, 0), Pelaaja4); |
---|
377 | Keyboard.Listen(Key.D, ButtonState.Down, |
---|
378 | LiikutaPelaajaa4, null, new Vector(300, 0), Pelaaja4); |
---|
379 | |
---|
380 | |
---|
381 | PhysicsObject Aloitus1 = PhysicsObject.CreateStaticObject(200, 30); |
---|
382 | Add(Aloitus1); |
---|
383 | Aloitus1.X = -400; |
---|
384 | Aloitus1.Y = -200; |
---|
385 | Aloitus1.Image = startti; |
---|
386 | |
---|
387 | PhysicsObject Lava2 = PhysicsObject.CreateStaticObject(800, 100); |
---|
388 | Lava2.X = -100; |
---|
389 | Lava2.Y = -300; |
---|
390 | Add(Lava2); |
---|
391 | Lava2.Image = Laava; |
---|
392 | Lava2.Tag = "Magma2"; |
---|
393 | |
---|
394 | |
---|
395 | |
---|
396 | } |
---|
397 | void LiikutaPelaajaa4(Vector vektori, PhysicsObject Pelaaja4) |
---|
398 | { |
---|
399 | Pelaaja4.Push(vektori); |
---|
400 | |
---|
401 | } |
---|
402 | } |
---|
403 | |
---|
404 | |
---|
405 | |
---|
406 | |
---|
407 | |
---|
408 | |
---|
409 | |
---|
410 | |
---|