- Timestamp:
- 2010-07-29 14:50:33 (13 years ago)
- Location:
- 2010/30/alkivima
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/alkivima/Car Duels/Peli.cs
r1396 r1404 4 4 using Jypeli.Assets; 5 5 using Jypeli.Effects; 6 using Physics2DDotNet.Ignorers; 6 7 7 8 public class Peli : TopDownPhysicsGame … … 9 10 PhysicsObject vasenReuna; 10 11 PhysicsObject oikeaReuna; 11 DoubleMeter voimaMittari ;12 DoubleMeter voimaMittari1; 12 13 DoubleMeter voimaMittari2; 13 14 Automobile auto1; … … 17 18 Label aikaNaytto; 18 19 20 AssaultRifle pyssy1; 21 AssaultRifle pyssy2; 22 19 23 protected override void Begin() 20 24 { 21 25 KineticFriction = 0.5; // Asetetaan kitka 22 26 23 27 24 28 auto1 = new Automobile(60, 50); 29 auto1.CollisionIgnorer = new ObjectIgnorer(); 25 30 auto1.Mass = 100.0; 26 31 auto1.Color = new Color(1, 1, 1); 27 32 auto1.X = -300; 28 33 auto1.Y = 0; 29 auto1.LinearDamping = 0.97 ;34 auto1.LinearDamping = 0.975; 30 35 auto1.AngularDamping = 0.1; 31 36 auto1.CanRotate = false; 32 auto1.Acceleration = 1 500;37 auto1.Acceleration = 1250; 33 38 Add(auto1, 1); 34 39 35 40 auto2 = new Automobile(60, 50); 41 auto2.CollisionIgnorer = new ObjectIgnorer(); 36 42 auto2.Mass = 100.0; 37 43 auto2.Color = new Color(255, 255, 255); 38 44 auto2.X = 300; 39 45 auto2.Y = 0; 40 auto2.LinearDamping = 0.97 ;46 auto2.LinearDamping = 0.975; 41 47 auto2.AngularDamping = 0.1; 42 48 auto2.Angle = Angle.Degrees(180.0); 43 49 auto2.CanRotate = false; 44 auto2.Acceleration = 1 500;50 auto2.Acceleration = 1250; 45 51 Add(auto2, 1); 46 47 AssaultRiflepyssy1 = new AssaultRifle(20, 5);52 53 pyssy1 = new AssaultRifle(20, 5); 48 54 pyssy1.Tag = "ase"; 55 pyssy1.TimeBetweenUse = TimeSpan.FromMilliseconds(200); 56 pyssy1.Ammo.Value = 500; 49 57 auto1.Add(pyssy1); 50 58 51 AssaultRiflepyssy2 = new AssaultRifle(20, 5);59 pyssy2 = new AssaultRifle(20, 5); 52 60 pyssy2.Tag = "ase"; 61 pyssy2.TimeBetweenUse = TimeSpan.FromMilliseconds(200); 62 pyssy2.Ammo.Value = 500; 53 63 auto2.Add(pyssy2); 54 64 … … 56 66 AddCollisionHandler(auto2, KasitteleAuto2Tormays); 57 67 58 ShowControlHelp();59 60 68 AsetaOhjaimet(); 61 69 … … 65 73 Pelaaja2HP(); 66 74 67 LisaaLaskurit(); 75 LisaaLaskurit(); 76 77 Voitto(); 68 78 } 69 79 void AsetaOhjaimet() … … 75 85 Keyboard.Listen(Key.A, ButtonState.Down, kaanny, "Käänny vasemmalle", auto1, 2.0); 76 86 Keyboard.Listen(Key.D, ButtonState.Down, kaanny, "Käänny oikealle", auto1, -2.0); 77 //Keyboard.Listen(Key.V, ButtonState.Down, AmmuAseella1, "Ammu", auto1);87 Keyboard.Listen(Key.V, ButtonState.Down, AmmuAseella, "Ammu", auto1, pyssy1); 78 88 79 89 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); … … 83 93 Keyboard.Listen(Key.Left, ButtonState.Down, kaanny, "Käänny vasemmalle", auto2, 2.0); 84 94 Keyboard.Listen(Key.Right, ButtonState.Down, kaanny, "Käänny oikealle", auto2, -2.0); 85 //Keyboard.Listen(Key.RightControl, ButtonState.Down, AmmuAseella2, "Ammu", auto2);86 } 87 95 Keyboard.Listen(Key.RightControl, ButtonState.Down, AmmuAseella, "Ammu", auto2, pyssy2); 96 } 97 88 98 void kiihdyta(Automobile auto) 89 99 { … … 98 108 void kaanny(Automobile auto, double kaannos) 99 109 { 100 auto.Angle = Angle.Degrees(auto.Angle.Degree + kaannos * 2);110 auto.Angle = Angle.Degrees(auto.Angle.Degree + kaannos * 1.75); 101 111 } 102 112 … … 227 237 228 238 pelaajan1Pisteet.Value += 1; 229 239 230 240 UusiEra(); 231 241 } 242 void Voitto() 243 { 244 if (pelaajan1Pisteet.Value == 5) 245 { 246 MessageDisplay.Add("Pelaaja 1 Voitti!"); 247 MessageDisplay.X = -75.0; 248 MessageDisplay.Y = 100.0; 249 } 250 if (pelaajan2Pisteet.Value == 5) 251 { 252 MessageDisplay.Add("Pelaaja 2 Voitti!"); 253 MessageDisplay.X = -75.0; 254 MessageDisplay.Y = 100.0; 255 } 256 } 232 257 void Pelaaja1HP() 233 258 { 234 voimaMittari = new DoubleMeter(10);235 voimaMittari .MaxValue = 10;259 voimaMittari1 = new DoubleMeter(25); 260 voimaMittari1.MaxValue = 25; 236 261 BarGauge voimaPalkki = new BarGauge(10, 150); 237 voimaPalkki.BindTo(voimaMittari );262 voimaPalkki.BindTo(voimaMittari1); 238 263 voimaPalkki.X = (0.95 * Screen.LeftSafe); 239 264 voimaPalkki.Y = (0.05 * Screen.Height); … … 242 267 void Pelaaja2HP() 243 268 { 244 voimaMittari2 = new DoubleMeter( 10);245 voimaMittari2.MaxValue = 10;269 voimaMittari2 = new DoubleMeter(25); 270 voimaMittari2.MaxValue = 25; 246 271 BarGauge voimaPalkki2 = new BarGauge(10, 150); 247 272 voimaPalkki2.BindTo(voimaMittari2); … … 252 277 void KasitteleAuto1Tormays(PhysicsObject auto1, PhysicsObject kohde) 253 278 { 254 255 if (auto1.Velocity.Magnitude > 200) 256 { 257 voimaMittari.Value++; 258 voimaMittari.Value -= 1; 259 voimaMittari.Value = voimaMittari.Value - 1; 260 } 261 if (voimaMittari.Value == 0) 279 280 if (auto1.Velocity.Magnitude > 300) 281 { 282 voimaMittari1.Value--; 283 } 284 if (voimaMittari1.Value == 0) 262 285 { 263 286 Pelaaja1Tuhoutuu(); 264 287 } 265 } 288 if (auto2.Velocity.Magnitude > auto1.Velocity.Magnitude) 289 { 290 voimaMittari1.Value--; 291 } 292 } 266 293 void KasitteleAuto2Tormays(PhysicsObject auto2, PhysicsObject kohde) 267 294 { 268 269 if (auto2.Velocity.Magnitude > 200) 270 { 271 voimaMittari2.Value++; 272 voimaMittari2.Value -= 1; 273 voimaMittari2.Value = voimaMittari2.Value - 1; 295 296 if (auto2.Velocity.Magnitude > 300) 297 { 298 voimaMittari2.Value--; 274 299 } 275 300 if (voimaMittari2.Value == 0) … … 279 304 if (auto1.Velocity.Magnitude > auto2.Velocity.Magnitude) 280 305 { 281 voimaMittari2.Value++; 282 voimaMittari2.Value -= 1; 283 voimaMittari2.Value = voimaMittari2.Value - 1; 306 voimaMittari2.Value--; 284 307 } 285 308 } 286 309 void LisaaLaskurit() 287 310 { 288 pelaajan1Pisteet = LuoPisteLaskuri( -250.0, 250.0);289 pelaajan2Pisteet = LuoPisteLaskuri( 311 pelaajan1Pisteet = LuoPisteLaskuri(-250.0, 250.0); 312 pelaajan2Pisteet = LuoPisteLaskuri(230.0, 250.0); 290 313 } 291 314 IntMeter LuoPisteLaskuri(double x, double y) … … 305 328 ClearControls(); 306 329 307 voimaMittari .Value = 10;308 voimaMittari2.Value = 10;330 voimaMittari1.Value = 25; 331 voimaMittari2.Value = 25; 309 332 310 333 auto1.X = -300; … … 322 345 323 346 } 324 void AmmuAseella1() 325 { 326 //PhysicsObject ammus = pyssy1.Shoot; 327 //if (ammus != null) 328 { 329 // ammus.Size *= 3; 330 } 331 } 332 void AmmuAseella2() 333 { 334 //PhysicsObject ammus = auto2.Weapon.Shoot; 335 //if (ammus != null) 336 { 337 // ammus.Size *= 3; 338 } 339 } 347 void AmmuAseella(Automobile auto, Weapon ase) 348 { 349 PhysicsObject ammus = ase.Shoot(); 350 351 if (ammus != null) 352 { 353 ammus.CollisionIgnorer = auto.CollisionIgnorer; 354 ammus.Size *= 3; 355 AddCollisionHandler(ammus, AmmusOsui); 356 } 357 } 358 359 void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde) 360 { 361 ammus.Destroy(); 362 363 if (kohde == auto1) 364 { 365 voimaMittari1.Value--; 366 return; 367 } 368 if (kohde == auto2) 369 { 370 voimaMittari2.Value--; 371 } 372 } 373 340 374 void EranAlku() 341 { 342 Timer aikaLaskuri = new Timer(); 343 aikaLaskuri.Interval = 3; 344 aikaLaskuri.Trigger += AikaLoppui; 345 Add(aikaLaskuri); 346 aikaLaskuri.Start(); 375 { 376 Timer aikaLaskuri = new Timer(); 377 aikaLaskuri.Interval = 3; 378 aikaLaskuri.Trigger += AikaLoppui; 379 aikaLaskuri.Start(); 347 380 348 381 aikaNaytto = new Label(); … … 353 386 aikaNaytto.BindTo(aikaLaskuri.SecondCounter); 354 387 Add(aikaNaytto); 355 388 } 389 390 void AikaLoppui(Timer ajastin) 391 { 392 MessageDisplay.Add("Start!"); 393 MessageDisplay.X = -30.0; 394 MessageDisplay.Y = 100.0; 395 ajastin.Stop(); 396 ajastin.Reset(); 397 ajastin.Destroy(); 398 aikaNaytto.Destroy(); 399 AsetaOhjaimet(); 400 401 pyssy1.Ammo.Value = 500; 402 pyssy2.Ammo.Value = 500; 403 } 356 404 } 357 358 void AikaLoppui( Timer ajastin )359 {360 MessageDisplay.Add( "Start!" );361 MessageDisplay.X = 0.0;362 MessageDisplay.Y = 100.0;363 ajastin.Reset();364 AsetaOhjaimet();365 }366 367 }
Note: See TracChangeset
for help on using the changeset viewer.