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 | Vector nopeusylös = new Vector (0.0, 200.0); |
---|
12 | Vector nopeusalas = new Vector(0.0, -200.0); |
---|
13 | |
---|
14 | PhysicsObject pallo; |
---|
15 | |
---|
16 | PhysicsObject maila1; |
---|
17 | PhysicsObject maila2; |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | public override void Begin() |
---|
22 | { |
---|
23 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
24 | luokentta(); |
---|
25 | asetaohjaimet(); |
---|
26 | aloitapeli(); |
---|
27 | |
---|
28 | |
---|
29 | |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | void luokentta() |
---|
34 | { |
---|
35 | Camera.ZoomToLevel(); |
---|
36 | |
---|
37 | Level.BackgroundColor = Color.Black; |
---|
38 | Level.CreateBorders(1.0, false); |
---|
39 | |
---|
40 | //pallo |
---|
41 | pallo = new PhysicsObject(40.0, 40.0); |
---|
42 | Add(pallo); |
---|
43 | pallo.Shape = Shape.Circle; |
---|
44 | pallo.X = -200.0; |
---|
45 | pallo.Y = 0.0; |
---|
46 | pallo.Restitution = 1.0; |
---|
47 | pallo.Color = Color.Lime; |
---|
48 | |
---|
49 | maila1 = luomaila (Level.Left + 20.0, 0.0); |
---|
50 | maila2 = luomaila(Level.Right - 20.0, 0.0); |
---|
51 | |
---|
52 | |
---|
53 | MessageDisplay.TextColor = Color.Lime; |
---|
54 | |
---|
55 | |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | void aloitapeli() |
---|
60 | { |
---|
61 | Vector impulssi = new Vector(500.0, 0.0); |
---|
62 | pallo.Hit(impulssi); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | PhysicsObject luomaila(double x, double y) |
---|
67 | { |
---|
68 | //maila |
---|
69 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
70 | maila.Shape = Shape.Rectangle; |
---|
71 | maila.Color = Color.Lime; |
---|
72 | maila.X = x; |
---|
73 | maila.Y = y; |
---|
74 | maila.Restitution = 1.0; |
---|
75 | Add(maila); |
---|
76 | |
---|
77 | return maila; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | void asetaohjaimet() |
---|
82 | { |
---|
83 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "poistu"); |
---|
84 | |
---|
85 | Keyboard.Listen(Key.A, ButtonState.Down, asetanopeus, "pelaaja1 liikuttaa mailaa ylös", maila1, nopeusylös); |
---|
86 | Keyboard.Listen(Key.A, ButtonState.Released, asetanopeus, null, maila1, Vector.Zero ); |
---|
87 | Keyboard.Listen(Key.Z, ButtonState.Down, asetanopeus, "pelaaja1 liikuttaa mailaa alas", maila1, nopeusalas); |
---|
88 | Keyboard.Listen(Key.Z, ButtonState.Released, asetanopeus, null, maila1, Vector.Zero); |
---|
89 | |
---|
90 | Keyboard.Listen(Key.Up, ButtonState.Down, asetanopeus, "pelaaja1 liikuttaa mailaa ylös", maila2, nopeusylös); |
---|
91 | Keyboard.Listen(Key.Up, ButtonState.Released, asetanopeus, null, maila2, Vector.Zero); |
---|
92 | Keyboard.Listen(Key.Down, ButtonState.Down, asetanopeus, "pelaaja2 liikuttaa mailaa alas", maila2, nopeusalas); |
---|
93 | Keyboard.Listen(Key.Down, ButtonState.Released, asetanopeus, null, maila2, Vector.Zero); |
---|
94 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "näytä ohjeet"); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | void asetanopeus(PhysicsObject maila, Vector nopeus) |
---|
99 | { |
---|
100 | maila.Velocity = nopeus; |
---|
101 | } |
---|
102 | } |
---|