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 | Keys(); |
---|
29 | |
---|
30 | Camera.Follow(bikePhysicsObject); |
---|
31 | |
---|
32 | Wind = new Vector(-25, 0); |
---|
33 | Smoke smoke = new Smoke(); |
---|
34 | Timer smokeTimer = new Timer(); |
---|
35 | smokeTimer.Interval = 0.1; |
---|
36 | smokeTimer.Timeout += delegate { smoke.Position = bike.Objects[1].Position; }; |
---|
37 | smokeTimer.Start(); |
---|
38 | Add(smoke); |
---|
39 | |
---|
40 | } |
---|
41 | |
---|
42 | void CreateLevel() |
---|
43 | { |
---|
44 | Surface level = Surface.CreateBottom(Level, 400, 700, 200, 200); |
---|
45 | Add(level); |
---|
46 | level.Left = Screen.Left; |
---|
47 | Gravity = new Vector(0.0, -800.0); |
---|
48 | } |
---|
49 | void CreatePlayer() |
---|
50 | { |
---|
51 | leftTire = new PhysicsObject(57.5, 57.5, Shape.Circle); |
---|
52 | rightTire = new PhysicsObject(57.5, 57.5, Shape.Circle); |
---|
53 | bikePhysicsObject = new PhysicsObject(250.0, 200.0); |
---|
54 | leftTire.X = -70.0; |
---|
55 | leftTire.Y = -260.0; |
---|
56 | rightTire.X = 65.0; |
---|
57 | rightTire.Y = -260.0; |
---|
58 | bikePhysicsObject.X = 0; |
---|
59 | bikePhysicsObject.Y = -200; |
---|
60 | leftTire.Image = tire; |
---|
61 | rightTire.Image = tire; |
---|
62 | bikePhysicsObject.Image = motorbike; |
---|
63 | this.bike = new PhysicsStructure(rightTire, leftTire, bikePhysicsObject); |
---|
64 | bikePhysicsObject.IgnoresCollisionResponse = true; |
---|
65 | Add(this.bike); |
---|
66 | Add(bikePhysicsObject); |
---|
67 | bike.KineticFriction = 1.0; |
---|
68 | bike.Restitution = 0.2; |
---|
69 | bike.Y += 100; |
---|
70 | } |
---|
71 | void Keys() |
---|
72 | { |
---|
73 | Keyboard.Listen(Key.Down, ButtonState.Down, Movement, null, new Vector(-5000, 0)); |
---|
74 | Keyboard.Listen(Key.Up, ButtonState.Down, Movement, null, new Vector(5000, 0)); |
---|
75 | Keyboard.Listen(Key.Left, ButtonState.Down, ChangeAngle, null, 1.0); |
---|
76 | Keyboard.Listen(Key.Right, ButtonState.Down, ChangeAngle, null, -1.0); |
---|
77 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
78 | } |
---|
79 | void Movement(Vector movement) |
---|
80 | { |
---|
81 | if(GetObjectAt(bikePhysicsObject.Position - new Vector(0, bike.Height / 2) * 0.9, 0.1) != null) |
---|
82 | { |
---|
83 | bike.Push(movement); |
---|
84 | } |
---|
85 | } |
---|
86 | void ChangeAngle(double ammount) |
---|
87 | { |
---|
88 | bike.AngularVelocity = ammount; |
---|
89 | } |
---|
90 | |
---|
91 | } |
---|