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