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 | |
---|
12 | Image Barrel = LoadImage("Kohde"); |
---|
13 | PhysicsObject Tynnyri; |
---|
14 | Image Kuva = LoadImage("Tausta"); |
---|
15 | PhysicsObject Pelaaja; |
---|
16 | PhysicsObject Maali; |
---|
17 | PhysicsObject Nappula; |
---|
18 | PhysicsObject Katoava; |
---|
19 | Image Pallo = LoadImage("Ball"); |
---|
20 | Image button = LoadImage("Nappula"); |
---|
21 | Image Tausta = LoadImage("Tausta"); |
---|
22 | Image Sahko = LoadImage("Warning"); |
---|
23 | Image Tausta2 = LoadImage("Tausta42"); |
---|
24 | |
---|
25 | public override void Begin() |
---|
26 | { |
---|
27 | |
---|
28 | |
---|
29 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, |
---|
30 | LiikutaPelaajaa, null, new Vector(-300, 0), Pelaaja); |
---|
31 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, |
---|
32 | LiikutaPelaajaa, null, new Vector(300, 0), Pelaaja); |
---|
33 | ControllerOne.Listen(Button.A, ButtonState.Down, |
---|
34 | MuutaPainovoima, null); |
---|
35 | |
---|
36 | Level.Background.Image = Kuva; |
---|
37 | LuoKatoava(); |
---|
38 | |
---|
39 | LuoMaali(); |
---|
40 | AloitaKentta(); |
---|
41 | Pelaaja = new PhysicsObject(100, 100); |
---|
42 | Pelaaja.X = -400; |
---|
43 | Pelaaja.Y = -350; |
---|
44 | Pelaaja.Shape = Shape.Circle; |
---|
45 | Pelaaja.Color = Color.Lime; |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | Add(Pelaaja); |
---|
50 | AddCollisionHandler(Pelaaja, KasittelePallonTormays); |
---|
51 | Level.CreateBorders(); |
---|
52 | Pelaaja.KineticFriction = 0.8; |
---|
53 | Pelaaja.Restitution = 0.2; |
---|
54 | Pelaaja.Image = Pallo; |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | Gravity = new Vector(0, -700); |
---|
59 | Keyboard.Listen(Key.Space, ButtonState.Pressed, |
---|
60 | MuutaPainovoima, null); |
---|
61 | Keyboard.Listen(Key.A, ButtonState.Down, |
---|
62 | LiikutaPelaajaa, null, new Vector(-300, 0), Pelaaja); |
---|
63 | Keyboard.Listen(Key.D, ButtonState.Down, |
---|
64 | LiikutaPelaajaa, null, new Vector(300, 0), Pelaaja); |
---|
65 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
66 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
67 | Level.BackgroundColor = Color.Gray; |
---|
68 | Camera.Follow(Pelaaja); |
---|
69 | } |
---|
70 | |
---|
71 | void AloitaKentta() |
---|
72 | { |
---|
73 | |
---|
74 | } |
---|
75 | void LiikutaPelaajaa(Vector vektori, PhysicsObject pelaaja) |
---|
76 | { |
---|
77 | pelaaja.Push(vektori); |
---|
78 | } |
---|
79 | Object LuoMaali() |
---|
80 | { |
---|
81 | |
---|
82 | PhysicsObject Nappula = PhysicsObject.CreateStaticObject(50, 30); |
---|
83 | Nappula.X = -250; |
---|
84 | Nappula.Y = 330; |
---|
85 | Nappula.Color = Color.Red; |
---|
86 | PhysicsObject Maali = PhysicsObject.CreateStaticObject(400.0, 400.0); |
---|
87 | Maali.Image = Sahko; |
---|
88 | Maali.Shape = Shape.Rectangle; |
---|
89 | Maali.X = Level.Right; |
---|
90 | Maali.Y = Level.Bottom; |
---|
91 | Add(Maali); |
---|
92 | PhysicsObject Tynnyri = PhysicsObject.CreateStaticObject(100, 100); |
---|
93 | Tynnyri.X = 240; |
---|
94 | Tynnyri.Y = 75; |
---|
95 | Add(Tynnyri); |
---|
96 | Tynnyri.Image = Barrel; |
---|
97 | |
---|
98 | return Maali; |
---|
99 | Nappula.Image = button; |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | } |
---|
105 | void MuutaPainovoima() |
---|
106 | { |
---|
107 | Gravity = Gravity * (-1); |
---|
108 | if (Level.Background.Image == Tausta2) |
---|
109 | { |
---|
110 | Level.Background.Image = Tausta; |
---|
111 | } else |
---|
112 | Level.Background.Image = Tausta2; |
---|
113 | |
---|
114 | ControllerOne.Vibrate(0.5, 0.5, 0.0, 0.0, 0.1); |
---|
115 | } |
---|
116 | Object LuoKatoava() |
---|
117 | { |
---|
118 | PhysicsObject Katoava = PhysicsObject.CreateStaticObject(100, 50); |
---|
119 | Katoava.X = 240; |
---|
120 | Katoava.Y = 0; |
---|
121 | Katoava.Color = Color.Black; |
---|
122 | Add(Katoava); |
---|
123 | return Katoava; |
---|
124 | Katoava.Shape = Shape.Rectangle; |
---|
125 | } |
---|
126 | void KasittelePallonTormays(PhysicsObject Pelaaja, PhysicsObject kohde) |
---|
127 | { |
---|
128 | if (kohde == Nappula) |
---|
129 | { |
---|
130 | MessageDisplay.Add("Bump!"); |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | |
---|