1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Effects; |
---|
6 | |
---|
7 | public class Peli : TopDownPhysicsGame |
---|
8 | { |
---|
9 | PhysicsObject vasenReuna; |
---|
10 | PhysicsObject oikeaReuna; |
---|
11 | |
---|
12 | protected override void Begin() |
---|
13 | { |
---|
14 | KineticFriction = 0.5; // Asetetaan kitka |
---|
15 | |
---|
16 | Automobile auto = new Automobile(60, 50); |
---|
17 | auto.Mass = 100.0; |
---|
18 | auto.Color = new Color(1, 1, 1); |
---|
19 | auto.X = -200; |
---|
20 | auto.Y = 0; |
---|
21 | auto.LinearDamping = 0.99; |
---|
22 | auto.AngularDamping = 1.0; |
---|
23 | Add(auto); |
---|
24 | |
---|
25 | Automobile auto2 = new Automobile(60, 50); |
---|
26 | auto2.Mass = 100.0; |
---|
27 | auto2.Color = new Color(255, 255, 255); |
---|
28 | auto2.X = 200; |
---|
29 | auto2.Y = 0; |
---|
30 | auto2.LinearDamping = 0.99; |
---|
31 | auto2.AngularDamping = 1.0; |
---|
32 | auto2.Angle = Angle.Degrees (180.0); |
---|
33 | Add(auto2); |
---|
34 | |
---|
35 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
36 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
37 | Keyboard.Listen(Key.Up, ButtonState.Down, kiihdyta, "Kiihdytä", auto); |
---|
38 | Keyboard.Listen(Key.Down, ButtonState.Down, jarruta, "Jarruta", auto); |
---|
39 | Keyboard.Listen(Key.Left, ButtonState.Down, kaanny, "Käänny vasemmalle", auto, 2.0); |
---|
40 | Keyboard.Listen(Key.Right, ButtonState.Down, kaanny, "Käänny oikealle", auto, -2.0); |
---|
41 | |
---|
42 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
43 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
44 | Keyboard.Listen(Key.W, ButtonState.Down, kiihdyta, "Kiihdytä", auto2); |
---|
45 | Keyboard.Listen(Key.S, ButtonState.Down, jarruta, "Jarruta", auto2); |
---|
46 | Keyboard.Listen(Key.A, ButtonState.Down, kaanny, "Käänny vasemmalle", auto2, 2.0); |
---|
47 | Keyboard.Listen(Key.D, ButtonState.Down, kaanny, "Käänny oikealle", auto2, -2.0); |
---|
48 | |
---|
49 | ShowControlHelp(); |
---|
50 | |
---|
51 | Kentta(); |
---|
52 | } |
---|
53 | |
---|
54 | void kiihdyta(Automobile auto) |
---|
55 | { |
---|
56 | auto.Accelerate(Time.SinceLastUpdate.TotalSeconds); |
---|
57 | } |
---|
58 | |
---|
59 | void jarruta(Automobile auto) |
---|
60 | { |
---|
61 | auto.Brake(Time.SinceLastUpdate.TotalSeconds); |
---|
62 | } |
---|
63 | |
---|
64 | void kaanny(Automobile auto, double kaannos) |
---|
65 | { |
---|
66 | auto.Angle = Angle.Degrees(auto.Angle.Degree + kaannos); |
---|
67 | } |
---|
68 | |
---|
69 | void Kentta() |
---|
70 | { |
---|
71 | PhysicsObject pylvas1 = PhysicsObject.CreateStaticObject(50.0, 50.0); |
---|
72 | pylvas1.Shape = Shapes.Rectangle; |
---|
73 | pylvas1.X = 200; |
---|
74 | pylvas1.Y = 200; |
---|
75 | pylvas1.Restitution = 0.2; |
---|
76 | pylvas1.Tag = "pylvas"; |
---|
77 | Add(pylvas1); |
---|
78 | |
---|
79 | PhysicsObject pylvas2 = PhysicsObject.CreateStaticObject(50.0, 50.0); |
---|
80 | pylvas2.Shape = Shapes.Rectangle; |
---|
81 | pylvas2.X = -200; |
---|
82 | pylvas2.Y = 200; |
---|
83 | pylvas2.Restitution = 0.2; |
---|
84 | pylvas2.Tag = "pylvas"; |
---|
85 | Add(pylvas2); |
---|
86 | |
---|
87 | PhysicsObject pylvas3 = PhysicsObject.CreateStaticObject(50.0, 50.0); |
---|
88 | pylvas3.Shape = Shapes.Rectangle; |
---|
89 | pylvas3.X = -200; |
---|
90 | pylvas3.Y = -200; |
---|
91 | pylvas3.Restitution = 0.2; |
---|
92 | pylvas3.Tag = "pylvas"; |
---|
93 | Add(pylvas3); |
---|
94 | |
---|
95 | PhysicsObject pylvas4 = PhysicsObject.CreateStaticObject(50.0, 50.0); |
---|
96 | pylvas4.Shape = Shapes.Rectangle; |
---|
97 | pylvas4.X = 200; |
---|
98 | pylvas4.Y = -200; |
---|
99 | pylvas4.Restitution = 0.2; |
---|
100 | pylvas4.Tag = "pylvas"; |
---|
101 | Add(pylvas4); |
---|
102 | |
---|
103 | GameObject maata = new GameObject(800.0, 700.0); |
---|
104 | maata.Shape = Shapes.Circle; |
---|
105 | maata.Color = Color.Gray; |
---|
106 | Add(maata); |
---|
107 | |
---|
108 | GameObject Reuna = new GameObject(70.0, 70.0); |
---|
109 | Reuna.Shape = Shapes.Circle; |
---|
110 | Reuna.Color = Color.Black; |
---|
111 | Add(Reuna); |
---|
112 | |
---|
113 | GameObject Boostipaikka = new GameObject(60.0, 60.0); |
---|
114 | Boostipaikka.Shape = Shapes.Circle; |
---|
115 | Boostipaikka.Color = Color.Turquoise; |
---|
116 | Add(Boostipaikka); |
---|
117 | |
---|
118 | |
---|
119 | vasenReuna = Level.CreateLeftBorder(); |
---|
120 | vasenReuna.Restitution = 0.3; |
---|
121 | vasenReuna.IsVisible = true; |
---|
122 | oikeaReuna = Level.CreateRightBorder(); |
---|
123 | oikeaReuna.Restitution = 0.3; |
---|
124 | oikeaReuna.IsVisible = true; |
---|
125 | PhysicsObject ylaReuna = Level.CreateTopBorder(); |
---|
126 | ylaReuna.Restitution = 0.3; |
---|
127 | ylaReuna.IsVisible = true; |
---|
128 | PhysicsObject alaReuna = Level.CreateBottomBorder(); |
---|
129 | alaReuna.Restitution = 0.3; |
---|
130 | alaReuna.IsVisible = true; |
---|
131 | |
---|
132 | Level.BackgroundColor = Color.ForestGreen; |
---|
133 | |
---|
134 | Camera.X = 0.0; |
---|
135 | Camera.Y = 0.0; |
---|
136 | Camera.Zoom(1.2); |
---|
137 | |
---|
138 | } |
---|
139 | void PylvaidenVarit() |
---|
140 | { |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | } |
---|