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