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.Globalization; |
---|
9 | |
---|
10 | namespace SFN |
---|
11 | { |
---|
12 | public class Peli : TopDownPhysicsGame |
---|
13 | { |
---|
14 | [Save] |
---|
15 | List<Auto> autot = new List<Auto>(); |
---|
16 | List<Image> autokuvat = new List<Image>(); |
---|
17 | List<int> hinnat = new List<int>(); |
---|
18 | String[] mallit = new String[4]; |
---|
19 | Label[] kauppakuvat = new Label[4]; |
---|
20 | Label number, malli, moottori, renkaat, moottorin_hinta, renkaiden_hinta, sell_price, rahat, keskiauto; |
---|
21 | Image MenuBackround, Arrow; |
---|
22 | [Save] |
---|
23 | public int ID = 0; |
---|
24 | int max_taso = 5; |
---|
25 | [Save] |
---|
26 | public double raha = 0; |
---|
27 | int ChangeColor; |
---|
28 | |
---|
29 | Automobile kaara; |
---|
30 | /*int engine = 1; |
---|
31 | int tires = 1;*/ |
---|
32 | Vector goal = new Vector(0, 0); |
---|
33 | GameObject nuoli; |
---|
34 | PhysicsObject[] kisat; |
---|
35 | Automobile[] siviilit; |
---|
36 | Vector[] kohteet; |
---|
37 | int siviilimaara; |
---|
38 | Timer kisa_aika; |
---|
39 | |
---|
40 | public override void Begin() |
---|
41 | { |
---|
42 | //Set cursos visible |
---|
43 | Mouse.IsCursorVisible = true; |
---|
44 | //Load images, set variables and more... |
---|
45 | PrepareGame(); |
---|
46 | //Create main menu |
---|
47 | CreateMenu(); |
---|
48 | |
---|
49 | //Create a car |
---|
50 | autot.Add(new Auto(mallit[0], 0, 0, 1, 1)); |
---|
51 | //autot.Add(new Auto(mallit[3], 3, 3, 5, 5)); |
---|
52 | } |
---|
53 | |
---|
54 | protected override void Update(Time time) |
---|
55 | { |
---|
56 | if (keskiauto != null) |
---|
57 | { |
---|
58 | keskiauto.Angle = keskiauto.Angle - Angle.FromDegrees(0.5); |
---|
59 | } |
---|
60 | if (nuoli != null) |
---|
61 | { |
---|
62 | nuoli.Position = kaara.Position; |
---|
63 | nuoli.Angle = (goal - kaara.Position).Angle; |
---|
64 | } |
---|
65 | if (goal != Vector.Zero && (goal - kaara.Position).Magnitude < 100) |
---|
66 | { |
---|
67 | goal = new Vector(0, 0); |
---|
68 | LuoKisat(); |
---|
69 | nuoli.IsVisible = false; |
---|
70 | raha += (1000 / kisa_aika.CurrentTime); |
---|
71 | MessageDisplay.Add("Money:" + raha); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | void PrepareGame() |
---|
76 | { |
---|
77 | //Load resources |
---|
78 | LoadResources(); |
---|
79 | |
---|
80 | //Set cars price |
---|
81 | hinnat.Add(5000); //Car 0 Price |
---|
82 | hinnat.Add(5200); //Car 1 Price |
---|
83 | hinnat.Add(20000); //Car 2 Price |
---|
84 | hinnat.Add(21000); //Car 3 Price |
---|
85 | |
---|
86 | //Set model names |
---|
87 | mallit[0] = "Model0"; //Car 0 Price |
---|
88 | mallit[1] = "Model1"; //Car 1 Price |
---|
89 | mallit[2] = "Model2"; //Car 2 Price |
---|
90 | mallit[3] = "Model3"; //Car 3 Price |
---|
91 | |
---|
92 | kisa_aika = new Timer(); |
---|
93 | MessageDisplay.TextColor = Color.Yellow; |
---|
94 | Gravity = 200; |
---|
95 | KineticFriction = 10; |
---|
96 | goal = Vector.Zero; |
---|
97 | } |
---|
98 | |
---|
99 | void LoadResources() |
---|
100 | { |
---|
101 | //Load menu backround |
---|
102 | MenuBackround = LoadImage("MenuBackround"); |
---|
103 | |
---|
104 | //Load arrow |
---|
105 | Arrow = LoadImage("Arrow"); |
---|
106 | |
---|
107 | //Load car images in loop |
---|
108 | for (int i = 0; i < 4; i += 1) |
---|
109 | { |
---|
110 | autokuvat.Add(LoadImage("Whites\\Car" + (i + 1))); |
---|
111 | autokuvat.Add(LoadImage("Blues\\Car" + (i + 1))); |
---|
112 | autokuvat.Add(LoadImage("Greens\\Car" + (i + 1))); |
---|
113 | autokuvat.Add(LoadImage("Reds\\Car" + (i + 1))); |
---|
114 | autokuvat.Add(LoadImage("Yellows\\Car" + (i + 1))); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | void CreateMenu() |
---|
119 | { |
---|
120 | //Set menu backround |
---|
121 | Level.Background.Image = MenuBackround; |
---|
122 | |
---|
123 | //Quit game button |
---|
124 | PushButton quit_game = new PushButton("Quit game"); |
---|
125 | quit_game.Clicked += new Action(quit_game_Clicked); |
---|
126 | quit_game.Position = new Vector(380.0, -50.0); |
---|
127 | Add(quit_game); |
---|
128 | |
---|
129 | //Load game button |
---|
130 | PushButton load_game = new PushButton("Load game"); |
---|
131 | load_game.Clicked += new Action(load_game_Clicked); |
---|
132 | load_game.Position = new Vector(200.0, -50.0); |
---|
133 | Add(load_game); |
---|
134 | |
---|
135 | //New game button |
---|
136 | PushButton new_game = new PushButton("New game"); |
---|
137 | new_game.Clicked += new Action(new_game_Clicked); |
---|
138 | new_game.Position = new Vector(20.0, -50.0); |
---|
139 | Add(new_game); |
---|
140 | } |
---|
141 | |
---|
142 | void new_game_Clicked() |
---|
143 | { |
---|
144 | ClearAll(); |
---|
145 | Keyboard.Listen(Key.Space, ButtonState.Released, GoToShop, null); |
---|
146 | //Sekalaista säätöä |
---|
147 | Level.Background.Image = null; |
---|
148 | Level.BackgroundColor = Color.LightGray; |
---|
149 | Camera.ZoomFactor = 0.4; |
---|
150 | |
---|
151 | //Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); |
---|
152 | //Window.AllowUserResizing = true; |
---|
153 | |
---|
154 | |
---|
155 | LuoKisat(); |
---|
156 | |
---|
157 | //Kontrollit |
---|
158 | Keyboard.Listen(Key.Up, ButtonState.Down, kaasu, null); |
---|
159 | Keyboard.Listen(Key.Left, ButtonState.Down, rattiV, null); |
---|
160 | Keyboard.Listen(Key.Right, ButtonState.Down, rattiO, null); |
---|
161 | Keyboard.Listen(Key.Down, ButtonState.Down, pakki, null); |
---|
162 | Keyboard.Listen(Key.RightControl, ButtonState.Down, jarru, null); |
---|
163 | Keyboard.Listen(Key.Tab, ButtonState.Released, rahatShow, null); |
---|
164 | |
---|
165 | //Auton kanssa säätöä |
---|
166 | kaara = new Automobile(100, 50); |
---|
167 | Camera.FollowedObject = kaara; |
---|
168 | kaara.TopSpeed = autot[ID].moottori * 75; |
---|
169 | kaara.Acceleration = autot[ID].moottori * 50; |
---|
170 | kaara.KineticFriction = 0.999; |
---|
171 | kaara.Maneuverability = Angle.FromDegrees(autot[ID].renkaat * 5); |
---|
172 | kaara.BrakeDeceleration = autot[ID].renkaat * 200; |
---|
173 | kaara.Image = autokuvat[(autot[ID].kori * 5) + (autot[ID].vari)]; |
---|
174 | kaara.X = Level.Left + 150; |
---|
175 | kaara.MomentOfInertia = 10000; |
---|
176 | kaara.LinearDamping = 0.9999; |
---|
177 | kaara.Mass = 10000; |
---|
178 | kaara.AngularDamping = 0.95; |
---|
179 | Add(kaara); |
---|
180 | |
---|
181 | nuoli = new GameObject(30, 30); |
---|
182 | nuoli.Color = Color.Green; |
---|
183 | nuoli.Shape = Shape.Triangle; |
---|
184 | nuoli.Image = Arrow; |
---|
185 | nuoli.IsVisible = false; |
---|
186 | Add(nuoli); |
---|
187 | |
---|
188 | //Turvatalo |
---|
189 | PhysicsObject Turva = PhysicsObject.CreateStaticObject(50, 50); |
---|
190 | Turva.Color = Color.Red; |
---|
191 | Turva.Shape = Shape.Circle; |
---|
192 | Turva.X = Level.Left + 60; |
---|
193 | Turva.Tag = "TT"; |
---|
194 | Add(Turva); |
---|
195 | |
---|
196 | //Kartan lataus |
---|
197 | /*TileMap World = TileMap.FromFile("Map.txt"); |
---|
198 | World.SetTileMethod('A', taloA); |
---|
199 | World.SetTileMethod('B', taloB); |
---|
200 | World.SetTileMethod('C', taloC); |
---|
201 | World.Execute(150,150);*/ |
---|
202 | |
---|
203 | AddCollisionHandler(kaara, KasitteleKaaranTormays); |
---|
204 | LuoSiviilit(); |
---|
205 | } |
---|
206 | |
---|
207 | void load_game_Clicked() |
---|
208 | { |
---|
209 | if ((DataStorage.Exists("autot.xml")) == true && (DataStorage.Exists("doublet.xml")) == true && (DataStorage.Exists("intit.xml")) == true) |
---|
210 | { |
---|
211 | autot = DataStorage.Load<List<Auto>>(autot, "autot.xml"); |
---|
212 | ID = DataStorage.Load<int>(ID, "intit.xml"); |
---|
213 | raha = DataStorage.Load<double>(raha, "doublet.xml"); |
---|
214 | |
---|
215 | GoToShop(); |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | ShowMessage("Game not loaded", "Save files does not exist."); |
---|
220 | } |
---|
221 | |
---|
222 | } |
---|
223 | |
---|
224 | void quit_game_Clicked() |
---|
225 | { |
---|
226 | Exit(); |
---|
227 | } |
---|
228 | |
---|
229 | void GoToShop() |
---|
230 | { |
---|
231 | Save(); |
---|
232 | //Clear all |
---|
233 | ClearAll(); |
---|
234 | //Zoom camera to level |
---|
235 | Camera.ZoomToLevel(); |
---|
236 | //Set level backround color light gray |
---|
237 | Level.BackgroundColor = Color.LightGray; |
---|
238 | |
---|
239 | //Ylapallki |
---|
240 | Label ylapalkki = new Label(Screen.Width, Screen.Height / 15); |
---|
241 | ylapalkki.Color = Color.SkyBlue; |
---|
242 | ylapalkki.Position = new Vector(0, Screen.Top - (ylapalkki.Height / 2)); |
---|
243 | Add(ylapalkki); |
---|
244 | |
---|
245 | //Alapalkki |
---|
246 | Label alapalkki = new Label(Screen.Width, Screen.Height / 4); |
---|
247 | alapalkki.Color = Color.SkyBlue; |
---|
248 | alapalkki.Position = new Vector(0, Screen.Bottom + (alapalkki.Height / 2)); |
---|
249 | Add(alapalkki); |
---|
250 | |
---|
251 | //Oikea reuna |
---|
252 | Label oikeareuna = new Label(Screen.Width / 6, Screen.Height); |
---|
253 | oikeareuna.Color = Color.SkyBlue; |
---|
254 | oikeareuna.Position = new Vector(Screen.Right - oikeareuna.Width / 2, 0); |
---|
255 | Add(oikeareuna); |
---|
256 | |
---|
257 | |
---|
258 | //Next button |
---|
259 | PushButton nextid = new PushButton("-->"); |
---|
260 | nextid.Position = new Vector(Screen.Right * 0.9, ylapalkki.Y); //Level.Right + 80, Level.Top + 60 |
---|
261 | nextid.Clicked += new Action(nextid_Clicked); |
---|
262 | Add(nextid); |
---|
263 | |
---|
264 | //Previous button |
---|
265 | PushButton previousid = new PushButton("<--"); |
---|
266 | previousid.Position = new Vector(Screen.Right * 0.65, ylapalkki.Y); //Level.Right - 80, Level.Top + 60 |
---|
267 | previousid.Clicked += new Action(previousid_Clicked); |
---|
268 | Add(previousid); |
---|
269 | |
---|
270 | //Update engine |
---|
271 | PushButton update_engine = new PushButton("Update engine"); |
---|
272 | update_engine.Position = new Vector(oikeareuna.X, Screen.Top * 0.75); |
---|
273 | update_engine.Clicked += new Action(update_engine_Clicked); |
---|
274 | Add(update_engine); |
---|
275 | |
---|
276 | //Update tiers |
---|
277 | PushButton update_tiers = new PushButton("Update tiers"); |
---|
278 | update_tiers.Position = new Vector(oikeareuna.X, Screen.Top * 0.52); |
---|
279 | update_tiers.Clicked += new Action(update_tiers_Clicked); |
---|
280 | Add(update_tiers); |
---|
281 | |
---|
282 | //Leave safehouse |
---|
283 | PushButton drive = new PushButton("Leave safehouse"); |
---|
284 | drive.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.4); |
---|
285 | drive.Clicked += new Action(drive_Clicked); |
---|
286 | Add(drive); |
---|
287 | |
---|
288 | //Sell car |
---|
289 | PushButton sell = new PushButton("Sell car"); |
---|
290 | sell.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.2); |
---|
291 | sell.Clicked += new Action(sell_Clicked); |
---|
292 | Add(sell); |
---|
293 | |
---|
294 | //Show selected car number of maximum |
---|
295 | number = new Label((ID + 1).ToString() + "/" + autot.Count.ToString()); |
---|
296 | number.Position = new Vector(Screen.Right * 0.78, ylapalkki.Y); |
---|
297 | Add(number); |
---|
298 | |
---|
299 | //Show car model |
---|
300 | malli = new Label(autot[ID].korinnimi.ToString()); |
---|
301 | malli.Position = new Vector(Screen.Left * 0.9, ylapalkki.Y); |
---|
302 | Add(malli); |
---|
303 | |
---|
304 | //Show engine level |
---|
305 | moottori = new Label("Engine: " + autot[ID].moottori.ToString()); |
---|
306 | moottori.Position = new Vector(Screen.Left * 0.5, ylapalkki.Y); |
---|
307 | Add(moottori); |
---|
308 | |
---|
309 | //Show money |
---|
310 | string RahaString; |
---|
311 | if (raha > 9) |
---|
312 | { |
---|
313 | RahaString = raha.ToString("0,0", CultureInfo.InvariantCulture); |
---|
314 | } |
---|
315 | else |
---|
316 | { |
---|
317 | RahaString = raha.ToString(); |
---|
318 | } |
---|
319 | rahat = new Label("Money: " + RahaString.ToString()); |
---|
320 | rahat.Position = new Vector(oikeareuna.X, 0); |
---|
321 | Add(rahat); |
---|
322 | |
---|
323 | //Show car sell price |
---|
324 | double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); |
---|
325 | sell_price = new Label("Sell price: " + hinta.ToString("0,0", CultureInfo.InvariantCulture)); |
---|
326 | sell_price.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.28); |
---|
327 | Add(sell_price); |
---|
328 | |
---|
329 | //Show tiers level |
---|
330 | renkaat = new Label("Tiers: " + autot[ID].renkaat.ToString()); |
---|
331 | renkaat.Position = new Vector(Screen.Left * 0.05, ylapalkki.Y); |
---|
332 | Add(renkaat); |
---|
333 | |
---|
334 | //Show updated engine price |
---|
335 | moottorin_hinta = new Label("Price: " + (autot[ID].moottori * 100).ToString("0,0", CultureInfo.InvariantCulture)); |
---|
336 | moottorin_hinta.Position = new Vector(oikeareuna.X, Screen.Top * 0.65); |
---|
337 | Add(moottorin_hinta); |
---|
338 | |
---|
339 | //Show updated tiers price |
---|
340 | renkaiden_hinta = new Label("Price: " + (autot[ID].renkaat * 100).ToString("0,0", CultureInfo.InvariantCulture)); |
---|
341 | renkaiden_hinta.Position = new Vector(oikeareuna.X, Screen.Top * 0.4); |
---|
342 | Add(renkaiden_hinta); |
---|
343 | |
---|
344 | //Change cars color |
---|
345 | //Green |
---|
346 | PushButton vihrea = new PushButton(""); |
---|
347 | vihrea.Color = Color.Green; |
---|
348 | vihrea.Size = new Vector(50, 50); |
---|
349 | vihrea.Position = new Vector(Screen.Right * 0.9, Screen.Bottom * 0.9); |
---|
350 | vihrea.Clicked += new Action(vihrea_Clicked); |
---|
351 | Add(vihrea); |
---|
352 | |
---|
353 | //Blue |
---|
354 | PushButton sininen = new PushButton(""); |
---|
355 | sininen.Color = Color.Blue; |
---|
356 | sininen.Size = new Vector(50, 50); |
---|
357 | sininen.Position = new Vector(Screen.Right * 0.8, Screen.Bottom * 0.9); |
---|
358 | sininen.Clicked += new Action(sininen_Clicked); |
---|
359 | Add(sininen); |
---|
360 | |
---|
361 | //Red |
---|
362 | PushButton punainen = new PushButton(""); |
---|
363 | punainen.Color = Color.Red; |
---|
364 | punainen.Size = new Vector(50, 50); |
---|
365 | punainen.Position = new Vector(Screen.Right * 0.9, Screen.Bottom * 0.78); |
---|
366 | punainen.Clicked += new Action(punainen_Clicked); |
---|
367 | Add(punainen); |
---|
368 | |
---|
369 | //Yellow |
---|
370 | PushButton keltainen = new PushButton(""); |
---|
371 | keltainen.Color = Color.Yellow; |
---|
372 | keltainen.Size = new Vector(50, 50); |
---|
373 | keltainen.Position = new Vector(Screen.Right * 0.8, Screen.Bottom * 0.78); |
---|
374 | keltainen.Clicked += new Action(keltainen_Clicked); |
---|
375 | Add(keltainen); |
---|
376 | |
---|
377 | //White |
---|
378 | PushButton valkoinen = new PushButton("White"); |
---|
379 | valkoinen.Clicked += new Action(valkoinen_Clicked); |
---|
380 | valkoinen.Color = Color.White; |
---|
381 | valkoinen.Size = new Vector(118, 50); |
---|
382 | valkoinen.Position = new Vector(Screen.Right * 0.85, Screen.Bottom * 0.66); |
---|
383 | Add(valkoinen); |
---|
384 | |
---|
385 | |
---|
386 | //Create cars images, prices and buy buttons |
---|
387 | double kerroin = 0.85; |
---|
388 | int kuvaindeksilaskuri = 0; |
---|
389 | for (int i = 0; i < 4; i++) |
---|
390 | { |
---|
391 | kauppakuvat[i] = new Label(40, 20); |
---|
392 | kauppakuvat[i].Image = autokuvat[0 + kuvaindeksilaskuri]; |
---|
393 | kauppakuvat[i].Position = new Vector(Screen.Left * kerroin, alapalkki.Y + alapalkki.Height * 0.2); |
---|
394 | Add(kauppakuvat[i]); |
---|
395 | |
---|
396 | PushButton nappi = new PushButton("Buy"); |
---|
397 | nappi.Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.2); |
---|
398 | int temp = i; |
---|
399 | nappi.Clicked += new Action(delegate { BuyCar(temp); }); |
---|
400 | Add(nappi); |
---|
401 | |
---|
402 | Label teksti = new Label("Price: " + hinnat[i].ToString("0,0", CultureInfo.InvariantCulture)); |
---|
403 | teksti.Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.05); |
---|
404 | Add(teksti); |
---|
405 | |
---|
406 | kuvaindeksilaskuri += 5; |
---|
407 | kerroin -= 0.3; |
---|
408 | } |
---|
409 | |
---|
410 | //Create rotating car in center area |
---|
411 | keskiauto = new Label(40 * 2, 20 * 2); |
---|
412 | keskiauto.Image = autokuvat[(autot[ID].kori * 5) + (autot[ID].vari)]; |
---|
413 | keskiauto.Position = new Vector(0 - oikeareuna.Width / 2, 0 + alapalkki.Height / 2 - ylapalkki.Height / 2); |
---|
414 | Add(keskiauto); |
---|
415 | } |
---|
416 | |
---|
417 | void valkoinen_Clicked() |
---|
418 | { |
---|
419 | //White |
---|
420 | ChangeColor = 0; |
---|
421 | ChangeCarColor(); |
---|
422 | } |
---|
423 | |
---|
424 | void keltainen_Clicked() |
---|
425 | { |
---|
426 | //Yellow |
---|
427 | ChangeColor = 4; |
---|
428 | ChangeCarColor(); |
---|
429 | } |
---|
430 | |
---|
431 | void punainen_Clicked() |
---|
432 | { |
---|
433 | //Red |
---|
434 | ChangeColor = 3; |
---|
435 | ChangeCarColor(); |
---|
436 | } |
---|
437 | |
---|
438 | void sininen_Clicked() |
---|
439 | { |
---|
440 | //Blue |
---|
441 | ChangeColor = 1; |
---|
442 | ChangeCarColor(); |
---|
443 | } |
---|
444 | |
---|
445 | void vihrea_Clicked() |
---|
446 | { |
---|
447 | //Green |
---|
448 | ChangeColor = 2; |
---|
449 | ChangeCarColor(); |
---|
450 | } |
---|
451 | |
---|
452 | void ChangeCarColor() |
---|
453 | { |
---|
454 | //Change all cars color |
---|
455 | kauppakuvat[0].Image = autokuvat[ChangeColor]; |
---|
456 | kauppakuvat[1].Image = autokuvat[ChangeColor + 5]; |
---|
457 | kauppakuvat[2].Image = autokuvat[ChangeColor + 10]; |
---|
458 | kauppakuvat[3].Image = autokuvat[ChangeColor + 15]; |
---|
459 | } |
---|
460 | |
---|
461 | void BuyCar(int indeksi) |
---|
462 | { |
---|
463 | //Buy car if enought money |
---|
464 | if (raha >= hinnat[indeksi]) |
---|
465 | { |
---|
466 | raha -= hinnat[indeksi]; |
---|
467 | autot.Add(new Auto(mallit[indeksi], ChangeColor, indeksi, 1, 1)); |
---|
468 | ID = autot.Count - 1; |
---|
469 | UpdateHUD(); |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | ShowMessage("Car not bought", "You don't have enough money."); |
---|
474 | } |
---|
475 | } |
---|
476 | |
---|
477 | void ShowMessage(string Title, string Message) |
---|
478 | { |
---|
479 | //Show message |
---|
480 | MessageWindow message = new MessageWindow(Title, Message); |
---|
481 | Add(message); |
---|
482 | } |
---|
483 | |
---|
484 | void UpdateHUD() |
---|
485 | { |
---|
486 | //Update game HUD |
---|
487 | double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); |
---|
488 | sell_price.Text = "Sell price: " + hinta.ToString("0,0", CultureInfo.InvariantCulture); |
---|
489 | malli.Text = autot[ID].korinnimi.ToString(); |
---|
490 | moottori.Text = "Engine: " + autot[ID].moottori.ToString(); |
---|
491 | renkaat.Text = "Tiers: " + autot[ID].renkaat.ToString(); |
---|
492 | number.Text = (ID + 1).ToString() + "/" + autot.Count.ToString(); |
---|
493 | moottorin_hinta.Text = "Price: " + (autot[ID].moottori * 100).ToString("0,0", CultureInfo.InvariantCulture); |
---|
494 | renkaiden_hinta.Text = "Price: " + (autot[ID].renkaat * 100).ToString("0,0", CultureInfo.InvariantCulture); |
---|
495 | keskiauto.Image = autokuvat[(autot[ID].kori * 5) + (autot[ID].vari)]; |
---|
496 | |
---|
497 | if (raha > 9) |
---|
498 | { |
---|
499 | rahat.Text = "Money: " + raha.ToString("0,0", CultureInfo.InvariantCulture); |
---|
500 | } |
---|
501 | else |
---|
502 | { |
---|
503 | rahat.Text = "Money: " + raha.ToString(); |
---|
504 | } |
---|
505 | } |
---|
506 | |
---|
507 | void previousid_Clicked() |
---|
508 | { |
---|
509 | //Previous car ID |
---|
510 | ID = (--ID + autot.Count) % autot.Count; |
---|
511 | UpdateHUD(); |
---|
512 | } |
---|
513 | |
---|
514 | void nextid_Clicked() |
---|
515 | { |
---|
516 | //Next car ID |
---|
517 | ID = ++ID % autot.Count; |
---|
518 | UpdateHUD(); |
---|
519 | } |
---|
520 | |
---|
521 | void update_tiers_Clicked() |
---|
522 | { |
---|
523 | //Calculate tiers price and continue it if enought money |
---|
524 | int hinta = autot[ID].renkaat * 100; |
---|
525 | if (raha >= hinta) |
---|
526 | { |
---|
527 | //Buy tiers if level is not maximum |
---|
528 | if (autot[ID].renkaat < max_taso) |
---|
529 | { |
---|
530 | raha = raha - hinta; |
---|
531 | autot[ID].renkaat += 1; |
---|
532 | } |
---|
533 | else |
---|
534 | { |
---|
535 | ShowMessage("Tiers not upgradet", "Your tiers are at maximum level."); |
---|
536 | } |
---|
537 | } |
---|
538 | else |
---|
539 | { |
---|
540 | ShowMessage("Tiers not upgradet", "You don't have enough money."); |
---|
541 | } |
---|
542 | UpdateHUD(); |
---|
543 | } |
---|
544 | |
---|
545 | void update_engine_Clicked() |
---|
546 | { |
---|
547 | //Calculate engine price and continue it if enought money |
---|
548 | int hinta = autot[ID].moottori * 100; |
---|
549 | if (raha >= hinta) |
---|
550 | { |
---|
551 | //Buy engine if level is not maximum |
---|
552 | if (autot[ID].moottori < max_taso) |
---|
553 | { |
---|
554 | raha = raha - hinta; |
---|
555 | autot[ID].moottori += 1; |
---|
556 | } |
---|
557 | else |
---|
558 | { |
---|
559 | ShowMessage("Engine not upgradet", "Your engine is at maximum level."); |
---|
560 | } |
---|
561 | } |
---|
562 | else |
---|
563 | { |
---|
564 | ShowMessage("Engine not upgradet", "You don't have enough money."); |
---|
565 | } |
---|
566 | UpdateHUD(); |
---|
567 | } |
---|
568 | |
---|
569 | void sell_Clicked() |
---|
570 | { |
---|
571 | //Sell car if player have more cars |
---|
572 | if (autot.Count > 1) |
---|
573 | { |
---|
574 | double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); |
---|
575 | autot.RemoveAt(ID); |
---|
576 | raha = raha + hinta; |
---|
577 | ID = ++ID % autot.Count; |
---|
578 | UpdateHUD(); |
---|
579 | } |
---|
580 | else |
---|
581 | { |
---|
582 | ShowMessage("Car not sold", "You can't sell your last car."); |
---|
583 | } |
---|
584 | } |
---|
585 | |
---|
586 | void LuoKisat() |
---|
587 | { |
---|
588 | kisat = new PhysicsObject[1]; |
---|
589 | |
---|
590 | kisat[0] = PhysicsObject.CreateStaticObject(50, 50); |
---|
591 | kisat[0].Shape = Shape.Circle; |
---|
592 | kisat[0].Color = Color.Blue; |
---|
593 | kisat[0].X = 0; |
---|
594 | kisat[0].Y = 200; |
---|
595 | kisat[0].Tag = "0"; |
---|
596 | Add(kisat[0]); |
---|
597 | |
---|
598 | } |
---|
599 | public void rahatShow() |
---|
600 | { |
---|
601 | MessageDisplay.Add("Money:" + raha); |
---|
602 | } |
---|
603 | |
---|
604 | public void kaasu() |
---|
605 | { |
---|
606 | kaara.Accelerate(Time.SinceLastUpdate.TotalSeconds); |
---|
607 | } |
---|
608 | public void rattiV() |
---|
609 | { |
---|
610 | if (kaara.Velocity.Magnitude > 1) { kaara.Turn(Angle.FromDegrees(1), Time.SinceLastUpdate.TotalSeconds); } |
---|
611 | } |
---|
612 | public void rattiO() |
---|
613 | { |
---|
614 | if (kaara.Velocity.Magnitude > 1) { kaara.Turn(Angle.FromDegrees(-1), Time.SinceLastUpdate.TotalSeconds); } |
---|
615 | } |
---|
616 | public void jarru() |
---|
617 | { |
---|
618 | if (kaara.Velocity.Magnitude > 1) { kaara.Brake(Time.SinceLastUpdate.TotalSeconds); } |
---|
619 | } |
---|
620 | public void pakki() |
---|
621 | { |
---|
622 | if (kaara.Velocity.Magnitude > 1) { kaara.Brake(Time.SinceLastUpdate.TotalSeconds); } |
---|
623 | else if (kaara.Velocity.Magnitude < 1) |
---|
624 | { |
---|
625 | Vector matti = Vector.FromLengthAndAngle(kaara.Mass * 5000, kaara.Angle + Angle.FromDegrees(180)); |
---|
626 | kaara.Push(matti); |
---|
627 | |
---|
628 | } |
---|
629 | } |
---|
630 | |
---|
631 | void KasitteleKaaranTormays(PhysicsObject kaara, PhysicsObject kohde) |
---|
632 | { |
---|
633 | if (kohde.Tag.ToString() == "TT") |
---|
634 | { |
---|
635 | GoToShop(); |
---|
636 | } |
---|
637 | if (kohde.Tag.ToString() == "0") |
---|
638 | { |
---|
639 | goal = new Vector(1, 1); |
---|
640 | nuoli.IsVisible = true; |
---|
641 | nuoli.Angle = goal.Angle + Angle.FromDegrees(180); |
---|
642 | for (int i = 0; i < kisat.Length; i++) { kisat[i].Destroy(); } |
---|
643 | kisa_aika.Interval = 2; |
---|
644 | kisa_aika.Trigger += Loss; |
---|
645 | kisa_aika.Start(); |
---|
646 | } |
---|
647 | } |
---|
648 | |
---|
649 | void LuoSiviilit() |
---|
650 | { |
---|
651 | siviilit = new Automobile[1]; |
---|
652 | kohteet = new Vector[1]; |
---|
653 | siviilit[0] = new Automobile(100, 50); |
---|
654 | siviilit[0].X = -800; |
---|
655 | siviilit[0].Y = 0; |
---|
656 | siviilit[0].Angle = Angle.FromDegrees(0); |
---|
657 | Add(siviilit[0]); |
---|
658 | siviilit[0].Accelerate(100); |
---|
659 | AddCollisionHandler(siviilit[0], Siviiliuhri); |
---|
660 | |
---|
661 | siviilimaara = 1; |
---|
662 | } |
---|
663 | |
---|
664 | void Siviiliuhri(PhysicsObject siviili, PhysicsObject kohde) |
---|
665 | { |
---|
666 | if (kohde != kaara) |
---|
667 | { |
---|
668 | siviilimaara -= 1; |
---|
669 | siviili.Destroy(); |
---|
670 | if (siviilimaara == 0) { LuoSiviilit(); } |
---|
671 | } |
---|
672 | } |
---|
673 | |
---|
674 | void Loss(Timer sender) |
---|
675 | { |
---|
676 | for (int i = 0; i < kisat.Length; i++) { kisat[i].Destroy(); } |
---|
677 | LuoKisat(); |
---|
678 | nuoli.IsVisible = false; |
---|
679 | sender.Stop(); |
---|
680 | } |
---|
681 | |
---|
682 | void drive_Clicked() |
---|
683 | { |
---|
684 | Save(); |
---|
685 | new_game_Clicked(); |
---|
686 | } |
---|
687 | |
---|
688 | void Save() |
---|
689 | { |
---|
690 | DataStorage.Save<List<Auto>>(autot, "autot.xml"); |
---|
691 | DataStorage.Save<int>(ID, "intit.xml"); |
---|
692 | DataStorage.Save<double>(raha, "doublet.xml"); |
---|
693 | } |
---|
694 | } |
---|
695 | } |
---|