- Timestamp:
- 2015-06-25 21:56:35 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun.cs
r6397 r6403 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Diagnostics.CodeAnalysis; 3 4 using System.Linq; 4 5 using Jypeli; … … 225 226 private Animation tattiMageAnimation; 226 227 private Animation tattiMageCastAnimation; 228 229 private Animation bossRiseAnimation; 230 private Animation bossFallAnimation; 231 private Animation bossHitAnimation; 227 232 #endregion 228 233 … … 235 240 private double bottomCamLimit; 236 241 237 private int levelNumber = 0; 242 private int levelNumber = 2; 243 244 private Action activateBoss; 238 245 239 246 public override void Begin() … … 394 401 tattiMageAnimation = LoadAnimation("tattimage"); 395 402 tattiMageCastAnimation = LoadAnimation("tattimagecast"); 403 bossRiseAnimation = LoadAnimation("bossrise"); 404 bossFallAnimation = LoadAnimation("bossfall"); 405 bossHitAnimation = LoadAnimation("bosshit"); 396 406 397 407 cameraOffset = Window.Width / 4; … … 448 458 449 459 //Tilemap 450 ColorTileMap level = ColorTileMap.FromLevelAsset("level" + levelNumber); 460 //ColorTileMap level = ColorTileMap.FromLevelAsset("level" + levelNumber); 461 ColorTileMap level = ColorTileMap.FromLevelAsset("bosstest"); 451 462 level.SetTileMethod(Color.Black, CreateGroundTop); 452 463 level.SetTileMethod(Color.Brown, CreateGround); … … 460 471 461 472 level.SetTileMethod(Color.Gray, (new AbstractTileMap<Color>.TileMethod[] { CreateCrawly, CreateWorm, null })[levelNumber]); // ಠ_ಠ 462 level.SetTileMethod(Color.Red, (new AbstractTileMap<Color>.TileMethod[] { CreateFireMage, CreateShroom, null})[levelNumber]);473 level.SetTileMethod(Color.Red, (new AbstractTileMap<Color>.TileMethod[] { CreateFireMage, CreateShroom, CreateBoss })[levelNumber]); 463 474 level.SetTileMethod(Color.White, CreateBlockObject); 464 475 level.SetTileMethod(Color.DarkGray, CreateMilk); … … 497 508 Add(lavaCollision); 498 509 499 var updateTimer = new Timer { Interval = 0.01};510 var updateTimer = new Timer { Interval = 0.01 }; 500 511 updateTimer.Timeout += delegate 501 512 { … … 505 516 updateTimer.Start(); 506 517 } 518 } 519 520 void CreateBoss(Vector position, double width, double height) 521 { 522 GameObject boss = new GameObject(700, 522); 523 boss.Position = position; 524 boss.Top = position.Y - height * 0.5; 525 boss.Animation = bossRiseAnimation; 526 Add(boss, -3); 527 528 List<PhysicsObject> eyes = null; // Lista jotta voi käyttää kätevästi ForEach:ia. 529 var health = new IntMeter(6, 0, 6); // Vähenee vain heinähangolla. 530 var eyeHealth = new IntMeter(30, 0, 30); // Vähenee maidon loiskutuksella. 531 532 eyeHealth.LowerLimit += delegate 533 { 534 // Bossi kaatuaa maahan. 535 eyes.ForEach(e => e.IsVisible = false); 536 boss.Animation = bossFallAnimation; 537 boss.Animation.StopOnLastFrame = true; 538 boss.Animation.Start(1); 539 540 // Bossi palautuu takaisin lyöntianimaatioonsa hetken päästä. 541 Timer.SingleShot(5.0, delegate 542 { 543 boss.Animation = bossHitAnimation; 544 eyeHealth.Value = eyeHealth.MaxValue; 545 eyes.ForEach(e => e.IsVisible = true); 546 }); 547 }; 548 549 // Alue johon pitää lyödä heinähangolla. 550 var headCollision = PhysicsObject.CreateStaticObject(50, 50); 551 headCollision.IsVisible = false; 552 headCollision.IgnoresCollisionResponse = true; 553 Add(headCollision); 554 AddCollisionHandler(headCollision, "pitchfork", delegate(PhysicsObject h, PhysicsObject fork) 555 { 556 if (boss.Animation == bossFallAnimation) 557 { 558 health.Value--; 559 } 560 }); 561 var headMoveTimer = new Timer { Interval = 0.01 }; 562 headMoveTimer.Timeout += delegate 563 { 564 headCollision.Position = boss.Position + new Vector(-10, 0); 565 }; 566 headMoveTimer.Start(); 567 headCollision.Destroyed += headMoveTimer.Stop; 568 569 // Lyöntianimaation päätteeksi lisätään kiviä. 570 bossHitAnimation.Played += delegate 571 { 572 var rock = new PhysicsObject(30, 30); 573 rock.Position = boss.Position + new Vector(RandomGen.NextDouble(-300, 100), 300); 574 rock.LifetimeLeft = TimeSpan.FromSeconds(2.0); 575 Add(rock); 576 }; 577 578 // Silmien luonti funktio. 579 Func<int, int, PhysicsObject> eyeFlame = (x, y) => 580 { 581 var flame = PhysicsObject.CreateStaticObject(width * 0.3, height * 0.6); 582 flame.Animation = new Animation(blaze); 583 flame.IgnoresCollisionResponse = true; 584 flame.IsVisible = false; 585 flame.Animation.Start(); 586 Add(flame); 587 AddCollisionHandler(flame, "milkparticle", delegate(PhysicsObject f, PhysicsObject particle) 588 { 589 // Otetaan vahinkoa vain kun ollaan näkyvillä. 590 if (flame.IsVisible) 591 { 592 particle.Destroy(); 593 eyeHealth.Value--; 594 } 595 }); 596 var moveTimer = new Timer { Interval = 0.01 }; 597 moveTimer.Timeout += delegate 598 { 599 flame.Position = boss.Position + new Vector(x, y); 600 }; 601 moveTimer.Start(); 602 flame.Destroyed += moveTimer.Stop; 603 return flame; 604 }; 605 606 eyes = new List<PhysicsObject>(new[] { eyeFlame(0, 150), eyeFlame(40, 145) }); 607 608 // Tuhotaan bossi kun se kuolee. 609 health.LowerLimit += delegate 610 { 611 eyes.ForEach(e => e.Destroy()); 612 boss.Destroy(); 613 headCollision.Destroy(); 614 Timer.SingleShot(4.0, Victory); 615 }; 616 617 // Kutsutaan kun pelaajat saapuu kentän päähän. 618 activateBoss = delegate 619 { 620 // Nostetaan bossi ylös maasta. 621 boss.MoveTo(position + new Vector(0, boss.Height * 0.4), 500); 622 boss.Animation.Start(1); 623 boss.Animation.StopOnLastFrame = true; 624 boss.Animation.Played += delegate 625 { 626 // Taistelu alkaa. 627 eyes.ForEach(e => e.IsVisible = true); 628 629 // Laitetaan lyöntianimaatio päälle. 630 boss.Animation = bossHitAnimation; 631 boss.Animation.Start(); 632 }; 633 }; 507 634 } 508 635 … … 844 971 } 845 972 }); 846 847 848 973 } 849 974 … … 1018 1143 AddCollisionHandler(player, "lava", delegate(PhysicsObject p, PhysicsObject t) 1019 1144 { 1020 player.Life.Value = player.Life.MinValue; 1145 // TODO: Ota alempi rivi pois kommentista. 1146 //player.Life.Value = player.Life.MinValue; 1021 1147 }); 1022 1148 … … 1089 1215 } 1090 1216 #endregion 1217 1218 void Victory() 1219 { 1220 ClearAll(); 1221 MessageDisplay.Add("Voitit muutes belin."); 1222 } 1091 1223 1092 1224 void SetControls() … … 1205 1337 if (levelNumber < 2) 1206 1338 { 1207 cameraTarget = (minPosition + maxPosition) *0.5;1339 cameraTarget = (minPosition + maxPosition) * 0.5; 1208 1340 cameraTarget.X = Math.Max(cameraTargetX, minX); //Lellllll. 1209 1341 … … 1222 1354 // Pakotetaan kameraa eteenpäin. Jos kaikki pelaajat on näytön oikealla puolella, niin liikutetaan nopeammin. 1223 1355 double cameraSpeed = players.All(p => Camera.WorldToScreen(p.Position).X > 0) ? 4.0 : 1.0; 1224 cameraTarget.X += cameraSpeed; 1356 cameraTarget.X += cameraSpeed; 1357 1358 cameraTarget.X = Math.Min(cameraTarget.X, rightCamLimit); 1359 1360 if (cameraTarget.X == rightCamLimit && activateBoss != null) 1361 { 1362 activateBoss(); 1363 activateBoss = null; 1364 } 1225 1365 } 1226 1366
Note: See TracChangeset
for help on using the changeset viewer.