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 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | LuoKentta(); |
---|
26 | AsetaOhjaimet(); |
---|
27 | Aloitapeli(); |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | Vector impulssi = new Vector(500.0, 0.0); pallo.Hit(impulssi); |
---|
32 | |
---|
33 | Level.CreateBorders(1.0, false); |
---|
34 | |
---|
35 | |
---|
36 | Level.Background.CreateGradient(Color.Black, Color.Gold); |
---|
37 | |
---|
38 | Camera.ZoomToLevel(); |
---|
39 | |
---|
40 | |
---|
41 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
42 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
43 | } |
---|
44 | |
---|
45 | void LuoKentta() |
---|
46 | { |
---|
47 | pallo = new PhysicsObject(50, 50); |
---|
48 | pallo.Shape = Shape.Circle; |
---|
49 | pallo.Color = Color.Gold; |
---|
50 | Add(pallo); |
---|
51 | pallo.X = -200.0; |
---|
52 | pallo.Y = 0.0; |
---|
53 | pallo.Restitution = 1.0; |
---|
54 | |
---|
55 | |
---|
56 | LuoMaila(Level.Left + 20.0, 0.0); |
---|
57 | LuoMaila(Level.Right - 20.0, 0.0); |
---|
58 | |
---|
59 | |
---|
60 | Level.CreateBorders(1.0, false); |
---|
61 | Level.Background.Color = Color.Black; |
---|
62 | } |
---|
63 | |
---|
64 | void Aloitapeli() |
---|
65 | { |
---|
66 | Vector impulssi = new Vector(500.0, 0.0); |
---|
67 | pallo.Hit(impulssi); |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | void AsetaOhjaimet() |
---|
74 | { |
---|
75 | Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); |
---|
76 | Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); |
---|
77 | |
---|
78 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
83 | { |
---|
84 | maila.Velocity = nopeus; |
---|
85 | } |
---|
86 | |
---|
87 | PhysicsObject LuoMaila (double x, double y) |
---|
88 | { |
---|
89 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 120.0); |
---|
90 | maila.Shape = Shape.Rectangle; |
---|
91 | maila.X = x; |
---|
92 | maila.Y = y; |
---|
93 | maila.Restitution = 1.0; |
---|
94 | Add(maila); |
---|
95 | return maila; |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | } |
---|
105 | |
---|
106 | |
---|