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 | protected override void Begin() |
---|
10 | { |
---|
11 | KineticFriction = 1.0; // Asetetaan kitka |
---|
12 | |
---|
13 | Automobile auto = new Automobile(80, 40); |
---|
14 | auto.Mass = 100.0; |
---|
15 | auto.Color = new Color(1, 1, 1); |
---|
16 | Add(auto); |
---|
17 | |
---|
18 | Automobile auto2 = new Automobile(80, 40); |
---|
19 | auto2.Mass = 100.0; |
---|
20 | auto2.Color = new Color(255, 255, 255); |
---|
21 | Add(auto2); |
---|
22 | |
---|
23 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
24 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
25 | Keyboard.Listen(Key.Up, ButtonState.Down, kiihdyta, "Kiihdytä", auto); |
---|
26 | Keyboard.Listen(Key.Down, ButtonState.Down, jarruta, "Jarruta", auto); |
---|
27 | Keyboard.Listen(Key.Left, ButtonState.Down, kaanny, "Käänny vasemmalle", auto, 2.0); |
---|
28 | Keyboard.Listen(Key.Right, ButtonState.Down, kaanny, "Käänny oikealle", auto, -2.0); |
---|
29 | |
---|
30 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
31 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
32 | Keyboard.Listen(Key.W, ButtonState.Down, kiihdyta, "Kiihdytä", auto2); |
---|
33 | Keyboard.Listen(Key.S, ButtonState.Down, jarruta, "Jarruta", auto2); |
---|
34 | Keyboard.Listen(Key.A, ButtonState.Down, kaanny, "Käänny vasemmalle", auto2, 2.0); |
---|
35 | Keyboard.Listen(Key.D, ButtonState.Down, kaanny, "Käänny oikealle", auto2, -2.0); |
---|
36 | |
---|
37 | ShowControlHelp(); |
---|
38 | |
---|
39 | Kentta(); |
---|
40 | } |
---|
41 | |
---|
42 | void kiihdyta(Automobile auto) |
---|
43 | { |
---|
44 | auto.Accelerate(Time.SinceLastUpdate.TotalSeconds); |
---|
45 | } |
---|
46 | |
---|
47 | void jarruta(Automobile auto) |
---|
48 | { |
---|
49 | auto.Brake(Time.SinceLastUpdate.TotalSeconds); |
---|
50 | } |
---|
51 | |
---|
52 | void kaanny(Automobile auto, double kaannos) |
---|
53 | { |
---|
54 | auto.Angle = Angle.Degrees(auto.Angle.Degree + kaannos); |
---|
55 | } |
---|
56 | |
---|
57 | void Kentta() |
---|
58 | { |
---|
59 | Level.BackgroundColor = Color.ForestGreen; |
---|
60 | } |
---|
61 | } |
---|