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 Peli : TopDownPhysicsGame |
---|
10 | { |
---|
11 | Automobile kaara; |
---|
12 | int engine = 100; |
---|
13 | int tires = 100; |
---|
14 | PushButton new_game, load_game, quit_game; |
---|
15 | |
---|
16 | Image MenuBackround = LoadImage("MenuBackround"); |
---|
17 | public override void Begin() |
---|
18 | { |
---|
19 | Gravity = 200; |
---|
20 | KineticFriction = 10; |
---|
21 | Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); |
---|
22 | Mouse.IsCursorVisible = true; |
---|
23 | CreateMenu(); |
---|
24 | } |
---|
25 | |
---|
26 | void CreateMenu() |
---|
27 | { |
---|
28 | |
---|
29 | //Set menu backround |
---|
30 | Level.Background.Image = MenuBackround; |
---|
31 | |
---|
32 | //Quit game button |
---|
33 | quit_game = new PushButton("Quit game"); |
---|
34 | quit_game.Clicked += new Action(quit_game_Clicked); |
---|
35 | quit_game.Position = new Vector(380.0, -50.0); |
---|
36 | Add(quit_game); |
---|
37 | |
---|
38 | //Load game button |
---|
39 | load_game = new PushButton("Load game"); |
---|
40 | load_game.Clicked += new Action(load_game_Clicked); |
---|
41 | load_game.Position = new Vector(200.0, -50.0); |
---|
42 | Add(load_game); |
---|
43 | |
---|
44 | //New game button |
---|
45 | new_game = new PushButton("New game"); |
---|
46 | new_game.Clicked += new Action(new_game_Clicked); |
---|
47 | new_game.Position = new Vector(20.0, -50.0); |
---|
48 | Add(new_game); |
---|
49 | } |
---|
50 | |
---|
51 | void new_game_Clicked() |
---|
52 | { |
---|
53 | //Sekalaista säätöä |
---|
54 | Level.Background.Image = null; |
---|
55 | Level.BackgroundColor = Color.LightGray; |
---|
56 | Camera.ZoomFactor = 0.3; |
---|
57 | new_game.Destroy(); |
---|
58 | load_game.Destroy(); |
---|
59 | quit_game.Destroy(); |
---|
60 | Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); |
---|
61 | Window.AllowUserResizing = true; |
---|
62 | kaara = new Automobile(100, 50); |
---|
63 | Add(kaara); |
---|
64 | Mouse.IsCursorVisible = true; |
---|
65 | Keyboard.Listen(Key.Up, ButtonState.Down, kaasu, null); |
---|
66 | Keyboard.Listen(Key.Left, ButtonState.Down, rattiV, null); |
---|
67 | Keyboard.Listen(Key.Right, ButtonState.Down, rattiO, null); |
---|
68 | Keyboard.Listen(Key.Down, ButtonState.Down, jarru, null); |
---|
69 | Keyboard.Listen(Key.RightControl, ButtonState.Down, jarru, null); |
---|
70 | Camera.FollowedObject = kaara; |
---|
71 | kaara.TopSpeed = engine * 100; |
---|
72 | kaara.Acceleration = engine * 10; |
---|
73 | kaara.KineticFriction = tires * 10; |
---|
74 | kaara.StaticFriction = tires * 10; |
---|
75 | kaara.Maneuverability = Angle.FromDegrees(tires); |
---|
76 | kaara.BrakeDeceleration = tires * 20; |
---|
77 | kaara.Image = LoadImage("Sporttinen2"); |
---|
78 | kaara.X = Level.Left + 50; |
---|
79 | kaara.MomentOfInertia = 1000; |
---|
80 | kaara.LinearDamping = 0.99; |
---|
81 | kaara.Mass = 1000; |
---|
82 | kaara.AngularDamping = 0.95; |
---|
83 | |
---|
84 | //Kartan lataus |
---|
85 | TileMap World = TileMap.FromFile("Map.txt"); |
---|
86 | World.SetTileMethod('A', taloA); |
---|
87 | World.SetTileMethod('B', taloB); |
---|
88 | World.SetTileMethod('C', taloC); |
---|
89 | World.Execute(101,101); |
---|
90 | } |
---|
91 | |
---|
92 | void load_game_Clicked() |
---|
93 | { |
---|
94 | MessageDisplay.Add("Can't load game. Game save system not availible."); |
---|
95 | } |
---|
96 | |
---|
97 | void quit_game_Clicked() |
---|
98 | { |
---|
99 | //Crediittejä tänne? |
---|
100 | Exit(); |
---|
101 | } |
---|
102 | |
---|
103 | public void kaasu() |
---|
104 | { |
---|
105 | kaara.Accelerate(Time.SinceLastUpdate.TotalSeconds); |
---|
106 | } |
---|
107 | public void rattiV() |
---|
108 | { |
---|
109 | if (kaara.Velocity.Magnitude > 1) { kaara.Turn(Angle.FromDegrees(1), Time.SinceLastUpdate.TotalSeconds); } |
---|
110 | } |
---|
111 | public void rattiO() |
---|
112 | { |
---|
113 | if (kaara.Velocity.Magnitude > 1) { kaara.Turn(Angle.FromDegrees(-1), Time.SinceLastUpdate.TotalSeconds); } |
---|
114 | } |
---|
115 | public void jarru() |
---|
116 | { |
---|
117 | if (kaara.Velocity.Magnitude > 1) {kaara.Brake(Time.SinceLastUpdate.TotalSeconds);} |
---|
118 | } |
---|
119 | |
---|
120 | //Talot |
---|
121 | void taloA(Vector paikka, double leveys, double korkeus) |
---|
122 | { |
---|
123 | PhysicsObject talo = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
124 | talo.Position = paikka; |
---|
125 | talo.Image = LoadImage("Talo1"); |
---|
126 | Add(talo); |
---|
127 | } |
---|
128 | void taloB(Vector paikka, double leveys, double korkeus) |
---|
129 | { |
---|
130 | PhysicsObject talo = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
131 | talo.Position = paikka; |
---|
132 | talo.Image = LoadImage("Talo2"); |
---|
133 | Add(talo); |
---|
134 | } |
---|
135 | void taloC(Vector paikka, double leveys, double korkeus) |
---|
136 | { |
---|
137 | PhysicsObject talo = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
138 | talo.Position = paikka; |
---|
139 | talo.Image = LoadImage("Talo3"); |
---|
140 | Add(talo); |
---|
141 | } |
---|
142 | } |
---|