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 JumpingAdventure : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject spaceship; |
---|
12 | PhysicsObject ufo; |
---|
13 | IntMeter elinvoimaLaskuri; |
---|
14 | public override void Begin() |
---|
15 | { |
---|
16 | Gravity = new Vector(0.0, -800.0); |
---|
17 | |
---|
18 | LuoVihollinen(new Vector(0.0, -380.0), 20.0, 20.0); |
---|
19 | LuoElinvoimalaskuri(); |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | spaceship = new PhysicsObject(30, 30, Shape.Star); |
---|
24 | spaceship.X = 0.0; |
---|
25 | spaceship.Y = -300.0; |
---|
26 | spaceship.Color = Color.Fuchsia; |
---|
27 | spaceship.CanRotate = false; |
---|
28 | spaceship.LifetimeLeft = TimeSpan.FromSeconds(45.0); |
---|
29 | AddCollisionHandler(spaceship, "pahis", PelaajaOsuu); |
---|
30 | Add(spaceship); |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | Level.Background.CreateStars(100000); |
---|
35 | |
---|
36 | Level.CreateBorders(); |
---|
37 | |
---|
38 | Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, null, new Vector(-10000, 0)); |
---|
39 | Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaPelaaja, null, new Vector(0, 0)); |
---|
40 | Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, new Vector(10000, 0)); |
---|
41 | Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaPelaaja, null, new Vector(0, 0)); |
---|
42 | Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, 10000)); |
---|
43 | Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaPelaaja, null, new Vector(0, 0)); |
---|
44 | Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, -10000)); |
---|
45 | Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaPelaaja, null, new Vector(0, 0)); |
---|
46 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
47 | } |
---|
48 | void LiikutaPelaajaa(Vector vektori) |
---|
49 | { |
---|
50 | spaceship.Push(vektori); |
---|
51 | } |
---|
52 | void PysaytaPelaaja(Vector vektori) |
---|
53 | { |
---|
54 | spaceship.Velocity = Vector.Zero; |
---|
55 | } |
---|
56 | |
---|
57 | void LuoVihollinen(Vector paikka, double leveys, double korkeus) |
---|
58 | { |
---|
59 | ufo = new PhysicsObject(leveys, korkeus, Shape.Hexagon); |
---|
60 | ufo.Position = paikka; |
---|
61 | ufo.Tag = "pahis"; |
---|
62 | ufo.Color = Color.Red; |
---|
63 | Add(ufo); |
---|
64 | } |
---|
65 | |
---|
66 | void LuoElinvoimalaskuri() |
---|
67 | { |
---|
68 | elinvoimaLaskuri = new IntMeter(0); |
---|
69 | |
---|
70 | Label elinvoimaNaytto = new Label(); |
---|
71 | elinvoimaNaytto.X = Screen.Left + 100; |
---|
72 | elinvoimaNaytto.Y = Screen.Top - 100; |
---|
73 | elinvoimaNaytto.TextColor = Color.White; |
---|
74 | elinvoimaNaytto.Color = Color.Black; |
---|
75 | |
---|
76 | elinvoimaNaytto.BindTo(elinvoimaLaskuri); |
---|
77 | Add(elinvoimaNaytto); |
---|
78 | } |
---|
79 | |
---|
80 | void PelaajaOsuu(PhysicsObject spaceship, PhysicsObject kohde) |
---|
81 | { |
---|
82 | elinvoimaLaskuri.Value++; |
---|
83 | |
---|
84 | if (elinvoimaLaskuri >= 100) |
---|
85 | spaceship.Destroy(); |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|