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_03 : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject pallo; |
---|
12 | Vector nopeusYlos = new Vector(0, 200); |
---|
13 | Vector nopeusalas = new Vector(0, -200); |
---|
14 | const double PALLON_MIN_NOPEUS = 10000; |
---|
15 | PhysicsObject maila1; |
---|
16 | PhysicsObject maila2; |
---|
17 | |
---|
18 | public override void Begin() |
---|
19 | { |
---|
20 | LuoKentta(); |
---|
21 | AsetaOhjaimet(); |
---|
22 | LisaaLaskurit(); |
---|
23 | Aloitapeli(); |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | Vector impulssi = new Vector(500.0, 0.0); pallo.Hit(impulssi); |
---|
28 | |
---|
29 | Level.CreateBorders(1.0, false); |
---|
30 | |
---|
31 | |
---|
32 | Level.Background.CreateGradient(Color.Black, Color.Gold); |
---|
33 | |
---|
34 | Camera.ZoomToLevel(); |
---|
35 | |
---|
36 | |
---|
37 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
38 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
39 | } |
---|
40 | |
---|
41 | void LuoKentta() |
---|
42 | { |
---|
43 | pallo = new PhysicsObject(50, 50); |
---|
44 | pallo.Shape = Shape.Circle; |
---|
45 | pallo.Color = Color.Gold; |
---|
46 | Add(pallo); |
---|
47 | pallo.X = -200.0; |
---|
48 | pallo.Y = 0.0; |
---|
49 | pallo.Restitution = 1.0; |
---|
50 | |
---|
51 | |
---|
52 | maila1= LuoMaila(Level.Left + 20.0, 0.0); |
---|
53 | maila2= LuoMaila(Level.Right - 20.0, 0.0); |
---|
54 | |
---|
55 | |
---|
56 | Level.CreateBorders(1.0, false); |
---|
57 | Level.Background.Color = Color.Black; |
---|
58 | } |
---|
59 | |
---|
60 | void Aloitapeli() |
---|
61 | { |
---|
62 | Vector impulssi = new Vector(500.0, 0.0); |
---|
63 | pallo.Hit(impulssi); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | void AsetaOhjaimet() |
---|
70 | { |
---|
71 | Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); |
---|
72 | Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); |
---|
73 | Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "pelaaja 1", maila1, nopeusalas); |
---|
74 | Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); |
---|
75 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
76 | |
---|
77 | Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); |
---|
78 | Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); |
---|
79 | Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "pelaaja 2: Likuta mailaa alas", maila2, nopeusalas); |
---|
80 | Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); |
---|
81 | |
---|
82 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
83 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
88 | { |
---|
89 | |
---|
90 | |
---|
91 | if ((maila.Top > 0) && (Level.Top > Level.Top)) |
---|
92 | { |
---|
93 | maila.Velocity = Vector.Zero; |
---|
94 | return; |
---|
95 | } |
---|
96 | |
---|
97 | maila.Velocity = nopeus; |
---|
98 | |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | PhysicsObject LuoMaila(double x, double y) |
---|
105 | { |
---|
106 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 120.0); |
---|
107 | maila.Shape = Shape.Rectangle; |
---|
108 | maila.X = x; |
---|
109 | maila.Y = y; |
---|
110 | maila.Restitution = 1.0; |
---|
111 | Add(maila); |
---|
112 | return maila; |
---|
113 | } |
---|
114 | void LiikutaMailaaYlos(PhysicsObject maila) |
---|
115 | { |
---|
116 | |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | void LisaaLaskurit() |
---|
121 | { |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | } |
---|
134 | |
---|
135 | |
---|