Changeset 951
- Timestamp:
- 2010-06-17 15:06:08 (13 years ago)
- Location:
- 2010/24/arhetaka/FysiikkaPeli1/FysiikkaPeli1
- Files:
-
- 18 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/24/arhetaka/FysiikkaPeli1/FysiikkaPeli1/Content/Content.contentproj
r911 r951 117 117 </Compile> 118 118 </ItemGroup> 119 <ItemGroup> 120 <Compile Include="special2.png"> 121 <Name>special2</Name> 122 <Importer>TextureImporter</Importer> 123 <Processor>TextureProcessor</Processor> 124 </Compile> 125 </ItemGroup> 126 <ItemGroup> 127 <Compile Include="plasma.png"> 128 <Name>plasma</Name> 129 <Importer>TextureImporter</Importer> 130 <Processor>TextureProcessor</Processor> 131 </Compile> 132 </ItemGroup> 133 <ItemGroup> 134 <Compile Include="special22.png"> 135 <Name>special22</Name> 136 <Importer>TextureImporter</Importer> 137 <Processor>TextureProcessor</Processor> 138 </Compile> 139 </ItemGroup> 140 <ItemGroup> 141 <Compile Include="special23.png"> 142 <Name>special23</Name> 143 <Importer>TextureImporter</Importer> 144 <Processor>TextureProcessor</Processor> 145 </Compile> 146 </ItemGroup> 147 <ItemGroup> 148 <Compile Include="alus121.png"> 149 <Name>alus121</Name> 150 <Importer>TextureImporter</Importer> 151 <Processor>TextureProcessor</Processor> 152 </Compile> 153 <Compile Include="alus122.png"> 154 <Name>alus122</Name> 155 <Importer>TextureImporter</Importer> 156 <Processor>TextureProcessor</Processor> 157 </Compile> 158 </ItemGroup> 159 <ItemGroup> 160 <Compile Include="alus221.png"> 161 <Name>alus221</Name> 162 <Importer>TextureImporter</Importer> 163 <Processor>TextureProcessor</Processor> 164 </Compile> 165 <Compile Include="alus222.png"> 166 <Name>alus222</Name> 167 <Importer>TextureImporter</Importer> 168 <Processor>TextureProcessor</Processor> 169 </Compile> 170 </ItemGroup> 171 <ItemGroup> 172 <Compile Include="lisaase1.png"> 173 <Name>lisaase1</Name> 174 <Importer>TextureImporter</Importer> 175 <Processor>TextureProcessor</Processor> 176 </Compile> 177 <Compile Include="lisaase2.png"> 178 <Name>lisaase2</Name> 179 <Importer>TextureImporter</Importer> 180 <Processor>TextureProcessor</Processor> 181 </Compile> 182 <Compile Include="lisaase3.png"> 183 <Name>lisaase3</Name> 184 <Importer>TextureImporter</Importer> 185 <Processor>TextureProcessor</Processor> 186 </Compile> 187 <Compile Include="lisaase4.png"> 188 <Name>lisaase4</Name> 189 <Importer>TextureImporter</Importer> 190 <Processor>TextureProcessor</Processor> 191 </Compile> 192 </ItemGroup> 193 <ItemGroup> 194 <Compile Include="plasma2.png"> 195 <Name>plasma2</Name> 196 <Importer>TextureImporter</Importer> 197 <Processor>TextureProcessor</Processor> 198 </Compile> 199 </ItemGroup> 119 200 </Project> -
2010/24/arhetaka/FysiikkaPeli1/FysiikkaPeli1/Peli.cs
r911 r951 13 13 PhysicsObject alaReuna; 14 14 PhysicsObject ylaReuna; 15 16 ImageDisplay alus1PerusAse; 17 ImageDisplay alus2PerusAse; 18 19 ImageDisplay alus1SpecialAse; 20 ImageDisplay alus2SpecialAse; 15 21 16 22 int siirtymaLaidassa = 80; … … 38 44 Timer p2specialTimer; 39 45 int specialNopeus = 500; 46 int p1special_reload_speed = 1; 47 int p2special_reload_speed = 1; 48 49 int p1kaanto_nopeus = 2; 50 int p2kaanto_nopeus = 2; 51 52 int alus1nopeus = 2000; 53 int alus2nopeus = 2000; 40 54 41 55 Animation alus1_kaasu_tekst; 42 56 Animation alus2_kaasu_tekst; 57 Animation alus1_idle_tekst; 58 Animation alus2_idle_tekst; 59 60 Animation lisaase_anim; 61 Animation perusase_anim; 62 63 Animation special_animation; 64 43 65 double resolutionX; 44 66 double resolutionY; … … 50 72 bool alus2_kaasuttaa = false; 51 73 74 bool lisaaseita = true; 75 52 76 int perusAmmusKoko = 3; 53 77 int AlustenHealth = 10; … … 56 80 int partikkelit = 50; 57 81 82 Timer reSpawnTimer1; 83 Timer reSpawnTimer2; 84 int respawntimer = 3; 85 58 86 protected override void Begin() 59 87 { … … 63 91 { 64 92 ClearAll(); 93 NollaaMuuttujat(); 94 95 LuoKentta(); 96 AsetaOhjaimet(); 97 LisaaLaskurit(); 98 } 99 void NollaaMuuttujat() 100 { 101 p1special_reload_speed = 1; 102 p2special_reload_speed = 1; 103 104 p1kaanto_nopeus = 2; 105 p2kaanto_nopeus = 2; 106 107 alus1nopeus = 1000; 108 alus2nopeus = 1000; 109 65 110 alus1_kaasuttaa = false; 66 111 alus2_kaasuttaa = false; 67 112 p1specialkentalla = false; 68 113 p2specialkentalla = false; 69 LuoKentta();70 AsetaOhjaimet();71 LisaaLaskurit();72 114 } 73 115 void LuoKentta() 74 116 { 117 resolutionX = Screen.Width; 118 resolutionY = Screen.Height; 119 120 reSpawnTimer1 = new Timer(); 121 reSpawnTimer2 = new Timer(); 122 Add(reSpawnTimer1); 123 Add(reSpawnTimer2); 124 75 125 TeeGalaksi(); 76 TeeAsteroidi(0,0, 3, 200);77 TeeAlukset( );126 TeeAsteroidi(0,0,5, 200); 127 TeeAlukset(true, true); 78 128 UpDate(); //tekee ajopisteet ja tutkii ovatko alukset vielä kentällä 79 129 TeeSpecial(); //tekee special aseet ja lisää kuuntelijat 80 TeeHealth(); 81 resolutionX = Screen.Width; 82 resolutionY = Screen.Height; 83 TeeReunat(); 130 TeeHealth(); 131 TeeAseidenKuvat(); 84 132 Level.Background.CreateStars(3000); 133 134 TeeReunat(); 85 135 Camera.ZoomToLevel(); 136 MessageDisplay.X = 0; 137 MessageDisplay.TextColor = Color.White; 138 86 139 } 87 140 void TeeGalaksi() … … 122 175 Add(asteroidi); 123 176 } 124 } 125 } 126 void TeeAlukset() 127 { 128 alus1 = LuoAlus(1, Level.Left + 20.0, 0.0); 129 alus1.Tag = "alus1"; 130 alus1.Image = LoadImage("alus12"); 131 alus1.Color = Color.Red; 132 133 Image[] alus_kaasu1 = LoadImages( 134 "alus12", 135 "alus12_kaasuttaa" 136 ); 137 alus1_kaasu_tekst = new Animation(alus_kaasu1); 138 alus1_kaasu_tekst.FPS = 10; 139 alus1.Animation = alus1_kaasu_tekst; 140 141 alus1.LinearDamping = alustenIlmanvastus; 142 143 alus2 = LuoAlus(2, Level.Right - 20.0, 0.0); 144 alus2.Tag = "alus2"; 145 alus2.Image = LoadImage("alus22"); 146 alus2.Color = Color.Blue; 147 148 Image[] alus_kaasu2 = LoadImages( 149 "alus22", 150 "alus22_kaasuttaa" 151 ); 152 153 alus2_kaasu_tekst = new Animation(alus_kaasu2); 154 alus2_kaasu_tekst.FPS = 5; 155 alus2.Animation = alus2_kaasu_tekst; 156 alus2.Angle = Angle.StraightAngle; 157 alus2.LinearDamping = alustenIlmanvastus; 158 177 else if (lisaaseita && koko > 20) 178 { 179 PhysicsObject lisaase = new PhysicsObject(koko, koko); 180 lisaase.Color = Color.White; 181 lisaase.Tag = "lisaase"; 182 lisaase.Mass = koko; 183 lisaase.Image = LoadImage("lisaase1"); 184 Image[] lisaaseimaget = LoadImages( 185 "lisaase1", 186 "lisaase2", 187 "lisaase3", 188 "lisaase4" 189 ); 190 lisaase_anim = new Animation(lisaaseimaget); 191 lisaase_anim.FPS = 1.5; 192 lisaase.Animation = lisaase_anim; 193 lisaase.Animation.Start(); 194 lisaase.X = x; 195 lisaase.Y = y; 196 Add(lisaase); 197 } 198 } 199 } 200 void TeeAlukset(bool p1, bool p2) 201 { 202 if (p1) 203 { 204 alus1 = LuoAlus(1, Level.Left + 20.0, 0.0); 205 alus1.Tag = "alus1"; 206 alus1.Image = LoadImage("alus12"); 207 alus1.Color = Color.Red; 208 AddCollisionHandler(alus1, AlusOsuu); 209 210 Image[] alus1idle = LoadImages( 211 "alus12", 212 "alus121", 213 "alus122" 214 ); 215 alus1_idle_tekst = new Animation(alus1idle); 216 alus1_idle_tekst.FPS = 1.5; 217 alus1.Animation = alus1_idle_tekst; 218 alus1.Animation.Start(); 219 220 Image[] alus_kaasu1 = LoadImages( 221 "alus12", 222 "alus12_kaasuttaa" 223 ); 224 alus1_kaasu_tekst = new Animation(alus_kaasu1); 225 alus1_kaasu_tekst.FPS = 10; 226 alus1.LinearDamping = alustenIlmanvastus; 227 228 229 } 230 if (p2) 231 { 232 alus2 = LuoAlus(2, Level.Right - 20.0, 0.0); 233 alus2.Tag = "alus2"; 234 alus2.Image = LoadImage("alus22"); 235 alus2.Color = Color.Blue; 236 AddCollisionHandler(alus2, AlusOsuu); 237 238 Image[] alus2idle = LoadImages( 239 "alus22", 240 "alus221", 241 "alus222" 242 ); 243 alus2_idle_tekst = new Animation(alus2idle); 244 alus2_idle_tekst.FPS = 1.5; 245 alus2.Animation = alus2_idle_tekst; 246 alus2.Animation.Start(); 247 248 249 Image[] alus_kaasu2 = LoadImages( 250 "alus22", 251 "alus22_kaasuttaa" 252 ); 253 alus2_kaasu_tekst = new Animation(alus_kaasu2); 254 alus2_kaasu_tekst.FPS = 10; 255 256 alus2.Angle = Angle.StraightAngle; 257 alus2.LinearDamping = alustenIlmanvastus; 258 } 159 259 } 160 260 void TeeReunat() … … 205 305 Add(alaReuna); 206 306 } 307 void TeeAseidenKuvat() 308 { 309 alus1PerusAse = new ImageDisplay(); 310 TeeAsenaytto(alus1PerusAse, Screen.Left + 50, Screen.Top - 50); 311 alus1PerusAse.Image = LoadImage("plasma"); 312 Image[] alus_perus = LoadImages( 313 "plasma", 314 "plasma2" 315 ); 316 perusase_anim = new Animation(alus_perus); 317 alus1PerusAse.Animation = perusase_anim; 318 alus1PerusAse.Animation.FPS = 15; 319 alus1PerusAse.Animation.Start(); 320 321 Add(alus1PerusAse); 322 323 alus2PerusAse = new ImageDisplay(); 324 TeeAsenaytto(alus2PerusAse, Screen.Right - 50, Screen.Top - 50); 325 alus2PerusAse.Image = LoadImage("plasma"); 326 alus2PerusAse.Animation = perusase_anim; 327 alus2PerusAse.Animation.FPS = 15; 328 alus2PerusAse.Animation.Start(); 329 Add(alus2PerusAse); 330 331 Image[] alus_special = LoadImages( 332 "special2", 333 "special22", 334 "special23" 335 ); 336 special_animation = new Animation(alus_special); 337 338 alus1SpecialAse = new ImageDisplay(); 339 TeeAsenaytto(alus1SpecialAse, Screen.Left + 100, Screen.Top - 50); 340 alus1SpecialAse.Image = LoadImage("special2"); 341 alus1SpecialAse.Animation = special_animation; 342 alus1SpecialAse.Animation.FPS = 4; 343 alus1SpecialAse.Animation.Start(); 344 Add(alus1SpecialAse); 345 346 alus2SpecialAse = new ImageDisplay(); 347 TeeAsenaytto(alus2SpecialAse, Screen.Right - 100, Screen.Top - 50); 348 alus2SpecialAse.Image = LoadImage("special2"); 349 alus2SpecialAse.Animation = special_animation; 350 alus2SpecialAse.Animation.FPS = 4; 351 alus2SpecialAse.Animation.Start(); 352 353 Add(alus2SpecialAse); 354 } 355 void TeeAsenaytto(ImageDisplay naytto, double x, double y) 356 { 357 naytto.AutoSize = false; 358 naytto.Width = 40; 359 naytto.Height = 40; 360 naytto.X = x; 361 naytto.Y = y; 362 } 363 364 207 365 PhysicsObject LuoAlus(int kumpi, double x, double y) 208 366 { … … 221 379 void LisaaLaskurit() 222 380 { 223 p1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0);224 p2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0);225 } 226 IntMeter LuoPisteLaskuri(double x, double y )381 p1Pisteet = LuoPisteLaskuri(Screen.Left + 75.0, Screen.Top - 250.0, Color.Red); 382 p2Pisteet = LuoPisteLaskuri(Screen.Right - 75.0, Screen.Top - 250.0, Color.Blue); 383 } 384 IntMeter LuoPisteLaskuri(double x, double y, Color vari) 227 385 { 228 386 IntMeter laskuri = new IntMeter(0); … … 232 390 naytto.X = x; 233 391 naytto.Y = y; 234 naytto.ValueColor = Color.White;235 // laskuri.UpperLimit += Voitto;236 237 //Add(naytto);392 naytto.ValueColor = vari; 393 //naytto.Width = 50; 394 //naytto.Height = 50; 395 Add(naytto); 238 396 return laskuri; 239 397 } … … 263 421 void KaannaVasen(PhysicsObject alus, int nopeus) 264 422 { 265 alus.AngularVelocity = 4; 423 if (alus.Tag == "alus1") 424 { 425 alus.AngularVelocity = p1kaanto_nopeus; 426 } 427 else if (alus.Tag == "alus2") 428 { 429 alus.AngularVelocity = p2kaanto_nopeus; 430 } 266 431 } 267 432 void KaannaOikea(PhysicsObject alus, int nopeus) 268 433 { 269 alus.AngularVelocity = -4; 270 } 434 if (alus.Tag == "alus1") 435 { 436 alus.AngularVelocity = -p1kaanto_nopeus; 437 } 438 else if (alus.Tag == "alus2") 439 { 440 alus.AngularVelocity = -p2kaanto_nopeus; 441 } 442 } 443 271 444 void PysaytaPyoriminen(PhysicsObject alus, int nopeus) 272 445 { … … 276 449 { 277 450 Angle aluksenKulma = alus.Angle; 278 Vector impulssi = Vector.FromLengthAndAngle(2000, aluksenKulma); 451 Vector impulssi; 452 if (alus.Tag == "alus1") 453 { 454 impulssi = Vector.FromLengthAndAngle(alus1nopeus, aluksenKulma); 455 } 456 else 457 { 458 impulssi = Vector.FromLengthAndAngle(alus2nopeus, aluksenKulma); 459 } 279 460 double aluksenAste = aluksenKulma.Degree; 280 461 alus.Push(impulssi); … … 283 464 { 284 465 alus1_kaasuttaa = true; 466 alus1.Animation = alus1_kaasu_tekst; 467 285 468 } 286 469 if (alus.Tag == "alus2") 287 470 { 288 471 alus2_kaasuttaa = true; 472 alus2.Animation = alus2_kaasu_tekst; 289 473 } 290 474 … … 296 480 { 297 481 alus1_kaasuttaa = false; 482 alus1.Animation = alus1_idle_tekst; 483 298 484 } 299 485 if (alus.Tag == "alus2") 300 486 { 301 487 alus2_kaasuttaa = false; 488 alus2.Animation = alus2_idle_tekst; 302 489 } 303 490 } … … 389 576 void AlusOsuu(PhysicsObject alus, PhysicsObject kohde) 390 577 { 391 392 } 578 if (kohde.Tag.ToString().Length > 8) 579 { 580 string kohdestr = kohde.Tag.ToString(); 581 if (alus.Tag == "alus2" && kohdestr[8] == 'i') 582 { 583 p2healthmittari.Value -= 1; 584 } 585 else if (alus.Tag == "alus1" && kohdestr[8] == 'i') 586 { 587 p1healthmittari.Value -= 1; 588 } 589 } 590 if (kohde.Tag == "lisaase") 591 { 592 int mikaase = RandomGen.NextInt(4); 593 if (mikaase == 0) 594 { 595 if (alus.Tag == "alus1") 596 { 597 p1special_reload_speed += 1; 598 MessageDisplay.Add("Pelaaja 1 special latausnopeus +"); 599 } 600 if (alus.Tag == "alus2") 601 { 602 p2special_reload_speed += 1; 603 MessageDisplay.Add("Pelaaja 2 special latausnopeus +"); 604 } 605 } 606 if (mikaase == 1) 607 { 608 if (alus.Tag == "alus1") 609 { 610 p1healthmittari.Value += 3; 611 MessageDisplay.Add("Pelaaja 1 health +3"); 612 } 613 if (alus.Tag == "alus2") 614 { 615 p2healthmittari.Value += 3; 616 MessageDisplay.Add("Pelaaja 2 health +3"); 617 } 618 } 619 if (mikaase == 2) 620 { 621 if (alus.Tag == "alus1") 622 { 623 alus1nopeus += 1000; 624 MessageDisplay.Add("Pelaaja 1 nopeus +"); 625 } 626 if (alus.Tag == "alus2") 627 { 628 alus2nopeus += 1000; 629 MessageDisplay.Add("Pelaaja 2 nopeus +"); 630 } 631 } 632 if (mikaase == 3) 633 { 634 if (alus.Tag == "alus1") 635 { 636 p1kaanto_nopeus += 1; 637 MessageDisplay.Add("Pelaaja 1 kääntönopeus +"); 638 } 639 if (alus.Tag == "alus2") 640 { 641 p2kaanto_nopeus += 1; 642 MessageDisplay.Add("Pelaaja 2 kääntönopeus +"); 643 } 644 } 645 kohde.Destroy(); 646 } 647 } 393 648 void UpDate() 394 649 { … … 493 748 p1health.Max = AlustenHealth; 494 749 p1healthmittari = new DoubleMeter(AlustenHealth); 750 p1healthmittari.MaxValue = AlustenHealth; 495 751 p1healthmittari.MinValue = 0; 496 752 p1healthmittari.LowerLimit += Voitto; … … 499 755 p1health.ValueColor = Color.Red; 500 756 p1health.X = Screen.Left + 50; 501 p1health.Y = Screen.Top - 1 00;757 p1health.Y = Screen.Top - 150; 502 758 Add(p1health); 503 759 … … 505 761 p2health.Max = AlustenHealth; 506 762 p2healthmittari = new DoubleMeter(AlustenHealth); 763 p2healthmittari.MaxValue = AlustenHealth; 507 764 p2healthmittari.MinValue = 0; 508 765 p2healthmittari.LowerLimit += Voitto; … … 511 768 p2health.ValueColor = Color.Blue; 512 769 p2health.X = Screen.Right - 50; 513 p2health.Y = Screen.Top - 1 00;770 p2health.Y = Screen.Top - 150; 514 771 Add(p2health); 515 772 } … … 545 802 p1special.BindTo(p1specialTeho); 546 803 p1special.X = Screen.Left + 100; 547 p1special.Y = Screen.Top - 1 00;804 p1special.Y = Screen.Top - 150; 548 805 p1special.Width = 40; 549 806 Add(p1special); … … 554 811 p2special.BindTo(p2specialTeho); 555 812 p2special.X = Screen.Right - 100; 556 p2special.Y = Screen.Top - 1 00;813 p2special.Y = Screen.Top - 150; 557 814 p2special.Width = 40; 558 815 Add(p2special); … … 562 819 if (alus.Tag == "alus1" && !p1specialkentalla) 563 820 { 564 p1specialTeho.Value += 1;821 p1specialTeho.Value += p1special_reload_speed; 565 822 } 566 823 if (alus.Tag == "alus2" && !p2specialkentalla) 567 824 { 568 p2specialTeho.Value += 1;825 p2specialTeho.Value += p2special_reload_speed; 569 826 } 570 827 … … 582 839 ammus.Tag = alus.Tag + "special"; 583 840 AddCollisionHandler(ammus, AmmusOsuu); 584 ammus.Image = LoadImage("special ");841 ammus.Image = LoadImage("special2"); 585 842 ammus.CanRotate = true; 586 843 ammus.AngularVelocity = 3; … … 592 849 p1specialTimer.Tag = ammus; 593 850 p1specialTimer.Interval = specialLifeTime; 594 p1specialTimer.Trigger += new Timer.TriggerHandler(Rajaytap1Special); // // asetetaan tapahtuma, kun aikaLaskuri kun 5 sekuntia on kulunut.851 p1specialTimer.Trigger += new Timer.TriggerHandler(Rajaytap1Special); 595 852 p1specialTimer.Start(); 596 853 p1specialTeho.Value = 1; … … 608 865 ammus.Tag = alus.Tag + "special"; 609 866 AddCollisionHandler(ammus, AmmusOsuu); 610 ammus.Image = LoadImage("special ");867 ammus.Image = LoadImage("special2"); 611 868 ammus.CanRotate = true; 612 869 ammus.AngularVelocity = 3; … … 618 875 p2specialTimer.Tag = ammus; 619 876 p2specialTimer.Interval = specialLifeTime; 620 p2specialTimer.Trigger += new Timer.TriggerHandler(Rajaytap2Special); // // asetetaan tapahtuma, kun aikaLaskuri kun 5 sekuntia on kulunut.877 p2specialTimer.Trigger += new Timer.TriggerHandler(Rajaytap2Special); 621 878 p2specialTimer.Start(); 622 879 p2specialTeho.Value = 1; … … 651 908 MessageDisplay.TextColor = Color.White; 652 909 MessageDisplay.Add("Pelaaja 1 voitti pelin."); 910 p1Pisteet.Value += 1; 653 911 TuhoaAlus(alus2); 912 reSpawnTimer2.Interval = respawntimer; 913 reSpawnTimer2.Trigger += new Timer.TriggerHandler(ReSpawnp2); 914 reSpawnTimer2.Start(); 915 654 916 } 655 917 if (p1healthmittari <= 0) … … 657 919 MessageDisplay.TextColor = Color.White; 658 920 MessageDisplay.Add("Pelaaja 2 voitti pelin."); 659 TuhoaAlus(alus1); 921 p2Pisteet.Value += 1; 922 TuhoaAlus(alus1); 923 reSpawnTimer1.Interval = respawntimer; 924 reSpawnTimer1.Trigger += new Timer.TriggerHandler(ReSpawnp1); 925 reSpawnTimer1.Start(); 660 926 } 661 927 } … … 725 991 alus.Destroy(); 726 992 } 993 private void ReSpawnp1(Timer sender) 994 { 995 sender.Stop(); 996 TeeAlukset(true, false); 997 } 998 999 private void ReSpawnp2(Timer sender) 1000 { 1001 sender.Stop(); 1002 TeeAlukset(false, true); 1003 } 727 1004 }
Note: See TracChangeset
for help on using the changeset viewer.