1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | |
---|
7 | class Tasohyppely : PhysicsGame |
---|
8 | { |
---|
9 | |
---|
10 | |
---|
11 | const double nopeus = 200; |
---|
12 | const double hyppyVoima =3000; |
---|
13 | |
---|
14 | PlatformCharacter Seppo; |
---|
15 | PlatformCharacter AntiSeppo; |
---|
16 | PhysicsObject taso; |
---|
17 | |
---|
18 | |
---|
19 | protected override void Begin() |
---|
20 | |
---|
21 | { |
---|
22 | Gravity = new Vector(0, -1000); |
---|
23 | |
---|
24 | Camera.ZoomToLevel(0.5); |
---|
25 | |
---|
26 | luoKentta(); |
---|
27 | lisaaNappaimet(); |
---|
28 | |
---|
29 | Camera.Follow(Seppo); |
---|
30 | |
---|
31 | Camera.StayInLevel = true; |
---|
32 | |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | void luoKentta() |
---|
37 | { |
---|
38 | Level.Background.CreateGradient(Color.White, Color.SkyBlue); |
---|
39 | PhysicsObject vasenReuna = Level.CreateLeftBorder(); |
---|
40 | vasenReuna.StaticFriction = 0; |
---|
41 | PhysicsObject OikeaReuna = Level.CreateRightBorder(); |
---|
42 | OikeaReuna.StaticFriction = 0; |
---|
43 | PhysicsObject Pohja = Level.CreateBottomBorder(); |
---|
44 | Pohja.StaticFriction = 0; |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | PhysicsObject taso = PhysicsObject.CreateStaticObject(150, 20); |
---|
49 | taso.Color = Color.Green; |
---|
50 | taso.X = -50; |
---|
51 | taso.Y = 0; |
---|
52 | taso.AngularVelocity = 9.0; |
---|
53 | |
---|
54 | |
---|
55 | Add(taso); |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | lisaaTaso(-200, -200); |
---|
60 | lisaaTaso(100, -200); |
---|
61 | lisaaTaso(100, 200); |
---|
62 | lisaaTaso(-200, 200); |
---|
63 | lisaaTaso(-400, 0); |
---|
64 | lisaaTaso(400, 0); |
---|
65 | lisaaTaso(-50, -300); |
---|
66 | lisaaTaso(-50, 300); |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | lisaaPelaajat(); |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | void lisaaTaso(double x, double y) |
---|
77 | { |
---|
78 | PhysicsObject taso = PhysicsObject.CreateStaticObject(100, 30); |
---|
79 | taso.Color = Color.Green; |
---|
80 | taso.X = x; |
---|
81 | taso.Y = y; |
---|
82 | Add(taso); |
---|
83 | } |
---|
84 | |
---|
85 | void lisaaPelaajat() |
---|
86 | { |
---|
87 | Seppo = new PlatformCharacter(110,100); |
---|
88 | Seppo.Mass = 4.0; |
---|
89 | Seppo.Image = LoadImage("sepoo"); |
---|
90 | Seppo.X = -200; |
---|
91 | Seppo.Y = 120; |
---|
92 | |
---|
93 | |
---|
94 | Add(Seppo); |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | AntiSeppo = new PlatformCharacter(100,100); |
---|
99 | AntiSeppo.Mass = 4.0; |
---|
100 | AntiSeppo.Image = LoadImage("sepoo2"); |
---|
101 | AntiSeppo.X = 100; |
---|
102 | AntiSeppo.Y = 120; |
---|
103 | |
---|
104 | Add(AntiSeppo); |
---|
105 | |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | void lisaaNappaimet() |
---|
113 | { |
---|
114 | Keyboard.Listen(Key.CapsLock, ButtonState.Pressed, Begin, ""); |
---|
115 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
116 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
117 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", Seppo, -nopeus); |
---|
118 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", Seppo, nopeus); |
---|
119 | ControllerOne.Listen(Button.A, ButtonState.Down, rajahdys3, ""); |
---|
120 | ControllerOne.Listen(Button.DPadUp, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", Seppo, hyppyVoima); |
---|
121 | ControllerOne.Listen(Button.X, ButtonState.Pressed, rajahdys, ""); |
---|
122 | ControllerOne.Listen(Button.Y, ButtonState.Down, rajahdys5, ""); |
---|
123 | ControllerOne.Listen(Button.RightTrigger, ButtonState.Down, teleport, ""); |
---|
124 | ControllerOne.Listen(Button.LeftTrigger, ButtonState.Down, teleport3, ""); |
---|
125 | ControllerOne.Listen(Button.RightStick, ButtonState.Down, seppotelettaa, ""); |
---|
126 | ControllerOne.Listen(Button.RightShoulder, ButtonState.Down, muhahaa, ""); |
---|
127 | ControllerOne.Listen(Button.DPadDown, ButtonState.Down, rajahdys8, ""); |
---|
128 | |
---|
129 | |
---|
130 | ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
131 | ControllerTwo.Listen(Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", AntiSeppo, -nopeus); |
---|
132 | ControllerTwo.Listen(Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", AntiSeppo, nopeus); |
---|
133 | ControllerTwo.Listen(Button.A, ButtonState.Down, rajahdys4, ""); |
---|
134 | ControllerTwo.Listen(Button.DPadUp, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", AntiSeppo, hyppyVoima); |
---|
135 | ControllerTwo.Listen(Button.X, ButtonState.Pressed, rajahdys2, ""); |
---|
136 | ControllerTwo.Listen(Button.Y, ButtonState.Down, rajahdys6, ""); |
---|
137 | ControllerTwo.Listen(Button.RightTrigger, ButtonState.Down, teleport2, ""); |
---|
138 | ControllerTwo.Listen(Button.LeftTrigger, ButtonState.Down, teleport4, ""); |
---|
139 | ControllerTwo.Listen(Button.RightStick, ButtonState.Down, antiseppotelettaa, ""); |
---|
140 | ControllerTwo.Listen(Button.RightShoulder, ButtonState.Down, muhahaa2, ""); |
---|
141 | |
---|
142 | |
---|
143 | ControllerOne.Listen(Button.Start, ButtonState.Pressed, restartti, "Aloita peli uudelleen"); |
---|
144 | ControllerTwo.Listen(Button.Start, ButtonState.Pressed, restartti, "Aloita peli uudelleen"); |
---|
145 | |
---|
146 | ControllerOne.Listen(Button.B, ButtonState.Down, HeitaKranaatti, ""); |
---|
147 | ControllerTwo.Listen(Button.B, ButtonState.Down, HeitaKranaatti2, ""); |
---|
148 | |
---|
149 | ControllerOne.Listen(Button.LeftShoulder, ButtonState.Pressed, poisto, ""); |
---|
150 | ControllerTwo.Listen(Button.LeftShoulder, ButtonState.Pressed, poisto, ""); |
---|
151 | |
---|
152 | ControllerOne.Listen(Button.LeftStick, ButtonState.Pressed, tuomio, ""); |
---|
153 | ControllerTwo.Listen(Button.LeftStick, ButtonState.Pressed, tuomio, ""); |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | } |
---|
161 | |
---|
162 | void liikuta(PlatformCharacter hahmo, double nopeus) |
---|
163 | { |
---|
164 | hahmo.Walk(nopeus); |
---|
165 | } |
---|
166 | |
---|
167 | void hyppaa(PlatformCharacter hahmo, double voima) |
---|
168 | { |
---|
169 | hahmo.Jump(voima ); |
---|
170 | } |
---|
171 | |
---|
172 | void rajahdys() |
---|
173 | { |
---|
174 | Explosion rajahdys = new Explosion(500.00); |
---|
175 | rajahdys.Position = Seppo.Position; |
---|
176 | Add(rajahdys); |
---|
177 | rajahdys.Speed = 500.0; |
---|
178 | rajahdys.Force = 3000; |
---|
179 | ControllerOne.Vibrate(99, 99, 99, 99, 0.1); |
---|
180 | |
---|
181 | |
---|
182 | } |
---|
183 | void rajahdys2() |
---|
184 | { |
---|
185 | Explosion rajahdys = new Explosion(500.00); |
---|
186 | rajahdys.Position = AntiSeppo.Position; |
---|
187 | Add(rajahdys); |
---|
188 | rajahdys.Speed = 500.0; |
---|
189 | rajahdys.Force = 3000; |
---|
190 | ControllerTwo.Vibrate(99, 99, 99, 99, 0.1); |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | void rajahdys3() |
---|
195 | { |
---|
196 | Explosion rajahdys = new Explosion(500.00); |
---|
197 | rajahdys.Position = Seppo.Position; |
---|
198 | Add(rajahdys); |
---|
199 | rajahdys.Speed = 500.0; |
---|
200 | rajahdys.Force = 250; |
---|
201 | ControllerOne.Vibrate(99, 99, 99, 99, 0.1); |
---|
202 | |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | void rajahdys4() |
---|
208 | { |
---|
209 | Explosion rajahdys = new Explosion(500.00); |
---|
210 | rajahdys.Position = AntiSeppo.Position; |
---|
211 | Add(rajahdys); |
---|
212 | rajahdys.Speed = 500.0; |
---|
213 | rajahdys.Force = 250; |
---|
214 | ControllerTwo.Vibrate(99, 99, 99, 99, 0.1); |
---|
215 | } |
---|
216 | |
---|
217 | void rajahdys5() |
---|
218 | { |
---|
219 | Explosion rajahdys = new Explosion(500.00); |
---|
220 | rajahdys.Position = AntiSeppo.Position; |
---|
221 | Add(rajahdys); |
---|
222 | rajahdys.Speed = 50.0; |
---|
223 | rajahdys.Force = 200; |
---|
224 | ControllerTwo.Vibrate(99, 99, 99, 99, 0.1); |
---|
225 | } |
---|
226 | |
---|
227 | void rajahdys6() |
---|
228 | { |
---|
229 | Explosion rajahdys = new Explosion(500.00); |
---|
230 | rajahdys.Position = Seppo.Position; |
---|
231 | Add(rajahdys); |
---|
232 | rajahdys.Speed = 50.0; |
---|
233 | rajahdys.Force = 200; |
---|
234 | ControllerOne.Vibrate(99, 99, 99, 99, 0.1); |
---|
235 | } |
---|
236 | |
---|
237 | void restartti() |
---|
238 | { |
---|
239 | |
---|
240 | Seppo.X = -200; |
---|
241 | Seppo.Y = 120; |
---|
242 | |
---|
243 | AntiSeppo.X = 100; |
---|
244 | AntiSeppo.Y = 120; |
---|
245 | |
---|
246 | } |
---|
247 | |
---|
248 | void teleport2() |
---|
249 | { |
---|
250 | Gravity = new Vector(0, 1000); |
---|
251 | } |
---|
252 | |
---|
253 | void teleport() |
---|
254 | { |
---|
255 | Gravity = new Vector(0, 1000); |
---|
256 | } |
---|
257 | |
---|
258 | void teleport3() |
---|
259 | { |
---|
260 | Gravity = new Vector(0, -1000); |
---|
261 | } |
---|
262 | |
---|
263 | |
---|
264 | void teleport4() |
---|
265 | { |
---|
266 | Gravity = new Vector(0, -1000); |
---|
267 | } |
---|
268 | |
---|
269 | |
---|
270 | void HeitaKranaatti() |
---|
271 | { |
---|
272 | Grenade kranaatti = new Grenade(4.0); |
---|
273 | kranaatti.X = Seppo.X + 10; |
---|
274 | kranaatti.Y = Seppo.Y + 10; |
---|
275 | Add(kranaatti); |
---|
276 | Vector heittoVoima = Vector.FromLengthAndAngle(4000, Angle.Degrees(45)); |
---|
277 | kranaatti.Hit(heittoVoima); |
---|
278 | } |
---|
279 | |
---|
280 | void HeitaKranaatti2() |
---|
281 | { |
---|
282 | Grenade kranaatti = new Grenade(4.0); |
---|
283 | kranaatti.X = AntiSeppo.X - 10; |
---|
284 | kranaatti.Y = AntiSeppo.Y - 10; |
---|
285 | Add(kranaatti); |
---|
286 | Vector heittoVoima = Vector.FromLengthAndAngle(4000, Angle.Degrees(45)); |
---|
287 | kranaatti.Hit(heittoVoima); |
---|
288 | } |
---|
289 | |
---|
290 | void seppotelettaa() |
---|
291 | { |
---|
292 | Seppo.Position = RandomGen.NextVector(Level.Right, Level.Bottom, Level.Left, Level.Top); |
---|
293 | } |
---|
294 | |
---|
295 | void antiseppotelettaa() |
---|
296 | { |
---|
297 | AntiSeppo.Position = RandomGen.NextVector(Level.Right, Level.Bottom, Level.Left, Level.Top); |
---|
298 | } |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | void muhahaa() |
---|
303 | { |
---|
304 | ClusterGrenade kranaatti = new ClusterGrenade(4.0, 2); |
---|
305 | Add(kranaatti); |
---|
306 | kranaatti.X = Seppo.X + 10; |
---|
307 | kranaatti.Y = Seppo.Y + 10; |
---|
308 | Vector heittoVoima = Vector.FromLengthAndAngle(4000, Angle.Degrees(45)); |
---|
309 | kranaatti.Hit(heittoVoima); |
---|
310 | |
---|
311 | kranaatti.NumberOfClusters = 4; |
---|
312 | |
---|
313 | } |
---|
314 | |
---|
315 | |
---|
316 | void muhahaa2() |
---|
317 | { |
---|
318 | ClusterGrenade kranaatti = new ClusterGrenade(4.0, 2); |
---|
319 | Add(kranaatti); |
---|
320 | kranaatti.X = AntiSeppo.X - 10; |
---|
321 | kranaatti.Y = AntiSeppo.Y - 10; |
---|
322 | Vector heittoVoima = Vector.FromLengthAndAngle(4000, Angle.Degrees(45)); |
---|
323 | kranaatti.Hit(heittoVoima); |
---|
324 | |
---|
325 | kranaatti.NumberOfClusters = 4; |
---|
326 | |
---|
327 | } |
---|
328 | |
---|
329 | |
---|
330 | void poisto() |
---|
331 | { |
---|
332 | ClearAll(); |
---|
333 | Begin(); |
---|
334 | } |
---|
335 | |
---|
336 | void tuomio() |
---|
337 | { |
---|
338 | Grenade kranaatti = new Grenade(250.0); |
---|
339 | kranaatti.Position = RandomGen.NextVector(Level.Right, Level.Bottom, Level.Left, Level.Top); |
---|
340 | kranaatti.ExplosionForce = 9999999999999999999; |
---|
341 | kranaatti.ExplosionSpeed = 55; |
---|
342 | ControllerTwo.Vibrate(99, 99, 99, 99, 1.1); |
---|
343 | ControllerOne.Vibrate(99, 99, 99, 99, 1.1); |
---|
344 | |
---|
345 | |
---|
346 | Add(kranaatti); |
---|
347 | Vector heittoVoima = Vector.FromLengthAndAngle(4000, Angle.Degrees(45)); |
---|
348 | kranaatti.Hit(heittoVoima); |
---|
349 | } |
---|
350 | |
---|
351 | |
---|
352 | void rajahdys8() |
---|
353 | { |
---|
354 | Explosion rajahdys = new Explosion(500.00); |
---|
355 | rajahdys.Position = AntiSeppo.Position; |
---|
356 | Add(rajahdys); |
---|
357 | rajahdys.Speed = 1000.0; |
---|
358 | rajahdys.Force = 8000; |
---|
359 | ControllerTwo.Vibrate(99, 99, 99, 99, 0.1); |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | |
---|
364 | |
---|
365 | |
---|
366 | |
---|
367 | |
---|