Changeset 2549
- Timestamp:
- 2011-08-04 14:57:03 (12 years ago)
- Location:
- 2011/31/JereK/Serades/Serades
- Files:
-
- 9 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/31/JereK/Serades/Serades/Serades/Peli.cs
r2531 r2549 9 9 public class Peli : TopDownPhysicsGame 10 10 { 11 ExplosionSystem rajahdys = 12 new ExplosionSystem(LoadImage("rajahdys"), 100); 13 bool kaksinpeli = false; 14 11 15 Vector[] vihollistenAloitukset = { new Vector(450,350), 12 16 new Vector(-450,350), 13 17 new Vector(450,-350), 14 18 new Vector(-450,-350)}; 15 Image olionkuva = LoadImage("alu s");19 Image olionkuva = LoadImage("alukset"); 16 20 Image karttakuva = LoadImage("kartta"); 17 21 Image vihokuva = LoadImage("vihollinen"); 18 22 Image taustakuva = LoadImage("taustakuva"); 19 Image oliokuva = LoadImage("alu s2");23 Image oliokuva = LoadImage("alukset2"); 20 24 Image pomonkuva = LoadImage("boss"); 25 Image taustaKuva = LoadImage("kartta7"); 26 27 21 28 PhysicsObject pelaaja1; 22 29 PhysicsObject pelaaja2; … … 24 31 LaserGun pelaaja2Pyssy; 25 32 List<Label> valikonKohdat; 33 PlasmaCannon pelaaja1Pyssy2; 34 PlasmaCannon pelaaja2Pyssy2; 35 36 37 Timer aaltoajastin; 26 38 27 39 … … 55 67 56 68 Label kohta3 = new Label("Lopeta ja poistu pelistä."); 57 kohta3.Position = new Vector(0, - 40);69 kohta3.Position = new Vector(0, -60); 58 70 valikonKohdat.Add(kohta3); 71 72 Label kohta4 = new Label("Ohjeet."); 73 kohta4.Position = new Vector(0, -30); 74 valikonKohdat.Add(kohta4); 59 75 60 76 foreach (Label valikonKohta in valikonKohdat) … … 66 82 Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, AloitaKaksinpeli, null); 67 83 Mouse.ListenOn(kohta3, MouseButton.Left, ButtonState.Pressed, Exit, null); 84 Mouse.ListenOn(kohta4, MouseButton.Left, ButtonState.Pressed, NäytäOhjeet, null); 68 85 69 86 Mouse.IsCursorVisible = true; … … 89 106 } 90 107 108 void NäytäOhjeet() 109 { 110 ClearAll(); 111 Level.Background.Image = taustaKuva; 112 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, ""); 113 Level.Background.FitToLevel(); 114 115 } 91 116 92 117 93 118 void LuoAlus() 94 119 { 95 pelaaja1 = new PhysicsObject(30, 30); 120 pelaaja1 = new PhysicsObject(50, 80); 121 pelaaja1.Tag = "pelaaja"; 96 122 Add(pelaaja1); 97 123 pelaaja1.LinearDamping = 0.96; … … 104 130 pelaaja1Pyssy.Angle = pelaaja1Pyssy.Angle + Angle.FromDegrees(90); 105 131 beam.Color = Color.Blue; 132 pelaaja1Pyssy.IsVisible = false; 133 pelaaja1Pyssy2 = new PlasmaCannon(20, 5); 134 135 pelaaja1.Add(pelaaja1Pyssy2); 136 pelaaja1Pyssy2.IsVisible = false; 137 106 138 } 107 139 108 140 void AsetaPelaaja2() 109 141 { 110 pelaaja2 = new PhysicsObject(30, 30); 142 pelaaja2 = new PhysicsObject(50, 80); 143 pelaaja2.Tag = "pelaaja"; 111 144 Add(pelaaja2); 112 145 pelaaja2.LinearDamping = 0.96; … … 120 153 beam.Color = Color.Blue; 121 154 pelaaja2.X = 30; 155 pelaaja2Pyssy.IsVisible = false; 156 pelaaja2Pyssy2 = new PlasmaCannon(20, 5); 157 pelaaja2.Add(pelaaja2Pyssy2); 158 pelaaja2Pyssy2.IsVisible = false; 159 122 160 } 123 161 … … 126 164 taso++; 127 165 128 if (taso < 2)129 { 130 MessageDisplay.Add(" Seuraava aalto alkaa!!");166 if (taso < 6) 167 { 168 MessageDisplay.Add("~Seuraava aalto alkaa!!"); 131 169 Timer.SingleShot(3, AloitaAalto); 132 170 } 133 171 else 134 172 { 135 MessageDisplay.Add(" VAROKAA POMOA");173 MessageDisplay.Add("~Hoitele nyt pomo-alus!!"); 136 174 Timer.SingleShot(3, AloitaPomotaistelu); 137 175 } … … 140 178 void AloitaPomotaistelu() 141 179 { 142 PhysicsObject Pomo = new PhysicsObject(200, 100); 180 Alus Pomo = new Alus(100, 200); 181 if (kaksinpeli) Pomo.HP = 500; 182 else Pomo.HP = 200; 183 143 184 Pomo.Image = pomonkuva; 144 185 Add(Pomo); 145 Pomo.X = 450; 146 Pomo.Y = 350; 186 Pomo.IgnoresExplosions = true; 187 Pomo.X = 400; 188 Pomo.Y = 300; 189 Pomo.Tag = "vihollinen"; 190 191 TagFollowerBrain seuraajanAivot = new TagFollowerBrain("pelaaja", 2000); 192 seuraajanAivot.TargetFollowDistance = 9999999; 193 seuraajanAivot.TargetCloseDistance = 1; 194 Pomo.Brain = seuraajanAivot; 195 seuraajanAivot.Active = true; 196 Add(Pomo); 197 198 //viholliset.Add(Pomo); 199 147 200 148 201 PlasmaCannon plasmaTykki = new PlasmaCannon(20, 5); 149 202 Pomo.Add(plasmaTykki); 203 plasmaTykki.Angle = plasmaTykki.Angle - Angle.FromDegrees(90); 150 204 plasmaTykki.PlasmaParticleCollision = PlasmaPalloOsuu; 151 205 152 206 Timer pomonkaantoajastin = new Timer(); 207 pomonkaantoajastin.Interval = 0.1; 208 pomonkaantoajastin.Timeout += delegate { PomoKaantyy(Pomo); }; 209 pomonkaantoajastin.Start(); 210 211 Timer ajastin = new Timer(); 212 ajastin.Interval = 2; 213 ajastin.Timeout += delegate { PomoAmpuu(plasmaTykki); }; 214 ajastin.Start(); 215 } 216 217 void PomoKaantyy(PhysicsObject pomo) 218 { 219 pomo.Angle = pomo.Velocity.Angle + Angle.FromDegrees(90); 220 } 221 222 void PomoAmpuu(Weapon ase) 223 { 224 ase.Shoot(); 153 225 } 154 226 155 227 void AloitaAalto() 156 228 { 157 Timerajastin = new Timer();158 a jastin.Interval = 3.0 - (taso / 10.0);159 a jastin.Timeout += LuoVihollinen;160 161 a jastin.Start(2);229 aaltoajastin = new Timer(); 230 aaltoajastin.Interval = 3.0 - (taso / 10.0); 231 aaltoajastin.Timeout += LuoVihollinen; 232 233 aaltoajastin.Start(10); 162 234 } 163 235 164 236 void Aloitakaksin() 165 237 { 166 Timerajastin = new Timer();167 a jastin.Interval = 1.0 - (taso / 10.0);168 a jastin.Timeout += LuoVihollinen;169 a jastin.Start(30);238 aaltoajastin = new Timer(); 239 aaltoajastin.Interval = 1.0 - (taso / 10.0); 240 aaltoajastin.Timeout += LuoVihollinen; 241 aaltoajastin.Start(20); 170 242 } 171 243 … … 180 252 Keyboard.Listen(Key.Down, ButtonState.Down, 181 253 Kaasu, null, pelaaja1); 182 Keyboard.Listen(Key.RightControl, ButtonState. Pressed, Ammu, null, pelaaja1Pyssy);254 Keyboard.Listen(Key.RightControl, ButtonState.Down, Ammu, null, pelaaja1Pyssy); 183 255 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, ""); 256 Keyboard.Listen(Key.NumPad0 , ButtonState.Down, Ammu2, null, pelaaja1Pyssy2); 184 257 } 185 258 … … 194 267 Keyboard.Listen(Key.S, ButtonState.Down, 195 268 Kaasu, null, pelaaja2); 196 Keyboard.Listen(Key.LeftControl, ButtonState.Pressed, Ammu, null, pelaaja2Pyssy); 269 Keyboard.Listen(Key.LeftControl, ButtonState.Down, Ammu, null, pelaaja2Pyssy); 270 Keyboard.Listen(Key.Tab , ButtonState.Down, Ammu2, null, pelaaja2Pyssy2); 197 271 } 198 272 … … 203 277 } 204 278 279 void Ammu2(Weapon ase) 280 { 281 PhysicsObject ammus2 = ase.Shoot(); 282 if (ammus2 != null) AddCollisionHandler(ammus2, ammus2Osuu); 283 } 284 285 void ammus2Osuu(PhysicsObject ammus, PhysicsObject kohde) 286 { 287 ammus.Destroy(); 288 289 if (kohde.Tag.ToString() == "vihollinen") 290 { 291 Alus alus = (Alus)kohde; 292 alus.HP--; 293 294 if (alus.HP < 1) 295 { 296 rajahdys.AddEffect(kohde.X, kohde.Y, 500); 297 kohde.Destroy(); 298 if (viholliset.Contains(kohde)) 299 { 300 viholliset.Remove(kohde); 301 if (viholliset.Count == 0 && aaltoajastin.Enabled == false) { SeuraavaTaso(); } 302 } 303 } 304 } 305 } 205 306 206 307 void Kaasu(PhysicsObject alus) … … 218 319 for (int i = 0; i < 4; i++) 219 320 { 220 PhysicsObject vihollinen = new PhysicsObject(40, 40); 321 Alus vihollinen = new Alus(40, 40); 322 vihollinen.HP = 1; 323 if (kaksinpeli) vihollinen.HP = 5; 324 else vihollinen.HP = 1; 221 325 vihollinen.X = 450; 222 326 vihollinen.Y = 350; … … 226 330 vihollinen.Tag = "vihollinen"; 227 331 228 FollowerBrain seuraajanAivot = new FollowerBrain(); 229 seuraajanAivot.Target = pelaaja1; 230 seuraajanAivot.Speed = 50; 231 seuraajanAivot.TargetFollowDistance = 600; 232 seuraajanAivot.FollowAlways = true; 332 TagFollowerBrain seuraajanAivot = new TagFollowerBrain("pelaaja",5000); 333 seuraajanAivot.TargetFollowDistance = 9999999; 233 334 seuraajanAivot.TargetCloseDistance = 1; 234 seuraajanAivot.StopWhenTargetClose = false; 235 seuraajanAivot.TargetClose += mitaTapahtuuKunOllaanLahella; 335 //seuraajanAivot. += mitaTapahtuuKunOllaanLahella; 236 336 vihollinen.Brain = seuraajanAivot; 237 337 seuraajanAivot.Active = true; … … 242 342 } 243 343 244 void mitaTapahtuuKunOllaanLahella(object lahettajaAivot, EventArgs e)245 {246 //TODO247 }248 249 344 void LaserSadeOsuu(PhysicsObject ammus, PhysicsObject kohde) 250 345 { 251 346 ammus.Destroy(); 252 Explosion rajahdys = new Explosion(50); 253 rajahdys.Position = ammus.Position; 347 348 349 if (kohde.Tag.ToString() == "vihollinen") 350 { 351 Alus alus = (Alus)kohde; 352 alus.HP--; 353 354 if (alus.HP < 1) 355 { 356 rajahdys.AddEffect(kohde.X, kohde.Y, 500); 357 kohde.Destroy(); 358 if (viholliset.Contains(kohde)) 359 { 360 viholliset.Remove(kohde); 361 if (viholliset.Count == 0 && aaltoajastin.Enabled == false) { SeuraavaTaso(); } 362 } 363 } 364 365 } 366 } 367 368 void PlasmaPalloOsuu(PhysicsObject pallo, PhysicsObject kohde) 369 { 370 if (kohde.Tag.ToString() == "pelaaja") 371 { 372 rajahdys.AddEffect(kohde.X, kohde.Y, 200); 373 kohde.Destroy(); 374 } 375 } 376 377 void AloitaPeli() 378 { 379 ClearAll(); 380 kaksinpeli = false; 254 381 Add(rajahdys); 255 256 if (kohde.Tag.ToString() == "vihollinen")257 {258 kohde.Destroy();259 if (viholliset.Contains(kohde)) {260 viholliset.Remove(kohde);261 if (viholliset.Count == 0) { SeuraavaTaso(); }262 }263 }264 }265 266 void PlasmaPalloOsuu(PhysicsObject pallo, PhysicsObject kohde)267 {268 if (kohde.Tag.ToString() == "pelaaja")269 {270 kohde.Destroy();271 }272 }273 274 void AloitaPeli()275 {276 ClearAll();277 382 MessageDisplay.TextColor = Color.OrangeRed; 278 383 … … 296 401 { 297 402 ClearAll(); 403 kaksinpeli = true; 404 Add(rajahdys); 298 405 MessageDisplay.TextColor = Color.OrangeRed; 299 406 LuoAlus(); … … 306 413 Level.Background.CreateStars(2000); 307 414 Aloitakaksin(); 415 //AloitaPomotaistelu(); 308 416 } 309 417 } 418 419 public class Alus : PhysicsObject 420 { 421 public int HP = 200; 422 423 public Alus(int width, int height) 424 : base(width, height) 425 { 426 427 } 428 } -
2011/31/JereK/Serades/Serades/SeradesContent/SeradesContent.contentproj
r2531 r2549 86 86 </Compile> 87 87 </ItemGroup> 88 <ItemGroup> 89 <Compile Include="rajahdys.png"> 90 <Name>rajahdys</Name> 91 <Importer>TextureImporter</Importer> 92 <Processor>TextureProcessor</Processor> 93 </Compile> 94 </ItemGroup> 95 <ItemGroup> 96 <Compile Include="uusialus.png"> 97 <Name>uusialus</Name> 98 <Importer>TextureImporter</Importer> 99 <Processor>TextureProcessor</Processor> 100 </Compile> 101 </ItemGroup> 102 <ItemGroup> 103 <Compile Include="uusialu1.png"> 104 <Name>uusialu1</Name> 105 <Importer>TextureImporter</Importer> 106 <Processor>TextureProcessor</Processor> 107 </Compile> 108 </ItemGroup> 109 <ItemGroup> 110 <Compile Include="uusialu2.png"> 111 <Name>uusialu2</Name> 112 <Importer>TextureImporter</Importer> 113 <Processor>TextureProcessor</Processor> 114 </Compile> 115 </ItemGroup> 116 <ItemGroup> 117 <Compile Include="alukset.png"> 118 <Name>alukset</Name> 119 <Importer>TextureImporter</Importer> 120 <Processor>TextureProcessor</Processor> 121 </Compile> 122 </ItemGroup> 123 <ItemGroup> 124 <Compile Include="alukset2.png"> 125 <Name>alukset2</Name> 126 <Importer>TextureImporter</Importer> 127 <Processor>TextureProcessor</Processor> 128 </Compile> 129 </ItemGroup> 130 <ItemGroup> 131 <Compile Include="kartta7.png"> 132 <Name>kartta7</Name> 133 <Importer>TextureImporter</Importer> 134 <Processor>TextureProcessor</Processor> 135 </Compile> 136 </ItemGroup> 88 137 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 89 138 <!-- 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.