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