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_0 : PhysicsGame |
---|
10 | { |
---|
11 | Vector nopeusAlas = new Vector(0, -200); |
---|
12 | Vector nopeusYlos = new Vector(0, 200); |
---|
13 | PhysicsObject pallo; |
---|
14 | PhysicsObject maila1; |
---|
15 | PhysicsObject maila2; |
---|
16 | |
---|
17 | public override void Begin() |
---|
18 | { |
---|
19 | LuoKentta(); |
---|
20 | AloitaPeli(); |
---|
21 | AsetaOhjaimet(); |
---|
22 | LisaaLaskurit(); |
---|
23 | } |
---|
24 | void AloitaPeli() |
---|
25 | { |
---|
26 | Vector impulssi = new Vector(500.0, 0.0); |
---|
27 | pallo.Hit(impulssi); |
---|
28 | } |
---|
29 | |
---|
30 | PhysicsObject Luomaila(double X, double Y) |
---|
31 | { |
---|
32 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
33 | maila.Shape = Shape.Rectangle; |
---|
34 | maila.X = X; |
---|
35 | maila.Y = Y; |
---|
36 | maila.Restitution = 1.0; |
---|
37 | |
---|
38 | Add(maila); |
---|
39 | return maila; |
---|
40 | } |
---|
41 | void LisaaLaskurit |
---|
42 | |
---|
43 | void AsetaOhjaimet() |
---|
44 | { |
---|
45 | Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "pelaaja1: Liikuta mailaa ylös", maila1, nopeusYlos); |
---|
46 | Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero ); |
---|
47 | Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja2: Liikuta mailaa alas", maila1, nopeusAlas); |
---|
48 | Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); |
---|
49 | |
---|
50 | Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "pelaaja2: Liikuta mailaa ylös", maila2, nopeusYlos); |
---|
51 | Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); |
---|
52 | Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja2: Liikuta mailaa alas", maila2, nopeusAlas); |
---|
53 | Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); |
---|
54 | |
---|
55 | } |
---|
56 | |
---|
57 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
58 | { |
---|
59 | if ( (nopeus.Y > 0) && (maila.Top > Level.Top) ) |
---|
60 | { |
---|
61 | maila.Velocity = Vector.Zero; |
---|
62 | return; |
---|
63 | } |
---|
64 | if ( (nopeus.Y > 0) && (maila.Top) ) |
---|
65 | { |
---|
66 | maila.Velocity = Vector.Zero; |
---|
67 | return; |
---|
68 | } |
---|
69 | maila.Velocity = nopeus; |
---|
70 | } |
---|
71 | |
---|
72 | void LuoKentta() |
---|
73 | { |
---|
74 | |
---|
75 | pallo = new PhysicsObject(40, 40); |
---|
76 | |
---|
77 | Add(pallo); |
---|
78 | pallo.Color = Color.DarkCyan; |
---|
79 | Level.BackgroundColor = Color.Magenta; |
---|
80 | pallo.Shape = Shape.Circle; |
---|
81 | pallo.X = -200.0; |
---|
82 | pallo.Y = 100.0; |
---|
83 | pallo.Restitution = 1.0; |
---|
84 | |
---|
85 | maila1 = Luomaila(Level.Left + 20.0, 0.0); |
---|
86 | maila2 = Luomaila(Level.Right - 20.0, 0.0); |
---|
87 | |
---|
88 | Level.CreateBorders(1.0, false); |
---|
89 | Camera.ZoomToLevel(); |
---|
90 | |
---|
91 | |
---|
92 | { |
---|
93 | |
---|
94 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
95 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|