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 OK : PhysicsGame |
---|
10 | { |
---|
11 | GameObject command; //UI-ruutu, jossa pelikomennot |
---|
12 | GameObject feed; //UI-ruutu, johon tulee combat log |
---|
13 | GameObject portrait; //ruutu, jossa pelihahmon HP ja kauniit kasvot |
---|
14 | GameObject tappio; //ruutu, joka ilmaantuu pelaajan hävitessä |
---|
15 | |
---|
16 | GameObject foe1; //ruutu, jossa pahis 1 |
---|
17 | GameObject foe2; //ruutu, jossa pahis 2 |
---|
18 | GameObject foe3; //ruutu, jossa pahis 3 |
---|
19 | |
---|
20 | double textheight = -220; |
---|
21 | double textwidth = -750; |
---|
22 | |
---|
23 | GameObject inventory; //ruutu, jossa kamasi näkyvät |
---|
24 | |
---|
25 | GameObject transition; //ruutu, jolla peli menee eteenpäin |
---|
26 | GameObject voitto; //ruutu, joka tulee kun voitat pelin |
---|
27 | |
---|
28 | int vihollisNro = 1; |
---|
29 | |
---|
30 | PhysicsObject Pointer; //jolla valitaan schaibaa |
---|
31 | Timer ajastin; |
---|
32 | |
---|
33 | bool pelaajatoiminut = false; //tarkistaa, että onko pelaaja käyttänyt vuoronsa, että hän ei pääse rikkomaan peliä |
---|
34 | |
---|
35 | IntMeter goopHP; //ekan vihollisen hp |
---|
36 | IntMeter skeleHP; //tokan vihollisen hp |
---|
37 | IntMeter snekHP; //kolmannen vihollisen HP |
---|
38 | IntMeter HP; //pelaajan hp |
---|
39 | |
---|
40 | int playerdamage = 10; //pelaajan tehot |
---|
41 | int enemy1damage = 5; //ekan vihollisen tehot |
---|
42 | int enemy2damage = 20; //tokan vihollisen tehot |
---|
43 | int enemy3damage = 24; //kolmannen vihollisen tehot |
---|
44 | |
---|
45 | Label foeHP; // eka vihu |
---|
46 | Label foe2HP; //toka vihu |
---|
47 | Label playerHP; |
---|
48 | Label feedtext; |
---|
49 | |
---|
50 | Vector nopeusYlos = new Vector(0, 100); |
---|
51 | Vector nopeusAlas = new Vector(0, -100); |
---|
52 | Vector nopeusVasen = new Vector(-200, 0); |
---|
53 | Vector nopeusOikea = new Vector(200, 0); |
---|
54 | |
---|
55 | public override void Begin() |
---|
56 | { |
---|
57 | LuoAlue(); |
---|
58 | luopelaaja(); |
---|
59 | LuoHP(); |
---|
60 | Kontrollit(); |
---|
61 | |
---|
62 | |
---|
63 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
64 | } |
---|
65 | |
---|
66 | void LuoAlue() |
---|
67 | { |
---|
68 | |
---|
69 | Level.Background.Color = Color.White; |
---|
70 | |
---|
71 | command = new GameObject(450.0, 300.0); |
---|
72 | command.Shape = Shape.Rectangle; |
---|
73 | command.Color = Color.Black; |
---|
74 | command.X = 370.00; |
---|
75 | command.Y = -330.00; |
---|
76 | command.Image = LoadImage("Kökkö"); |
---|
77 | Add(command, 1); |
---|
78 | |
---|
79 | feed = new GameObject(1000.00, 300.00); |
---|
80 | feed.Shape = Shape.Rectangle; |
---|
81 | feed.Color = Color.Black; |
---|
82 | feed.X = -400.00; |
---|
83 | feed.Y = -330.00; |
---|
84 | Add(feed); |
---|
85 | |
---|
86 | feedtext = new Label(); |
---|
87 | feedtext.X = textwidth; |
---|
88 | feedtext.Y = textheight; |
---|
89 | feedtext.TextColor = Color.White; |
---|
90 | feedtext.Color = Color.Transparent; |
---|
91 | Add(feedtext, 2); |
---|
92 | |
---|
93 | |
---|
94 | portrait = new GameObject(250.00, 300.00); |
---|
95 | portrait.Shape = Shape.Rectangle; |
---|
96 | portrait.Color = Color.Black; |
---|
97 | portrait.X = 750.00; |
---|
98 | portrait.Y = -330.00; |
---|
99 | Add(portrait); |
---|
100 | |
---|
101 | foe1 = new GameObject(1800.00, 700.00); |
---|
102 | foe1.Shape = Shape.Rectangle; |
---|
103 | foe1.Color = Color.Aqua; |
---|
104 | foe1.X = -10.00; |
---|
105 | foe1.Y = 200.00; |
---|
106 | foe1.Image = LoadImage("köntsä"); |
---|
107 | Add(foe1); |
---|
108 | } |
---|
109 | |
---|
110 | PhysicsObject luopelaaja() |
---|
111 | { |
---|
112 | Pointer = new PhysicsObject(5.0, 5.0); |
---|
113 | Pointer.Color = Color.White; |
---|
114 | Pointer.X = 190.00; |
---|
115 | Pointer.Y = -220.00; |
---|
116 | Add(Pointer, 2); |
---|
117 | Pointer.IgnoresExplosions = true; |
---|
118 | return Pointer; |
---|
119 | } |
---|
120 | |
---|
121 | void LuoHP() |
---|
122 | { |
---|
123 | goopHP = new IntMeter(20); |
---|
124 | |
---|
125 | foeHP = new Label(); |
---|
126 | |
---|
127 | foeHP.X = 150.00; |
---|
128 | foeHP.Y = Screen.Top - 40.00; |
---|
129 | foeHP.TextColor = Color.Red; |
---|
130 | foeHP.Color = Color.Transparent; |
---|
131 | |
---|
132 | foeHP.BindTo(goopHP); |
---|
133 | Add(foeHP, 2); |
---|
134 | |
---|
135 | HP = new IntMeter(65); |
---|
136 | |
---|
137 | Label playerHP = new Label(); |
---|
138 | |
---|
139 | playerHP.X = 660.00; |
---|
140 | playerHP.Y = -200.00; |
---|
141 | playerHP.TextColor = Color.LightGreen; |
---|
142 | playerHP.Color = Color.Transparent; |
---|
143 | |
---|
144 | playerHP.BindTo(HP); |
---|
145 | Add(playerHP, 2); |
---|
146 | |
---|
147 | skeleHP = new IntMeter(40); |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | } |
---|
153 | void AsetaNopeus(PhysicsObject Pointer, Vector nopeus) |
---|
154 | { |
---|
155 | PlaySound("blip"); |
---|
156 | |
---|
157 | if (Pointer.Velocity.Magnitude > 0) return; |
---|
158 | |
---|
159 | Vector sijainti = Pointer.Position + nopeus; |
---|
160 | if (sijainti.Y > command.Top) return; |
---|
161 | else if (sijainti.Y < command.Bottom) return; |
---|
162 | |
---|
163 | Pointer.MoveTo(Pointer.Position + nopeus, 1000.00); |
---|
164 | |
---|
165 | } |
---|
166 | void Kontrollit() |
---|
167 | { |
---|
168 | Keyboard.Listen(Key.Down, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusAlas); |
---|
169 | //Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
170 | |
---|
171 | Keyboard.Listen(Key.Up, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusYlos); |
---|
172 | //Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
173 | |
---|
174 | |
---|
175 | Keyboard.Listen(Key.Z, ButtonState.Pressed, Valitse, null); |
---|
176 | |
---|
177 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
178 | |
---|
179 | } |
---|
180 | |
---|
181 | void Valitse() |
---|
182 | |
---|
183 | { |
---|
184 | |
---|
185 | if (pelaajatoiminut) return; |
---|
186 | pelaajatoiminut = true; |
---|
187 | if (Pointer.Y > command.Top - command.Height / 3) Attack(); |
---|
188 | else if (Pointer.Y < command.Bottom + command.Height / 3) Exit(); |
---|
189 | else Items(); |
---|
190 | } |
---|
191 | |
---|
192 | void Items() |
---|
193 | { |
---|
194 | pelaajatoiminut = false; |
---|
195 | inventory = new GameObject (450.0, 300.0); |
---|
196 | command.Shape = Shape.Rectangle; |
---|
197 | inventory.Color = Color.Black; |
---|
198 | inventory.X = 370.00; |
---|
199 | inventory.Y = -330.00; |
---|
200 | inventory.Image = LoadImage("Items"); |
---|
201 | Add(inventory); |
---|
202 | command.Destroy(); |
---|
203 | |
---|
204 | Keyboard.Listen(Key.X, ButtonState.Pressed, LuoAlue, null); |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | } |
---|
210 | |
---|
211 | void Attack() //mitä tapahtuu jos painaa attackkia |
---|
212 | { |
---|
213 | if (goopHP.Value > 0) attackenemy1(); |
---|
214 | else if (skeleHP.Value > 0) attackenemy2(); |
---|
215 | else if (snekHP.Value > 0) attackenemy3(); |
---|
216 | } |
---|
217 | |
---|
218 | void attackenemy1() |
---|
219 | { |
---|
220 | goopHP.Value -= playerdamage; |
---|
221 | |
---|
222 | GameObject hit = new GameObject(100.00, 100.00); |
---|
223 | hit.Shape = Shape.Star; |
---|
224 | hit.Color = Color.OrangeRed; |
---|
225 | hit.X = 0.00; |
---|
226 | hit.Y = Screen.Top - 60.00; |
---|
227 | Add(hit, 3); |
---|
228 | hit.Image = LoadImage("hitanim2"); |
---|
229 | hit.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 50); |
---|
230 | |
---|
231 | PlaySound("hit"); |
---|
232 | |
---|
233 | GameObject hit2 = new GameObject(100.00, 100.00); |
---|
234 | hit2.Shape = Shape.Star; |
---|
235 | hit2.Color = Color.OrangeRed; |
---|
236 | hit2.X = 0.00; |
---|
237 | hit2.Y = Screen.Top - 60.00; |
---|
238 | hit2.Image = LoadImage("hitanim"); |
---|
239 | hit2.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 100); |
---|
240 | Add(hit2, 3); |
---|
241 | |
---|
242 | Attackfeed(playerdamage); |
---|
243 | } |
---|
244 | |
---|
245 | void attackenemy2() |
---|
246 | { |
---|
247 | skeleHP.Value -= playerdamage; |
---|
248 | |
---|
249 | GameObject hit = new GameObject(100.00, 100.00); |
---|
250 | hit.Shape = Shape.Star; |
---|
251 | hit.Color = Color.OrangeRed; |
---|
252 | hit.X = 0.00; |
---|
253 | hit.Y = Screen.Top - 60.00; |
---|
254 | Add(hit, 3); |
---|
255 | hit.Image = LoadImage("hitanim2"); |
---|
256 | hit.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 50); |
---|
257 | |
---|
258 | PlaySound("hit"); |
---|
259 | |
---|
260 | GameObject hit2 = new GameObject(100.00, 100.00); |
---|
261 | hit2.Shape = Shape.Star; |
---|
262 | hit2.Color = Color.OrangeRed; |
---|
263 | hit2.X = 0.00; |
---|
264 | hit2.Y = Screen.Top - 60.00; |
---|
265 | hit2.Image = LoadImage("hitanim"); |
---|
266 | hit2.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 100); |
---|
267 | Add(hit2, 3); |
---|
268 | |
---|
269 | Attackfeed(playerdamage); |
---|
270 | } |
---|
271 | |
---|
272 | void attackenemy3() |
---|
273 | { |
---|
274 | snekHP.Value -= playerdamage; |
---|
275 | |
---|
276 | GameObject hit = new GameObject(100.00, 100.00); |
---|
277 | hit.Shape = Shape.Star; |
---|
278 | hit.Color = Color.OrangeRed; |
---|
279 | hit.X = 0.00; |
---|
280 | hit.Y = Screen.Top - 60.00; |
---|
281 | Add(hit, 3); |
---|
282 | hit.Image = LoadImage("hitanim2"); |
---|
283 | hit.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 50); |
---|
284 | |
---|
285 | PlaySound("hit"); |
---|
286 | |
---|
287 | GameObject hit2 = new GameObject(100.00, 100.00); |
---|
288 | hit2.Shape = Shape.Star; |
---|
289 | hit2.Color = Color.OrangeRed; |
---|
290 | hit2.X = 0.00; |
---|
291 | hit2.Y = Screen.Top - 60.00; |
---|
292 | hit2.Image = LoadImage("hitanim"); |
---|
293 | hit2.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 100); |
---|
294 | Add(hit2, 3); |
---|
295 | |
---|
296 | Attackfeed(playerdamage); |
---|
297 | } |
---|
298 | |
---|
299 | void Attackfeed(double damage) //combat login tiedot päivittyy |
---|
300 | { |
---|
301 | double y = feedtext.Y; |
---|
302 | |
---|
303 | feedtext.Text = "Delivered " + damage + " damage.\n" + feedtext.Text; |
---|
304 | feedtext.Y = textheight - feedtext.Height / 2; |
---|
305 | |
---|
306 | switch (vihollisNro) |
---|
307 | { |
---|
308 | case 1: |
---|
309 | if (goopHP > 0) Timer.SingleShot(1.0, Enemy1attack); |
---|
310 | else Transition(); |
---|
311 | break; |
---|
312 | |
---|
313 | case 2: |
---|
314 | if (skeleHP > 0) Timer.SingleShot(1.0, Enemy2attack); |
---|
315 | else Transition2(); |
---|
316 | break; |
---|
317 | |
---|
318 | case 3: |
---|
319 | if (snekHP > 0) Timer.SingleShot(1.0, Enemy3attack); |
---|
320 | else Voitit(); |
---|
321 | break; |
---|
322 | } |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | |
---|
327 | |
---|
328 | |
---|
329 | } |
---|
330 | |
---|
331 | void Enemy1attack() //ekan vihollisen AI |
---|
332 | |
---|
333 | { |
---|
334 | PlaySound("playertakesdamage"); |
---|
335 | HP.Value -= enemy1damage; |
---|
336 | |
---|
337 | double y = feedtext.Y; |
---|
338 | double x = feedtext.X; |
---|
339 | |
---|
340 | feedtext.Text = "Received " + enemy1damage + " damage.\n" + feedtext.Text; |
---|
341 | feedtext.Y = textheight - feedtext.Height / 2; |
---|
342 | feedtext.X = textwidth;; |
---|
343 | |
---|
344 | pelaajatoiminut = false; |
---|
345 | |
---|
346 | if (HP == 0) Lose(); |
---|
347 | } |
---|
348 | |
---|
349 | void Enemy2attack() //tokan vihollisen AI |
---|
350 | { |
---|
351 | PlaySound("playertakesdamage"); |
---|
352 | HP.Value -= enemy2damage; |
---|
353 | |
---|
354 | double y = feedtext.Y; |
---|
355 | double x = feedtext.X; |
---|
356 | |
---|
357 | feedtext.Text = "Received " + enemy2damage + " damage.\n" + feedtext.Text; |
---|
358 | feedtext.Y = textheight - feedtext.Height / 2; |
---|
359 | feedtext.X = textwidth; ; |
---|
360 | |
---|
361 | pelaajatoiminut = false; |
---|
362 | |
---|
363 | if (HP == 0) Lose(); |
---|
364 | } |
---|
365 | |
---|
366 | void Enemy3attack() //kolmannen vihollisen ai |
---|
367 | { |
---|
368 | PlaySound("playertakesdamage"); |
---|
369 | HP.Value -= enemy3damage; |
---|
370 | |
---|
371 | double y = feedtext.Y; |
---|
372 | double x = feedtext.X; |
---|
373 | |
---|
374 | feedtext.Text = "Received " + enemy3damage + " damage.\n" + feedtext.Text; |
---|
375 | feedtext.Y = textheight - feedtext.Height / 2; |
---|
376 | feedtext.X = textwidth; ; |
---|
377 | |
---|
378 | pelaajatoiminut = false; |
---|
379 | |
---|
380 | if (HP == 0) Lose(); |
---|
381 | } |
---|
382 | void Transition() //pelin siirtyminen eteenpäin, kun pahis voitettu |
---|
383 | { |
---|
384 | foeHP.Destroy(); |
---|
385 | vihollisNro++; |
---|
386 | transition = new GameObject(1800.00, 700.00); |
---|
387 | transition.Shape = Shape.Rectangle; |
---|
388 | transition.Color = Color.Aqua; |
---|
389 | transition.X = -10.00; |
---|
390 | transition.Y = 200.00; |
---|
391 | transition.Image = LoadImage("transiitio"); |
---|
392 | Add(transition); |
---|
393 | |
---|
394 | Timer.SingleShot(1.5, Lisaapahis2); |
---|
395 | } |
---|
396 | |
---|
397 | void Transition2() //pelin siirtyminen eteenpäin, kun toinen pahis on voitettu |
---|
398 | { |
---|
399 | foeHP.Destroy(); |
---|
400 | vihollisNro++; |
---|
401 | transition = new GameObject(1800.00, 700.00); |
---|
402 | transition.Shape = Shape.Rectangle; |
---|
403 | transition.Color = Color.Aqua; |
---|
404 | transition.X = -10.00; |
---|
405 | transition.Y = 200.00; |
---|
406 | transition.Image = LoadImage("transiitio"); |
---|
407 | Add(transition, 3); |
---|
408 | |
---|
409 | Timer.SingleShot(1.5, Lisaapahis3); |
---|
410 | } |
---|
411 | |
---|
412 | void Lisaapahis2() |
---|
413 | { |
---|
414 | foe2 = new GameObject(1800.00, 700.00); |
---|
415 | foe2.Shape = Shape.Rectangle; |
---|
416 | foe2.Color = Color.Aqua; |
---|
417 | foe2.X = -10.00; |
---|
418 | foe2.Y = 200.00; |
---|
419 | foe2.Image = LoadImage("luumies"); |
---|
420 | Add(foe2); |
---|
421 | |
---|
422 | pelaajatoiminut = false; |
---|
423 | |
---|
424 | skeleHP = new IntMeter(40); |
---|
425 | |
---|
426 | foeHP = new Label(); |
---|
427 | |
---|
428 | foeHP.X = 150.00; |
---|
429 | foeHP.Y = Screen.Top - 40.00; |
---|
430 | foeHP.TextColor = Color.Red; |
---|
431 | foeHP.Color = Color.Transparent; |
---|
432 | Add(foeHP); |
---|
433 | |
---|
434 | foeHP.BindTo(skeleHP); |
---|
435 | Add(foeHP, 3); |
---|
436 | |
---|
437 | } |
---|
438 | |
---|
439 | void Lisaapahis3() |
---|
440 | |
---|
441 | { |
---|
442 | foe3 = new GameObject(1800.00, 700.00); |
---|
443 | foe3.Shape = Shape.Rectangle; |
---|
444 | foe3.Color = Color.Aqua; |
---|
445 | foe3.X = -10.00; |
---|
446 | foe3.Y = 200.00; |
---|
447 | foe3.Image = LoadImage("snek"); |
---|
448 | Add(foe3, 3); |
---|
449 | |
---|
450 | pelaajatoiminut = false; |
---|
451 | |
---|
452 | snekHP = new IntMeter(100); |
---|
453 | |
---|
454 | foeHP = new Label(); |
---|
455 | |
---|
456 | foeHP.X = 150.00; |
---|
457 | foeHP.Y = Screen.Top - 40.00; |
---|
458 | foeHP.TextColor = Color.Blue; |
---|
459 | foeHP.Color = Color.Transparent; |
---|
460 | Add(foeHP); |
---|
461 | |
---|
462 | foeHP.BindTo(snekHP); |
---|
463 | Add(foeHP, 2); |
---|
464 | } |
---|
465 | |
---|
466 | void Voitit() //kun pelaaja voittaa kaikki pahikset |
---|
467 | { |
---|
468 | pelaajatoiminut = true; |
---|
469 | foeHP.Destroy(); |
---|
470 | voitto = new GameObject(1800.00, 700.00); |
---|
471 | voitto.Shape = Shape.Rectangle; |
---|
472 | voitto.Color = Color.Aqua; |
---|
473 | voitto.X = -10.00; |
---|
474 | voitto.Y = 200.00; |
---|
475 | voitto.Image = LoadImage("voitto"); |
---|
476 | Add(voitto, 3); |
---|
477 | |
---|
478 | Timer.SingleShot(10, Exit); |
---|
479 | } |
---|
480 | |
---|
481 | void Lose() //pelaajan häviö |
---|
482 | { |
---|
483 | pelaajatoiminut = true; |
---|
484 | foeHP.Destroy(); |
---|
485 | |
---|
486 | tappio = new GameObject(Screen.Width, Screen.Height); |
---|
487 | tappio.Shape = Shape.Rectangle; |
---|
488 | tappio.Color = Color.Black; |
---|
489 | tappio.Image = LoadImage("häviö"); |
---|
490 | Add(tappio, 3); |
---|
491 | |
---|
492 | } |
---|
493 | } |
---|
494 | |
---|