- Timestamp:
- 2010-07-29 14:52:47 (13 years ago)
- Location:
- 2010/30/lijiolva/Teh Bus Game
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/lijiolva/Teh Bus Game/Ohjelma.cs
r1364 r1409 7 7 using (Peli game = new Peli()) 8 8 { 9 #if !DEBUG10 game.IsFullScreen = true;11 #endif9 //#if !DEBUG 10 // game.IsFullScreen = true; 11 //#endif 12 12 game.Run(); 13 13 } -
2010/30/lijiolva/Teh Bus Game/Peli.cs
r1378 r1409 3 3 using Jypeli.Widgets; 4 4 using Jypeli.Assets; 5 using System.Collections.Generic; 5 6 6 7 public class Peli : TopDownPhysicsGame 7 8 { 8 PhysicsObject auto = new PhysicsObject(40, 20); 9 Vector Vektori = new Vector() ; 9 Vector Vektori = new Vector(); 10 List<Vector> bussinReitti; 11 List<GameObject> bussiReitinPisteet; 12 GameObject viimeisinPisteAlla; 13 PhysicsObject bussi; 14 int minuutti = 0; 15 int tunti = 0; 16 int id = 0; 17 18 bool onkoPisteAlla; 19 10 20 protected override void Begin() 11 21 { 22 bussinReitti = new List<Vector>(); 23 bussiReitinPisteet = new List<GameObject>(); 12 24 KineticFriction = 0.8; // Asetetaan kitka 13 LuoTalo(100, 60); 14 auto.Mass = 01.0; 15 auto.Color = new Color(192, 192, 255); 16 Add(auto); 25 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 26 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 27 LuoBussi("Doublebus", 0, 0); 28 AsetaOhjaimet(); 29 IsFullScreen = true; 30 Timer ajastin = new Timer(); 31 ajastin.Interval = 5; 32 ajastin.Trigger += paivitaKello; 33 ajastin.Start(); 34 35 Label kello = new Label(); 36 kello.Text = tunti.ToString() + ":" + minuutti.ToString(); 37 kello.TextColor = Color.Black; 38 kello.X = Screen.Right - 50; 39 kello.Y = Screen.Top - 25; 40 Add(kello); 17 41 18 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");19 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); 20 Mouse.Listen(MouseButton.Left, ButtonState.Down, Reitti, "Siirry", auto);42 ajastin.Tag = kello; 43 44 21 45 } 22 void LuoTalo(double x, double y) 23 { 24 PhysicsObject talo = new PhysicsObject(100.0, 100.0, Shapes.Rectangle); 25 talo.X = x ; 26 talo.Y = y ; 27 talo.Color = Color.Yellow; 28 talo.IgnoresCollisionResponse = true; 29 Add(talo); 30 } 31 void Reitti (PhysicsObject auto) 46 47 void AsetaOhjaimet() 48 { 49 Mouse.IsCursorVisible = true; 50 Mouse.Listen(MouseButton.Left, ButtonState.Pressed, LisaaReittipiste, "Siirry", bussi); 51 Mouse.Listen(MouseButton.Right, ButtonState.Pressed, PoistaReittipiste, ""); 52 Mouse.ListenMovement(1.0, HiirenLiikutus, null); 53 } 54 55 void HiirenLiikutus(AnalogState hiirenTila) 56 { 57 bool onkoPaalla; 58 foreach (GameObject piste in bussiReitinPisteet) 59 { 60 onkoPaalla = Mouse.IsCursorOn(piste); 61 if (onkoPaalla) 62 { 63 piste.Color = Color.Green; 64 viimeisinPisteAlla = piste; 65 onkoPisteAlla = true; 66 continue; 67 } 68 else 69 { 70 piste.Color = Color.Red; 71 onkoPisteAlla = false; 72 } 73 } 74 MessageDisplay.Add(onkoPisteAlla.ToString()); 75 } 76 77 78 79 void LisaaReittipiste(PhysicsObject auto) 32 80 { 33 81 Vektori = Mouse.PositionOnWorld; 34 auto.Push(Vektori); 35 auto.Angle = Vektori.Angle; 82 LisaaBussireitinPiste(Mouse.PositionOnWorld); 83 MessageDisplay.Add("Lisättiin " + bussinReitti[bussinReitti.Count - 1].X + " " + bussinReitti[bussinReitti.Count - 1].Y); 84 } 85 86 void PoistaReittipiste() 87 { 88 Vektori = Mouse.PositionOnWorld; 89 //auto.Push(Vektori); 90 //auto.Angle = Vektori.Angle; 91 if (onkoPisteAlla) 92 { 93 MessageDisplay.Add("poistetaan " + viimeisinPisteAlla.Position.X + " " + viimeisinPisteAlla.Position.Y); 94 bussiReitinPisteet.Remove(viimeisinPisteAlla); 95 bussinReitti.Remove(viimeisinPisteAlla.Position); 96 viimeisinPisteAlla.Destroy(); 97 onkoPisteAlla = false; 98 } 99 } 100 101 void LisaaBussireitinPiste(Vector paikka) 102 { 103 bussinReitti.Add(paikka); 104 GameObject piste = new GameObject(5, 5); 105 piste.Tag = "piste"; 106 piste.Color = Color.Red; 107 piste.Position = paikka; 108 Add(piste); 109 bussiReitinPisteet.Add(piste); 110 } 111 112 void LuoBussi(string tyyppi, double x, double y) 113 { 114 int kapasiteetti; 115 bussi = new PhysicsObject(40, 20); 116 PathFollowerBrain polkuaivot = new PathFollowerBrain(); 117 LisaaBussireitinPiste(new Vector(x, y)); 118 polkuaivot.Path = bussinReitti; 119 bussi.Brain = polkuaivot; 120 polkuaivot.Active = true; 121 polkuaivot.Speed = 150; 122 id += 1; 123 bussi.Mass = 5.0; 124 bussi.Color = new Color(10, 50, 60); 125 bussi.Tag = id; 126 127 if (tyyppi == "Smallbus") kapasiteetti = 30; 128 if (tyyppi == "Longbus") kapasiteetti = 60; 129 if (tyyppi == "Doublebus") kapasiteetti = 80; 130 Add(bussi); 131 } 132 void paivitaKello(Timer ajastin) 133 { 134 minuutti += 1; 135 if (minuutti == 60) 136 { 137 tunti += 1; 138 minuutti = 0; 139 } 140 if (tunti == 24) 141 { 142 tunti = 0; 143 } 144 145 Label kello = (Label)ajastin.Tag; 146 kello.Text = tunti.ToString() + ":" + minuutti.ToString(); 36 147 } 37 148 } 38
Note: See TracChangeset
for help on using the changeset viewer.