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 | |
---|
11 | PhysicsObject pallo; |
---|
12 | |
---|
13 | PhysicsObject maila1; |
---|
14 | PhysicsObject maila2; |
---|
15 | |
---|
16 | protected override void Begin() |
---|
17 | { |
---|
18 | //TODO: Alusta peli tässä |
---|
19 | AsetaOhjaimet(); |
---|
20 | LuoKentta() ; |
---|
21 | AloitaPeli() ; |
---|
22 | |
---|
23 | } |
---|
24 | void LuoKentta() |
---|
25 | { |
---|
26 | pallo = new PhysicsObject(40.0, 40.0); |
---|
27 | pallo.Shape = Shapes.Circle ; |
---|
28 | Add(pallo); |
---|
29 | pallo.X = 200.0; |
---|
30 | pallo.Y = 5.9; |
---|
31 | pallo.Color = Color.DarkViolet ; |
---|
32 | Level.CreateBorders( 1.0,false); |
---|
33 | pallo.Restitution = 1.0; |
---|
34 | Level.BackgroundColor = Color.DarkRed ; |
---|
35 | Camera.ZoomToLevel(); |
---|
36 | maila1 = LuoMaila( Level.Left + 20.0, 0.0 ); |
---|
37 | maila2 = LuoMaila( Level.Right - 20.0, 0.0 ); |
---|
38 | |
---|
39 | } |
---|
40 | void AloitaPeli() |
---|
41 | { |
---|
42 | Vector impulssi = new Vector(500.0, 1.0); |
---|
43 | pallo.Hit(impulssi); |
---|
44 | } |
---|
45 | PhysicsObject LuoMaila(double x, double y) |
---|
46 | { |
---|
47 | |
---|
48 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
49 | maila.Shape = Shapes.Rectangle; |
---|
50 | maila.X = x; |
---|
51 | maila.Y = y; |
---|
52 | maila.Restitution = 1.0; |
---|
53 | Add(maila); |
---|
54 | |
---|
55 | return maila; |
---|
56 | } |
---|
57 | void AsetaOhjaimet() |
---|
58 | { |
---|
59 | |
---|
60 | Keyboard.Listen( Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos ); |
---|
61 | Keyboard.Listen( Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero ); |
---|
62 | Keyboard.Listen( Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas ); |
---|
63 | Keyboard.Listen( Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero ); |
---|
64 | |
---|
65 | Keyboard.Listen( Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos ); |
---|
66 | Keyboard.Listen( Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero ); |
---|
67 | Keyboard.Listen( Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas ); |
---|
68 | Keyboard.Listen( Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero ); |
---|
69 | |
---|
70 | Keyboard.Listen( Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet" ); |
---|
71 | Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, "Poistu" ); |
---|
72 | |
---|
73 | } |
---|
74 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
75 | { |
---|
76 | maila.Velocity = nopeus; |
---|
77 | } |
---|
78 | } |
---|