source: 2011/26/JuhoK/SFN_New/SFN/SFN/SFN/Peli.cs @ 2409

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