- Timestamp:
- 2013-06-25 14:50:21 (10 years ago)
- Location:
- 2013/26/OtsoR/Projekti/Projekti
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/26/OtsoR/Projekti/Projekti/Projekti/Projekti.cs
r4203 r4219 7 7 using Jypeli.Widgets; 8 8 9 class Vihu : PhysicsObject 10 { 11 private IntMeter health = new IntMeter(3, 0, 3); 12 public IntMeter Health { get { return health; } } 13 14 public Vihu(double leveys, double korkeus, Shape muoto) 15 : base(leveys, korkeus, muoto) 16 { 17 ProgressBar elamaPalkki = new ProgressBar(6, 2.5); 18 elamaPalkki.BindTo(health); 19 Add(elamaPalkki); 20 21 health.LowerLimit += delegate { 22 this.Destroy(); 23 }; 24 } 25 } 26 9 27 public class Projekti : PhysicsGame 10 28 { … … 13 31 Color[] shipcolors2 = { Color.Ruby, Color.Azure, Color.Emerald, Color.Emerald }; 14 32 Image shell = LoadImage("bullet"); 33 Image pointer = LoadImage("pointer"); 15 34 16 35 String[] weaponnames = { "projectile","laser","plasma" }; … … 25 44 PhysicsObject ship2; 26 45 Weapon weapon2; 27 PhysicsObject hostile;46 //PhysicsObject hostile; 28 47 Weapon hostilew; 48 GameObject line; 29 49 30 50 Label number; 31 51 Label number2; 52 Label colour; 32 53 Label weaponlabel; 33 54 Label weaponlabel2; … … 90 111 Add(number); 91 112 113 colour = new Label("style"); 114 colour.X = -125; 115 colour.Y = 125; 116 Add(colour); 117 92 118 weaponlabel = new Label(weaponnames[0]); 93 119 weaponlabel.X = 125; … … 150 176 ship.CollisionIgnoreGroup = 1; 151 177 ship.Tag = "player"; 152 } 153 void Createship2() 178 if (weapon is LaserGun) 179 { 180 line = new GameObject(5000, 1.25); 181 line.Image = pointer; 182 line.X = 2500; 183 ship.Add(line); 184 } 185 } 186 void Createship2() 154 187 { 155 188 ship2 = new PhysicsObject(16, 16, Shape.FromImage(Aluskuva2.Image)); … … 168 201 void Spawnhostiles() 169 202 { 170 int shipcounter = 0; 171 172 while (shipcounter < 5) 203 while (shipcounter < 25) 173 204 { 174 205 int hostileship = RandomGen.NextInt(0, 100); … … 184 215 hostiley = RandomGen.NextDouble(Level.Bottom, Level.Top); 185 216 hostilex = Level.Left + 2 * Level.Right * RandomGen.NextInt(0, 2); 186 187 217 } 188 218 Createhostile(hostileship, hostiley, hostilex); … … 192 222 void Createhostile(int randomship, double randomy, double randomx) 193 223 { 194 hostile = new PhysicsObject(16, 16, Shape.FromImage(shipimages[randomship]));224 Vihu hostile = new Vihu(16, 16, Shape.FromImage(shipimages[randomship])); 195 225 hostile.Image = shipimages[randomship]; 196 226 hostile.Y = randomy; … … 207 237 hostile.Image.ReplaceColor(Color.Black, Color.Emerald); 208 238 239 hostile.Destroyed += death; 240 209 241 PlasmaCannon hostilew = new PlasmaCannon(0, 0); 210 242 hostilew.ProjectileCollision = weaponhit; … … 223 255 hostile.Brain = brain; 224 256 } 257 void death() 258 { 259 shipcounter--; 260 MediaPlayer.Play("Daah"); 261 } 262 // void Createhealthbar() 263 // { 264 // health = new DoubleMeter(10); 265 // health.MaxValue = 10; 266 // //healthbar.LowerLimit += ElamaLoppui; 267 // 268 // ProgressBar healthbar = new ProgressBar(150, 20); 269 // healthbar.X = Screen.Left + 150; 270 // healthbar.Y = Screen.Top - 20; 271 // healthbar.BindTo(health); 272 // Add(healthbar); 273 // } 225 274 void createedges() 226 275 { … … 335 384 foreach (Label valikonKohta2 in valikonKohdat2) 336 385 { 337 386 Add(valikonKohta2); 338 387 } 339 388 Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, coopbase, null); … … 347 396 weapon.ProjectileCollision = weaponhit; 348 397 weapon.FireRate = 4.5; 398 weapon.Power.Value = 100; 399 weapon.Power.DefaultValue = 100; 349 400 break; 350 401 case 2: … … 352 403 weapon.ProjectileCollision = weaponhit; 353 404 weapon.FireRate = 1; 354 weapon.Power.DefaultValue = 3000;355 weapon.Power.Value = 3000;405 weapon.Power.DefaultValue = 1200; 406 weapon.Power.Value = 1200; 356 407 break; 357 408 case 3: 358 409 weapon = new PlasmaCannon(0, 0); 359 410 weapon.ProjectileCollision = weaponhit; 360 weapon.FireRate = 1 ;411 weapon.FireRate = 1.5; 361 412 weapon.Power.Value = 750; 362 413 weapon.Power.DefaultValue = 750; … … 371 422 weapon2 = new AssaultRifle(0, 0); 372 423 weapon2.ProjectileCollision = weaponhit; 373 weapon2.FireRate = 4; 424 weapon2.FireRate = 4.5; 425 weapon2.Power.Value = 100; 426 weapon2.Power.DefaultValue = 100; 374 427 break; 375 428 case 2: 376 429 weapon2 = new LaserGun(0, 0); 377 430 weapon2.ProjectileCollision = weaponhit; 378 weapon2.FireRate = 0.5; 431 weapon2.FireRate = 1; 432 weapon2.Power.DefaultValue = 1200; 433 weapon2.Power.Value = 1200; 379 434 break; 380 435 case 3: 381 436 weapon2 = new PlasmaCannon(0, 0); 382 437 weapon2.ProjectileCollision = weaponhit; 383 weapon2.FireRate = 2; 438 weapon2.FireRate = 1.5; 439 weapon2.Power.Value = 750; 440 weapon2.Power.DefaultValue = 750; 384 441 break; 385 442 } … … 401 458 ammus.Image = shell; 402 459 ammus.Size *=0.4; 460 AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 461 ammus.CollisionIgnoreGroup = 4; 403 462 } 404 463 if (ase is LaserGun) 405 464 { 465 ammus.Size *= 2; 406 466 ammus.IgnoresCollisionResponse = true; 407 467 } 408 468 if (ase is PlasmaCannon) 409 469 { 410 ammus.Size *= 1.5; 470 ammus.Size *= 1.2; 471 AddCollisionHandler(ammus, CollisionHandler.DestroyObject); 472 ammus.IgnoresCollisionResponse = true; 473 ammus.CollisionIgnoreGroup = 3; 411 474 } 412 475 } … … 416 479 void weaponhit(PhysicsObject ammus, PhysicsObject kohde) 417 480 { 418 if (kohde.Tag == "hostile") kohde.Destroy(); 419 ammus.Destroy(); 420 } 421 481 482 if (kohde.Tag == "hostile") 483 { 484 Vihu vihollinen = kohde as Vihu; 485 vihollinen.Health.Value -= 1; 486 } 487 } 488 void Controlsship() 489 { 490 Keyboard.Listen(Key.W, ButtonState.Down, movement, null, 0, 100, ship); 491 Keyboard.Listen(Key.S, ButtonState.Down, movement, null, 0, -100, ship); 492 Keyboard.Listen(Key.A, ButtonState.Down, movement, null, -100, 0, ship); 493 Keyboard.Listen(Key.D, ButtonState.Down, movement, null, 100, 0, ship); 494 Keyboard.Listen(Key.Space, ButtonState.Down, fire, "", weapon); 495 Mouse.ListenMovement(0, Aim, ""); 496 Mouse.Listen(MouseButton.Left, ButtonState.Down, fire, "", weapon); 497 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 498 } 499 void Aim(AnalogState hiirenLiike) 500 { 501 Vector suunta = (Mouse.PositionOnWorld - ship.AbsolutePosition).Normalize(); 502 ship.Angle = suunta.Angle; 503 } 504 void movement(int x, int y, PhysicsObject ship) 505 { 506 ship.Push(new Vector(x, y)); 507 } 422 508 void Controlsship1() 423 509 { … … 454 540 Createship(); 455 541 Spawnhostiles(); 456 Controlsship 1();542 Controlsship(); 457 543 Timer a = new Timer(); 458 a.Interval = 5;544 a.Interval = 1; 459 545 a.Timeout += Spawnhostiles; 460 546 a.Start(); -
2013/26/OtsoR/Projekti/Projekti/ProjektiContent/ProjektiContent.contentproj
r4203 r4219 553 553 </Compile> 554 554 </ItemGroup> 555 <ItemGroup> 556 <Compile Include="pointer.png"> 557 <Name>pointer</Name> 558 <Importer>TextureImporter</Importer> 559 <Processor>TextureProcessor</Processor> 560 </Compile> 561 </ItemGroup> 562 <ItemGroup> 563 <Compile Include="Daah.mp3"> 564 <Name>Daah</Name> 565 <Importer>Mp3Importer</Importer> 566 <Processor>SongProcessor</Processor> 567 </Compile> 568 </ItemGroup> 555 569 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 556 570 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.