1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | using System.Linq; |
---|
9 | public class name : PhysicsGame |
---|
10 | { |
---|
11 | |
---|
12 | Image motorbike = LoadImage("motorbike"); |
---|
13 | Image tire = LoadImage("tire"); |
---|
14 | PhysicsObject bikePhysicsObject; |
---|
15 | PhysicsObject leftTire; |
---|
16 | PhysicsObject rightTire; |
---|
17 | PhysicsStructure bike; |
---|
18 | public override void Begin() |
---|
19 | |
---|
20 | { |
---|
21 | |
---|
22 | Level.Width = Screen.Width * 25; |
---|
23 | SmoothTextures = true; |
---|
24 | IsFullScreen = false; |
---|
25 | |
---|
26 | CreatePlayer(); |
---|
27 | CreateLevel(); |
---|
28 | Timer(); |
---|
29 | Keys(); |
---|
30 | |
---|
31 | Camera.Follow(bikePhysicsObject); |
---|
32 | |
---|
33 | Wind = new Vector(-25, 0); |
---|
34 | Smoke smoke = new Smoke(); |
---|
35 | Timer smokeTimer = new Timer(); |
---|
36 | smokeTimer.Interval = 0.1; |
---|
37 | smokeTimer.Timeout += delegate { smoke.Position = bike.Objects[0].Position; }; |
---|
38 | smokeTimer.Start(); |
---|
39 | Add(smoke); |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | void Timer() |
---|
44 | { |
---|
45 | Timer timer = new Timer(); |
---|
46 | timer.Start(); |
---|
47 | |
---|
48 | Label label = new Label(); |
---|
49 | label.TextColor = Color.White; |
---|
50 | label.DecimalPlaces = 1; |
---|
51 | label.BindTo(timer.SecondCounter); |
---|
52 | Add(label); |
---|
53 | } |
---|
54 | void CreateLevel() |
---|
55 | { |
---|
56 | Surface level = Surface.CreateBottom(Level, 400, 700, 200, 200); |
---|
57 | Add(level); |
---|
58 | level.Left = Screen.Left; |
---|
59 | Gravity = new Vector(0.0, -800.0); |
---|
60 | } |
---|
61 | void CreatePlayer() |
---|
62 | { |
---|
63 | leftTire = new PhysicsObject(57.5, 57.5, Shape.Circle); |
---|
64 | rightTire = new PhysicsObject(57.5, 57.5, Shape.Circle); |
---|
65 | bikePhysicsObject = new PhysicsObject(250.0, 200.0); |
---|
66 | leftTire.X = -70.0; |
---|
67 | leftTire.Y = -260.0; |
---|
68 | rightTire.X = 65.0; |
---|
69 | rightTire.Y = -260.0; |
---|
70 | bikePhysicsObject.X = 0; |
---|
71 | bikePhysicsObject.Y = -200; |
---|
72 | leftTire.Image = tire; |
---|
73 | rightTire.Image = tire; |
---|
74 | bikePhysicsObject.Image = motorbike; |
---|
75 | this.bike = new PhysicsStructure(leftTire, rightTire, bikePhysicsObject); |
---|
76 | bikePhysicsObject.IgnoresCollisionResponse = true; |
---|
77 | Add(this.bike); |
---|
78 | Add(bikePhysicsObject); |
---|
79 | bike.KineticFriction = 1.0; |
---|
80 | bike.AngularDamping = 0.99; |
---|
81 | bike.LinearDamping = 1; |
---|
82 | bike.Restitution = 0.2; |
---|
83 | bike.Y += 100; |
---|
84 | } |
---|
85 | void Keys() |
---|
86 | { |
---|
87 | Keyboard.Listen(Key.Down, ButtonState.Down, Movement, null, new Vector(-5000, 0)); |
---|
88 | Keyboard.Listen(Key.Up, ButtonState.Down, Movement, null, new Vector(5000, 0)); |
---|
89 | Keyboard.Listen(Key.Left, ButtonState.Down, ChangeAngle, null, 1.0); |
---|
90 | Keyboard.Listen(Key.Right, ButtonState.Down, ChangeAngle, null, -1.0); |
---|
91 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
92 | } |
---|
93 | void Movement(Vector movement) |
---|
94 | { |
---|
95 | if(GetObjectAt(bikePhysicsObject.Position - new Vector(0, bike.Height / 2) * 0.9, 0.1) != null) |
---|
96 | { |
---|
97 | bike.Push(movement); |
---|
98 | } |
---|
99 | } |
---|
100 | void ChangeAngle(double ammount) |
---|
101 | { |
---|
102 | bike.AngularVelocity = ammount; |
---|
103 | } |
---|
104 | |
---|
105 | } |
---|