- Timestamp:
- 2013-06-26 14:57:08 (10 years ago)
- Location:
- 2013/26/OtsoR/Projekti/Projekti
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/26/OtsoR/Projekti/Projekti/Projekti/Projekti.cs
r4227 r4245 6 6 using Jypeli.Effects; 7 7 using Jypeli.Widgets; 8 9 class Vihu : PhysicsObject 8 class Player : PhysicsObject 9 { 10 private IntMeter health = new IntMeter(100, 0, 100); 11 public IntMeter Health { get { return health; } } 12 13 public Player(double width, double height, Shape shape) 14 : base(width, height, shape) 15 { 16 ProgressBar playerhealth = new ProgressBar(8, 3); 17 playerhealth.BindTo(health); 18 playerhealth.BarColor = Color.Green; 19 playerhealth.BorderColor = Color.Red; 20 playerhealth.X = -8; 21 playerhealth.Angle = Angle.RightAngle; 22 Add(playerhealth); 23 health.LowerLimit += delegate 24 { 25 this.Destroy(); 26 }; 27 } 28 } 29 class Enemy : PhysicsObject 10 30 { 11 31 private IntMeter health = new IntMeter(5, 0, 5); 12 32 public IntMeter Health { get { return health; } } 13 33 14 public Vihu(double leveys, double korkeus, Shape muoto)34 public Enemy(double leveys, double korkeus, Shape muoto) 15 35 : base(leveys, korkeus, muoto) 16 36 { 17 37 ProgressBar enemyhealth = new ProgressBar(6, 2.5); 18 38 enemyhealth.BindTo(health); 39 enemyhealth.X = -8; 40 enemyhealth.Angle = Angle.RightAngle; 19 41 Add(enemyhealth); 20 42 health.LowerLimit += delegate { 43 this.Destroy(); 44 }; 45 } 46 } 47 class Boss : PhysicsObject 48 { 49 private IntMeter health = new IntMeter(100, 0, 100); 50 public IntMeter Health { get { return health; } } 51 52 public Boss(double leveys, double korkeus, Shape muoto) 53 : base(leveys, korkeus, muoto) 54 { 55 ProgressBar enemyhealth = new ProgressBar(6, 2.5); 56 enemyhealth.BindTo(health); 57 enemyhealth.X = -20; 58 enemyhealth.Angle = Angle.RightAngle; 59 Add(enemyhealth); 21 60 health.LowerLimit += delegate { 22 61 this.Destroy(); … … 29 68 Color[] shipcolors = { Color.DarkGray, Color.Silver, Color.DarkOrange, Color.Ultramarine }; 30 69 Color[] shipcolors2 = { Color.Ruby, Color.Azure, Color.Emerald, Color.Emerald }; 70 Image boss1 = LoadImage("boss1"); 31 71 Image shell = LoadImage("bullet"); 32 72 Image pointer = LoadImage("pointer"); 73 Image rdamage = LoadImage("rdamage"); 74 Image rrepair = LoadImage("rrepair"); 33 75 34 76 String[] weaponnames = { "projectile","laser","plasma" }; … … 39 81 PhysicsObject rightedge; 40 82 41 P hysicsObjectship;83 Player ship; 42 84 Weapon weapon; 43 P hysicsObjectship2;85 Player ship2; 44 86 Weapon weapon2; 45 87 //PhysicsObject hostile; … … 61 103 IntMeter shipwpn2; 62 104 int shipcounter; 105 int bigshipcounter; 106 int bosscounter; 107 int runecounter; 63 108 public override void Begin() 64 109 { … … 161 206 Aluskuva2.Image.ReplaceColor(Color.Black, shipcolors2[shipcolor2.Value - 1]); 162 207 } 163 void Createship( )164 { 165 ship = new P hysicsObject(16, 16, Shape.FromImage(Aluskuva.Image));208 void Createship(double x, double y) 209 { 210 ship = new Player(16, 16, Shape.FromImage(Aluskuva.Image)); 166 211 ship.Image = Aluskuva.Image; 167 212 ship.Restitution = 1.0; 213 ship.X = x; 214 ship.Y = y; 168 215 ship.KineticFriction = 0.0; 169 216 ship.MomentOfInertia = Double.PositiveInfinity; … … 175 222 ship.CollisionIgnoreGroup = 1; 176 223 ship.Tag = "player"; 224 ship.Destroyed += playerdeath; 177 225 if (weapon is LaserGun) 178 226 { … … 183 231 } 184 232 } 185 void Createship2( )186 { 187 ship2 = new P hysicsObject(16, 16, Shape.FromImage(Aluskuva2.Image));233 void Createship2(double x, double y) 234 { 235 ship2 = new Player(16, 16, Shape.FromImage(Aluskuva2.Image)); 188 236 ship2.Image = Aluskuva2.Image; 237 ship2.X = x; 238 ship2.Y = y; 189 239 ship2.Restitution = 1.0; 190 240 ship2.KineticFriction = 0.0; … … 197 247 ship2.CollisionIgnoreGroup = 1; 198 248 ship2.Tag = "player"; 249 ship2.Destroyed += playerdeath; 250 if (weapon is LaserGun) 251 { 252 line = new GameObject(5000, 1.25); 253 line.Image = pointer; 254 line.X = 2500; 255 ship.Add(line); 256 } 199 257 } 200 258 void Spawnhostiles() 201 259 { 202 while (shipcounter < 25)260 while (shipcounter < 36) 203 261 { 204 262 int hostileship = RandomGen.NextInt(0, 100); … … 218 276 shipcounter++; 219 277 } 278 while (bigshipcounter < 4) 279 { 280 double bighostiley = 0.0; 281 double bighostilex = 0.0; 282 if (RandomGen.NextBool()) 283 { 284 bighostiley = Level.Bottom + 2 * Level.Top * RandomGen.NextInt(0, 2); 285 bighostilex = RandomGen.NextDouble(Level.Left, Level.Right); 286 } 287 else 288 { 289 bighostiley = RandomGen.NextDouble(Level.Bottom, Level.Top); 290 bighostilex = Level.Left + 2 * Level.Right * RandomGen.NextInt(0, 2); 291 } 292 Createbighostile(bighostiley, bighostilex); 293 bigshipcounter++; 294 } 220 295 } 221 296 void Createhostile(int randomship, double randomy, double randomx) 222 297 { 223 Vihu hostile = new Vihu(16, 16, Shape.FromImage(shipimages[randomship]));298 Enemy hostile = new Enemy(16, 16, Shape.FromImage(shipimages[randomship])); 224 299 hostile.Image = shipimages[randomship]; 225 300 hostile.Y = randomy; … … 231 306 hostile.AngularDamping = 1; 232 307 hostile.Tag = "hostile"; 233 Add(hostile); 308 hostile.Health.MaxValue = 5; 309 hostile.Health.Value = 5; 234 310 hostile.CollisionIgnoreGroup = 2; 235 311 hostile.Image.ReplaceColor(Color.White, Color.Ultramarine); 236 312 hostile.Image.ReplaceColor(Color.Black, Color.Emerald); 237 238 hostile.Destroyed += death; 239 240 PlasmaCannon hostilew = new PlasmaCannon(0, 0); 241 hostilew.ProjectileCollision = plasmahit; 313 Add(hostile); 314 315 hostile.Destroyed += enemydeath; 316 317 AssaultRifle hostilew = new AssaultRifle(0, 0); 318 hostilew.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 10, 0); }; 242 319 hostilew.FireRate = 0.5; 243 hostilew.Power.DefaultValue = 700;244 hostilew.Power.Value = 700;320 hostilew.Power.DefaultValue = 20; 321 hostilew.Power.Value = 20; 245 322 hostile.Add(hostilew); 246 323 … … 248 325 brain.Speed = 20; 249 326 brain.DistanceFar = 10000; 250 brain.DistanceClose = 200;327 brain.DistanceClose = 125; 251 328 brain.StopWhenTargetClose = false; 252 329 brain.TargetClose += delegate { fire(hostilew); }; … … 254 331 hostile.Brain = brain; 255 332 } 256 void death() 333 void Createbighostile(double y, double x) 334 { 335 Enemy Big1 = new Enemy(25, 29, Shape.FromImage(boss1)); 336 Big1.Image = boss1; 337 Big1.X = x; 338 Big1.Y = y; 339 Big1.Restitution = 1.0; 340 Big1.KineticFriction = 0.0; 341 Big1.MomentOfInertia = Double.PositiveInfinity; 342 Big1.LinearDamping = 0.95; 343 Big1.AngularDamping = 1; 344 Big1.Tag = "hostile"; 345 Big1.Health.MaxValue = 40; 346 Big1.Health.Value = 40; 347 Big1.CollisionIgnoreGroup = 2; 348 Big1.Image.ReplaceColor(Color.White, Color.Ultramarine); 349 Big1.Image.ReplaceColor(Color.Black, Color.Emerald); 350 Add(Big1); 351 Big1.Destroyed += bigenemydeath; 352 353 PlasmaCannon Big1w = new PlasmaCannon(0, 0); 354 Big1w.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 3, 0); }; 355 Big1w.FireRate = 1.5; 356 Big1w.Power.DefaultValue = 300; 357 Big1w.Power.Value = 300; 358 Big1.Add(Big1w); 359 360 FollowerBrain bigbrain1 = new FollowerBrain("player"); 361 bigbrain1.Speed = 15; 362 bigbrain1.DistanceFar = 10000; 363 bigbrain1.DistanceClose = 200; 364 bigbrain1.TurnSpeed = UnlimitedAngle.FromDegrees(10); 365 bigbrain1.StopWhenTargetClose = false; 366 bigbrain1.TargetClose += delegate { fire(Big1w); }; 367 bigbrain1.TurnWhileMoving = true; 368 Big1.Brain = bigbrain1; 369 } 370 void playerdeath() 371 { 372 MessageDisplay.Add("A player's ship has been destroyed"); 373 //MediaPlayer.Play("playerdeath"); 374 } 375 void enemydeath() 257 376 { 258 377 shipcounter--; 259 MediaPlayer.Play("Daah"); 260 } 261 // void Createhealthbar() 262 // { 263 // health = new DoubleMeter(10); 264 // health.MaxValue = 100; 265 // //healthbar.LowerLimit += ElamaLoppui; 266 // 267 // ProgressBar healthbar = new ProgressBar(150, 20); 268 // healthbar.X = Screen.Left + 150; 269 // healthbar.Y = Screen.Top - 20; 270 // healthbar.BindTo(health); 271 // Add(healthbar); 272 // } 378 } 379 void bigenemydeath() 380 { 381 bigshipcounter--; 382 } 383 void boss1death() 384 { 385 } 386 void boss2death() 387 { 388 } 273 389 void createedges() 274 390 { … … 367 483 shipweapon2.Y = 150; 368 484 shipweapon2.BindTo(shipwpn2); 369 370 485 Add(shiptype); 371 486 Add(shipcolour); … … 374 489 Add(shipcolour2); 375 490 Add(shipweapon2); 376 377 491 List<Label> valikonKohdat2; 378 492 valikonKohdat2 = new List<Label>(); // Alustetaan lista, johon valikon kohdat tulevat … … 393 507 case 1: 394 508 weapon = new AssaultRifle(0, 0); 395 weapon.ProjectileCollision = projectilehit;509 weapon.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 1); }; 396 510 weapon.FireRate = 4.5; 397 511 weapon.Power.Value = 100; … … 400 514 case 2: 401 515 weapon = new LaserGun(0, 0); 402 weapon.ProjectileCollision = laserhit;403 weapon.FireRate = 1;404 weapon.Power.DefaultValue = 1 200;405 weapon.Power.Value = 1 200;516 weapon.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 5); }; 517 weapon.FireRate = 0.8; 518 weapon.Power.DefaultValue = 1000; 519 weapon.Power.Value = 1000; 406 520 break; 407 521 case 3: 408 522 weapon = new PlasmaCannon(0, 0); 409 weapon.ProjectileCollision = plasmahit;523 weapon.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 3); }; 410 524 weapon.FireRate = 1.5; 411 525 weapon.Power.Value = 750; … … 420 534 case 1: 421 535 weapon2 = new AssaultRifle(0, 0); 422 weapon2.ProjectileCollision = projectilehit;536 weapon2.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 1); }; 423 537 weapon2.FireRate = 4.5; 424 538 weapon2.Power.Value = 100; … … 427 541 case 2: 428 542 weapon2 = new LaserGun(0, 0); 429 weapon2.ProjectileCollision = laserhit;543 weapon2.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 5); }; 430 544 weapon2.FireRate = 1; 431 weapon2.Power.DefaultValue = 1 200;432 weapon2.Power.Value = 1 200;545 weapon2.Power.DefaultValue = 1000; 546 weapon2.Power.Value = 1000; 433 547 break; 434 548 case 3: 435 549 weapon2 = new PlasmaCannon(0, 0); 436 weapon2.ProjectileCollision = plasmahit;550 weapon2.ProjectileCollision = delegate(PhysicsObject ammus, PhysicsObject kohde) { weaponhit(ammus, kohde, 0, 3); }; 437 551 weapon2.FireRate = 1.5; 438 552 weapon2.Power.Value = 750; … … 455 569 ammus.IgnoresCollisionResponse = true; 456 570 ammus.Image = shell; 457 ammus.Size *=0.4; 571 ammus.Size *= 0.4; 572 ammus.CollisionIgnoreGroup = 4; 458 573 AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 459 ammus.CollisionIgnoreGroup = 4;460 574 } 461 575 if (ase is LaserGun) … … 473 587 } 474 588 } 475 void projectilehit(PhysicsObject ammus, PhysicsObject kohde) 476 { 589 void weaponhit(PhysicsObject ammus, PhysicsObject kohde, int playerDamage, int enemyDamage) 590 { 591 if (kohde.Tag == "player") 592 { 593 Player ship = kohde as Player; 594 //ship.Health.Value -= 3; 595 ship.Health.Value -= playerDamage; 596 } 477 597 if (kohde.Tag == "hostile") 478 598 { 479 Vihu vihollinen = kohde as Vihu; 480 vihollinen.Health.Value -= 1; 481 } 482 } 483 void laserhit(PhysicsObject ammus, PhysicsObject kohde) 484 { 485 if (kohde.Tag == "hostile") 486 { 487 Vihu vihollinen = kohde as Vihu; 488 vihollinen.Health.Value -= 5; 489 } 490 } 491 void plasmahit(PhysicsObject ammus, PhysicsObject kohde) 492 { 493 if (kohde.Tag == "hostile") 494 { 495 Vihu vihollinen = kohde as Vihu; 496 vihollinen.Health.Value -= 3; 599 Enemy ship = kohde as Enemy; 600 //ship.Health.Value -= 1; 601 ship.Health.Value -= enemyDamage; 497 602 } 498 603 } … … 504 609 Keyboard.Listen(Key.D, ButtonState.Down, movement, null, 100, 0, ship); 505 610 Keyboard.Listen(Key.Space, ButtonState.Down, fire, "", weapon); 506 Mouse.ListenMovement(0, Aim, "");507 Mouse.Listen(MouseButton.Left, ButtonState.Down, fire, "", weapon);508 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");509 } 510 void Aim(AnalogState hiirenLiike )611 Mouse.ListenMovement(0, Aim, null, ship); 612 Mouse.Listen(MouseButton.Left, ButtonState.Down, fire, null, weapon); 613 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, null); 614 } 615 void Aim(AnalogState hiirenLiike, Player ship) 511 616 { 512 617 Vector suunta = (Mouse.PositionOnWorld - ship.AbsolutePosition).Normalize(); … … 534 639 Keyboard.Listen(Key.Add, ButtonState.Down, fire, "", weapon2); 535 640 } 536 void thrust(double direction, P hysicsObjectship)641 void thrust(double direction, Player ship) 537 642 { 538 643 Vector shipdirection = Vector.FromLengthAndAngle(100.0*direction, ship.Angle); 539 644 ship.Push(shipdirection); 540 645 } 541 void tilt(double direction, P hysicsObjectship)646 void tilt(double direction, Player ship) 542 647 { 543 648 ship.AngularAcceleration = 10.0*direction; … … 549 654 Level.CreateBorders(); 550 655 Camera.ZoomToLevel(); 551 Createship( );656 Createship(0, 0); 552 657 Spawnhostiles(); 553 658 Controlsship(); … … 564 669 Level.CreateBorders(); 565 670 Camera.ZoomToLevel(); 566 Createship( );567 Createship2( );671 Createship(-100, 0); 672 Createship2(100, 0); 568 673 Spawnhostiles(); 569 674 Controlsship1(); … … 575 680 a.Start(); 576 681 } 682 void Spawnrunes() 683 { 684 while (runecounter < 5) 685 { 686 int runetype = RandomGen.NextInt(0, 2); 687 double runey = 0.0; 688 double runex = 0.0; 689 if (RandomGen.NextBool()) 690 { 691 runey = Level.Bottom + 2 * Level.Top * RandomGen.NextInt(0, 2); 692 runex = RandomGen.NextDouble(Level.Left, Level.Right); 693 } 694 else 695 { 696 runey = RandomGen.NextDouble(Level.Bottom, Level.Top); 697 runex = Level.Left + 2 * Level.Right * RandomGen.NextInt(0, 2); 698 } 699 Createhostile(runetype, runey, runex); 700 runecounter++; 701 } 702 } 703 void Createrune(int runetype, double y, double x) 704 { 705 706 PhysicsObject Rune = new PhysicsObject(5, 5); 707 Rune.X = x; 708 Rune.Y = y; 709 Rune.CollisionIgnoreGroup = 2 & 3 & 4; 710 711 switch (runetype) 712 { 713 case 1: 714 //Addcollision 715 Rune.Image = rdamage; 716 break; 717 case 2: 718 //Addcollision 719 Rune.Image = rrepair; 720 break; 721 case 3: 722 //Addcollision 723 //Rune.Image = ...; 724 break; 725 } 726 } 577 727 } -
2013/26/OtsoR/Projekti/Projekti/ProjektiContent/ProjektiContent.contentproj
r4219 r4245 561 561 </ItemGroup> 562 562 <ItemGroup> 563 <Compile Include="Daah.mp3"> 564 <Name>Daah</Name> 565 <Importer>Mp3Importer</Importer> 566 <Processor>SongProcessor</Processor> 563 <Compile Include="boss1.png"> 564 <Name>boss1</Name> 565 <Importer>TextureImporter</Importer> 566 <Processor>TextureProcessor</Processor> 567 </Compile> 568 </ItemGroup> 569 <ItemGroup> 570 <Compile Include="rdamage.png"> 571 <Name>rdamage</Name> 572 <Importer>TextureImporter</Importer> 573 <Processor>TextureProcessor</Processor> 574 </Compile> 575 <Compile Include="rrepair.png"> 576 <Name>rrepair</Name> 577 <Importer>TextureImporter</Importer> 578 <Processor>TextureProcessor</Processor> 567 579 </Compile> 568 580 </ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.