Changeset 688
- Timestamp:
- 2010-06-10 14:57:17 (13 years ago)
- Location:
- 2010/23/ekeimaja/Labyrinth
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/ekeimaja/Labyrinth/Labyrinth/Peli.cs
r633 r688 7 7 8 8 namespace Labyrinth // © Eki Majankallio 2010 9 { //wanderedbrainilla hirviöt9 { 10 10 public class Peli : PhysicsGame 11 11 { 12 12 13 PhysicsObject Pelaaja1; 13 14 PhysicsObject Pelaaja2; 15 PhysicsObject Maali; 16 17 int pisteitaKentassa = 0; 14 18 15 19 const int RuudunLeveys = 50; 16 20 const int RuudunKorkeus = 50; 17 21 22 IntMeter kenttaLaskuri; 23 IntMeter pistelaskuri1; 24 IntMeter pistelaskuri2; 25 int pisteitakeratty = 0; 26 27 18 28 protected override void Begin() 19 29 { 20 21 30 LuoPisteLaskurit(); 31 MessageDisplay.TextColor = Color.White; 22 32 23 33 var merkit = new Dictionary<char, ObjectCreator>(); … … 38 48 } 39 49 50 void LuoPisteLaskurit() 51 { 52 // Pelaajan 1 pistelaskuri 53 pistelaskuri1 = new IntMeter(0); 54 ValueDisplay pisteNaytto1 = new ValueDisplay(); 55 pisteNaytto1.Text = "Pelaaja1 pisteet: "; 56 pisteNaytto1.X = Screen.Left + 100; 57 pisteNaytto1.Y = Screen.Top - 100; 58 pisteNaytto1.ValueColor = Color.Red; 59 pisteNaytto1.TextColor = Color.Red; 60 pisteNaytto1.BindTo(pistelaskuri1); 61 Add(pisteNaytto1); 62 63 // Pelaajan 2 pistelaskuri 64 pistelaskuri2 = new IntMeter(0); 65 ValueDisplay pisteNaytto2 = new ValueDisplay(); 66 pisteNaytto2.Text = "Pelaaja2 pisteet: "; 67 pisteNaytto2.X = Screen.Left + 100; 68 pisteNaytto2.Y = Screen.Top - 20; 69 pisteNaytto2.ValueColor = Color.Red; 70 pisteNaytto2.TextColor = Color.Red; 71 pisteNaytto2.BindTo(pistelaskuri2); 72 Add(pisteNaytto2); 73 } 74 40 75 PhysicsObject LuoPelaaja1() 41 76 { 42 Pelaaja1 = new PhysicsObject(40.0, 40.0);77 Pelaaja1 = new PhysicsObject(40.0, 40.0); 43 78 Pelaaja1.IgnoresPhysicsLogics = true; 44 Pelaaja1.CanRotate = false; 79 Pelaaja1.CanRotate = false; 80 Pelaaja1.Tag = "1"; 45 81 Pelaaja1.Image = LoadImage("player1"); 46 82 Add(Pelaaja1); 83 AddCollisionHandler(Pelaaja1, RuokaanTormays); 84 AddCollisionHandler(Pelaaja1, MaaliinTormays); 47 85 return Pelaaja1; 48 86 … … 54 92 Pelaaja2.IgnoresPhysicsLogics = true; 55 93 Pelaaja2.CanRotate = false; 94 Pelaaja2.Tag = "2"; 56 95 Pelaaja2.Image = LoadImage("player2"); 57 96 Add(Pelaaja2); 97 AddCollisionHandler(Pelaaja2, RuokaanTormays); 98 AddCollisionHandler(Pelaaja2, MaaliinTormays); 58 99 return Pelaaja2; 59 100 } 60 101 61 GameObject LuoHirvio()62 { 63 GameObject Hirvio = new GameObject(50.0, 50.0);102 PhysicsObject LuoHirvio() 103 { 104 PhysicsObject Hirvio = new PhysicsObject(48.0, 48.0); 64 105 Hirvio.Image = LoadImage("monster"); 65 106 Add(Hirvio); 107 Hirvio.IgnoresCollisionResponse = true; 108 Hirvio.Velocity = new Vector(90.0, 0.0); 109 AddCollisionHandler(Hirvio, SeinaanTormays); 110 AddCollisionHandler(Hirvio, PelaajaanTormays); 66 111 return Hirvio; 67 112 } 68 113 69 GameObject LuoRuoka()70 { 71 GameObject Ruoka = new GameObject(50.0, 50.0);114 PhysicsObject LuoRuoka() 115 { 116 PhysicsObject Ruoka = new PhysicsObject(50.0, 50.0); 72 117 Ruoka.Image = LoadImage("food"); 118 Ruoka.IgnoresPhysicsLogics = false; 119 Ruoka.CanRotate = true; 120 pisteitakeratty += 1; 73 121 Add(Ruoka); 122 Ruoka.Tag = "r"; 74 123 return Ruoka; 75 124 } 76 125 77 GameObject LuoMaali()78 { 79 GameObject Maali = new GameObject(50.0, 50.0);126 PhysicsObject LuoMaali() 127 { 128 Maali = new PhysicsObject (50.0, 50.0); 80 129 Maali.Image = LoadImage("goal"); 130 Maali.IgnoresPhysicsLogics = true; 131 Maali.CanRotate = false; 132 Maali.Restitution = 0.0; 81 133 Add(Maali); 82 134 return Maali; … … 88 140 seina.Shape = Shapes.Rectangle; 89 141 seina.Restitution = 0.0; 142 seina.IgnoresPhysicsLogics = true; 90 143 seina.Color = Color.Black; 91 144 return seina; … … 103 156 Keyboard.Listen(Key.W, ButtonState.Down, LiikutaPelaaja2Ylos, null); 104 157 Keyboard.Listen(Key.S, ButtonState.Down, LiikutaPelaaja2Alas, null); 158 105 159 //näppäin ylhäällä 106 160 Keyboard.Listen(Key.Left, ButtonState.Released, Pelaaja1.StopHorizontal, null); … … 112 166 Keyboard.Listen(Key.W, ButtonState.Released, Pelaaja2.StopVertical, null); 113 167 Keyboard.Listen(Key.S, ButtonState.Released, Pelaaja2.StopVertical, null); 114 115 } 116 168 169 } 170 171 #region Liikuttaminen 117 172 //pelaaja1 118 173 void LiikutaPelaajaaVasemmalle() … … 134 189 { 135 190 Pelaaja1.Hit(new Vector(0, -10)); 136 }191 } 137 192 //Pelaaja2 138 193 void LiikutaPelaaja2Vasemmalle() … … 155 210 Pelaaja2.Hit(new Vector(0, -10)); 156 211 } 157 212 #endregion 213 214 void SeinaanTormays(PhysicsObject Hirvio, PhysicsObject seina) 215 { 216 Hirvio.Velocity = -Hirvio.Velocity; 217 } 218 219 void PelaajaanTormays(PhysicsObject Hirvio, PhysicsObject kohde) 220 { 221 if (kohde == Pelaaja1) 222 { 223 Pelaaja1.Destroy(); 224 TextDisplay viesti = new TextDisplay(); 225 Add(viesti); 226 viesti.X = Screen.Left + 600; 227 viesti.Y = Screen.Top - 60; 228 viesti.Text = "Pelaaja1 joutui Hirviön kitaan!"; 229 } 230 if (kohde == Pelaaja2) 231 { 232 Pelaaja2.Destroy(); 233 TextDisplay viesti = new TextDisplay(); 234 Add(viesti); 235 viesti.X = Screen.Left + 600; 236 viesti.Y = Screen.Top - 60; 237 viesti.Text = "Pelaaja2 joutui Hirviön kitaan!"; 238 239 } 240 } 241 242 void RuokaanTormays(PhysicsObject tormaaja, PhysicsObject pallo) 243 { 244 if (pallo.Tag.ToString() == "r") // r-tägistä saa pisteitä 245 { 246 pisteitakeratty -= 1; 247 pallo.Destroy(); 248 if (tormaaja.Tag.ToString() == "1") 249 { 250 pistelaskuri1.Value += 10; 251 } 252 else if (tormaaja.Tag.ToString() == "2") 253 { 254 pistelaskuri2.Value += 10; 255 } 256 } 257 258 } 259 void MaaliinTormays(PhysicsObject voittaja, PhysicsObject tormattava) 260 { 261 if (pisteitakeratty != 1) 262 { 263 if (voittaja.Tag.ToString() == "1" && (tormattava == Maali)) 264 { 265 TextDisplay viesti = new TextDisplay(); 266 Add(viesti); 267 viesti.X = Screen.Left + 600; 268 viesti.Y = Screen.Top - 60; 269 viesti.Text = "Pelaaja1 voitti pelin!"; 270 } 271 else if (voittaja.Tag.ToString() == "2" && tormattava.Equals(Maali)) 272 { 273 TextDisplay viesti = new TextDisplay(); 274 Add(viesti); 275 viesti.X = Screen.Left + 600; 276 viesti.Y = Screen.Top - 60; 277 viesti.Text = "Pelaaja2 voitti pelin!"; 278 viesti.MaximumLifetime 279 ClearAll(); 280 goto 281 } 282 283 else if (pisteitakeratty < pisteitaKentassa ) 284 { 285 TextDisplay viesti = new TextDisplay(); 286 Add(viesti); 287 viesti.X = Screen.Left + 600; 288 viesti.Y = Screen.Top - 60; 289 viesti.Text = "Et ole kerännyt kaikkia pisteitä!"; 290 } 291 } 292 } 293 void SeuraavaKentta(int kentanNro) 294 { 295 296 297 kenttaLaskuri = new IntMeter(kentanNro); 298 299 if (kenttaLaskuri.Value == 1) LuoKentta1(); 300 else if (kenttaLaskuri.Value == 2) LuoKentta2(); 301 else if (kenttaLaskuri.Value == 3) LuoKentta3(); 302 else if (kenttaLaskuri.Value > 3) Exit(); 303 304 void LuoKentta1() 305 { 306 } 307 } 158 308 } 159 309 } 310 311 312 -
2010/23/ekeimaja/Labyrinth/Labyrinth/kentta1.txt
r633 r688 13 13 xxxxxxxxxxxx xx 000 xxxxxxxx 000000 xx 14 14 xx xx xxxxxxxx xx 15 xx xxxxxxxxxxxxx D000000 xx15 xx xxxxxxxxxxxxx 000000 xx 16 16 xx xxxxxxxxxxxxxxxxx xxx xxxxxxxxxxx 17 17 xx xxxxxxxxxxxxx Fx xxx xxxxxxxxxxx 18 xx 2 xxxxxxxxxxxxx 18 xx 2 xxxxxxxxxxxxx D xxxxxxxxxxx 19 19 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 20 20 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Note: See TracChangeset
for help on using the changeset viewer.