1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.ScreenObjects; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | public class Peli : TopDownPhysicsGame |
---|
7 | { |
---|
8 | protected override void Begin() |
---|
9 | { |
---|
10 | KineticFriction = 124560; // Asetetaan kitka |
---|
11 | |
---|
12 | Automobile auto = new Automobile(50, 20); |
---|
13 | auto.Mass = 2.0; |
---|
14 | auto.Color = Color.DarkRed; |
---|
15 | Add(auto); |
---|
16 | Level.CreateBorders(1.0, false); |
---|
17 | ShowControlHelp(); |
---|
18 | |
---|
19 | Vector qwerty = new Vector(50, 50); |
---|
20 | |
---|
21 | Automobile kaara = new Automobile(50, 20); |
---|
22 | kaara.Mass = 2.0; |
---|
23 | kaara.Color = Color.Green; |
---|
24 | kaara.Move(qwerty); |
---|
25 | Add(kaara); |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | { |
---|
30 | |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
37 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
38 | Keyboard.Listen(Key.Up, ButtonState.Down, kiihdyta, "Kiihdytä", auto); |
---|
39 | Keyboard.Listen(Key.Down, ButtonState.Down, jarruta, "Jarruta", auto); |
---|
40 | Keyboard.Listen(Key.Left, ButtonState.Down, kaanny, "Käänny vasemmalle", auto, Angle.Degrees(11234567)); |
---|
41 | Keyboard.Listen(Key.Right, ButtonState.Down, kaanny, "Käänny oikealle", auto, Angle.Degrees(-11234567)); |
---|
42 | |
---|
43 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
44 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
45 | Keyboard.Listen(Key.W, ButtonState.Down, kiihdyta, "Kiihdytä", kaara); |
---|
46 | Keyboard.Listen(Key.S, ButtonState.Down, jarruta, "Jarruta", kaara); |
---|
47 | Keyboard.Listen(Key.A, ButtonState.Down, kaanny, "Käänny vasemmalle",kaara,Angle.Degrees (11234567)); |
---|
48 | Keyboard.Listen(Key.D, ButtonState.Down, kaanny, "Käänny oikealle", kaara, Angle.Degrees(-11234567)); |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | void kiihdyta(Automobile kaara) |
---|
55 | { |
---|
56 | kaara.Accelerate(Time.SinceLastUpdate.TotalSeconds); |
---|
57 | } |
---|
58 | |
---|
59 | void jarruta(Automobile kaara) |
---|
60 | { |
---|
61 | kaara.Brake(Time.SinceLastUpdate.TotalSeconds); |
---|
62 | } |
---|
63 | |
---|
64 | void kaanny(Automobile kaara, Angle kaannos) |
---|
65 | { |
---|
66 | kaara.Turn(kaannos, Time.SinceLastUpdate.TotalSeconds); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | void kaasua(Automobile auto) |
---|
74 | { |
---|
75 | auto.Accelerate(Time.SinceLastUpdate.TotalSeconds); |
---|
76 | } |
---|
77 | |
---|
78 | void jarrut (Automobile auto) |
---|
79 | { |
---|
80 | auto.Brake(Time.SinceLastUpdate.TotalSeconds); |
---|
81 | } |
---|
82 | |
---|
83 | void kääntyy (Automobile auto, Angle kaannos) |
---|
84 | { |
---|
85 | auto.Turn(kaannos, Time.SinceLastUpdate.TotalSeconds); |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|