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 | |
---|
9 | public class name : PhysicsGame |
---|
10 | { |
---|
11 | Image motorbike = LoadImage("motorbike"); |
---|
12 | Image tire = LoadImage("tire"); |
---|
13 | PhysicsStructure tires; |
---|
14 | public override void Begin() |
---|
15 | |
---|
16 | { |
---|
17 | |
---|
18 | SmoothTextures = true; |
---|
19 | IsFullScreen = true; |
---|
20 | |
---|
21 | AddTires(); |
---|
22 | Points(); |
---|
23 | Keys(); |
---|
24 | |
---|
25 | Surface level = Surface.CreateBottom(Level, 30, 100, 10, 100); |
---|
26 | Add(level); |
---|
27 | Gravity = new Vector(0.0, -800.0); |
---|
28 | |
---|
29 | //Wind = new Vector(-25, 0); |
---|
30 | //Smoke smoke = new Smoke(); |
---|
31 | //smoke.Position = tires.Position; |
---|
32 | //Add(smoke); |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | void AddTires() |
---|
37 | { |
---|
38 | PhysicsObject leftTire = new PhysicsObject(50.0, 50.0, Shape.Circle); |
---|
39 | PhysicsObject rightTire = new PhysicsObject(50.0, 50.0, Shape.Circle); |
---|
40 | PhysicsObject bike = new PhysicsObject(200.0, 200.0); |
---|
41 | leftTire.X = -65.0; |
---|
42 | leftTire.Y = -250.0; |
---|
43 | rightTire.X = 65.0; |
---|
44 | rightTire.Y = -250.0; |
---|
45 | bike.X = 0; |
---|
46 | bike.Y = -200; |
---|
47 | leftTire.Image = tire; |
---|
48 | rightTire.Image = tire; |
---|
49 | bike.Image = motorbike; |
---|
50 | tires = new PhysicsStructure(leftTire, rightTire, bike); |
---|
51 | Add(tires); |
---|
52 | Add(bike); |
---|
53 | } |
---|
54 | void Keys() |
---|
55 | { |
---|
56 | Keyboard.Listen(Key.Down, ButtonState.Down, Movement, null, new Vector(-1000, 0)); |
---|
57 | Keyboard.Listen(Key.Up, ButtonState.Down, Movement, null, new Vector(1000, 0)); |
---|
58 | Keyboard.Listen(Key.Left, ButtonState.Down, ChangeAngle, null, 7.5); |
---|
59 | Keyboard.Listen(Key.Right, ButtonState.Down, ChangeAngle, null, -7.5); |
---|
60 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
61 | } |
---|
62 | void Movement(Vector movement) |
---|
63 | { |
---|
64 | tires.Push(movement); |
---|
65 | } |
---|
66 | void ChangeAngle(double ammount) |
---|
67 | { |
---|
68 | tires.AngularVelocity = ammount; |
---|
69 | } |
---|
70 | IntMeter pointCounter; |
---|
71 | void Points() |
---|
72 | { |
---|
73 | pointCounter = new IntMeter(0); |
---|
74 | Label pointLabel = new Label(); |
---|
75 | pointLabel.X = Screen.Left + 100; |
---|
76 | pointLabel.Y = Screen.Top - 100; |
---|
77 | pointLabel.TextColor = Color.Black; |
---|
78 | pointLabel.Color = Color.White; |
---|
79 | pointLabel.BindTo(pointCounter); |
---|
80 | Add(pointLabel); |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|