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 Pong : PhysicsGame |
---|
10 | { |
---|
11 | Vector nopeusYlos = new Vector(0, 200); |
---|
12 | Vector nopeusAlas = new Vector(0, -200); |
---|
13 | |
---|
14 | PhysicsObject pallo; |
---|
15 | |
---|
16 | PhysicsObject maila1; |
---|
17 | PhysicsObject maila2; |
---|
18 | |
---|
19 | public override void Begin() |
---|
20 | { |
---|
21 | LuoKentta(); |
---|
22 | AsetaOhjaimet(); |
---|
23 | AloitaPeli(); |
---|
24 | } |
---|
25 | |
---|
26 | void AsetaOhjaimet() |
---|
27 | { |
---|
28 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
29 | Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös"); |
---|
30 | Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila, null); |
---|
31 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
32 | } |
---|
33 | |
---|
34 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
35 | { |
---|
36 | maila.Velocity = nopeus; |
---|
37 | } |
---|
38 | |
---|
39 | void LuoKentta() |
---|
40 | { |
---|
41 | pallo = new PhysicsObject( 40.0, 40.0 ); |
---|
42 | pallo.Shape = Shape.Circle; |
---|
43 | pallo.X = -200.0; |
---|
44 | pallo.Y = 0.0; |
---|
45 | pallo.Restitution = 1.0; |
---|
46 | Add( pallo ); |
---|
47 | |
---|
48 | LuoMaila(Level.Left + 20.0, 0.0); |
---|
49 | LuoMaila(Level.Right - 20.0, 0.0); |
---|
50 | |
---|
51 | Level.CreateBorders( 1.0, false ); |
---|
52 | Level.BackgroundColor = Color.Black; |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | Camera.ZoomToLevel(); |
---|
57 | } |
---|
58 | |
---|
59 | void AloitaPeli() |
---|
60 | { |
---|
61 | Vector impulssi = new Vector( 500.0, 0.0 ); |
---|
62 | pallo.Hit( impulssi ); |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | } |
---|
68 | |
---|
69 | PhysicsObject LuoMaila(double x, double y) |
---|
70 | { |
---|
71 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
72 | maila.Shape = Shape.Rectangle; |
---|
73 | maila.X = x; |
---|
74 | maila.Y = y; |
---|
75 | maila.Restitution = 1.0; |
---|
76 | Add(maila); |
---|
77 | |
---|
78 | return maila; |
---|
79 | } |
---|
80 | } |
---|