1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | public class Peli : PhysicsGame |
---|
7 | { |
---|
8 | Vector nopeusylos = new Vector(0, 200); |
---|
9 | Vector nopeusalas = new Vector(0, -200); |
---|
10 | PhysicsObject pallo; |
---|
11 | |
---|
12 | PhysicsObject maila1; |
---|
13 | PhysicsObject maila2; |
---|
14 | |
---|
15 | protected override void Begin() |
---|
16 | { |
---|
17 | luokentta(); |
---|
18 | AsetaOhjaimet(); |
---|
19 | |
---|
20 | Aloitapeli(); |
---|
21 | //Vector impulssi = new Vector(500.0, 0.0); |
---|
22 | //pallo.Hit(impulssi); |
---|
23 | |
---|
24 | } |
---|
25 | void luokentta() |
---|
26 | { |
---|
27 | pallo = new PhysicsObject(40.0, 40.0); |
---|
28 | pallo.Shape = Shapes.Circle; |
---|
29 | pallo.X = -200.0; |
---|
30 | pallo.Y = 0.0; |
---|
31 | Add(pallo); |
---|
32 | Level.CreateBorders(); |
---|
33 | pallo.Restitution = 1.0; |
---|
34 | Level.CreateBorders(1.0, false); |
---|
35 | Level.BackgroundColor = Color.DarkCyan; |
---|
36 | Camera.ZoomToLevel(); |
---|
37 | maila1 = LuoMaila(Level.Left + 20.0, 0.0); |
---|
38 | maila2 = LuoMaila(Level.Right - 20.0, 0.0); |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | } |
---|
43 | |
---|
44 | void Aloitapeli () |
---|
45 | { |
---|
46 | |
---|
47 | Vector impulssi = new Vector(500.0, 0.0); |
---|
48 | pallo.Hit(impulssi); |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | PhysicsObject LuoMaila( double X, double Y ) |
---|
55 | { |
---|
56 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
57 | maila.Shape = Shapes.Rectangle; |
---|
58 | maila.X = X; |
---|
59 | maila.Y = Y; |
---|
60 | maila.Restitution = 1.0; |
---|
61 | Add(maila); |
---|
62 | return maila; |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | void AsetaOhjaimet () |
---|
68 | { |
---|
69 | Keyboard.Listen (Key.Escape, ButtonState.Pressed, Exit, "Poistu" ); |
---|
70 | Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1:Liikuta Mailaa Ylos", maila1, nopeusylos); |
---|
71 | Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | } |
---|
77 | void AsetaNopeus( PhysicsObject maila, Vector nopeus ) |
---|
78 | { |
---|
79 | maila.Velocity = nopeus; |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|