public void OnExplosionHappened(object source, ExplosionEventArgs e) { // GrenadeExplosion1.Play(0.5f, 0, 0); PlayRandomSound(GrenadeExplosion1, GrenadeExplosion2, GrenadeExplosion3); Explosion explosion = e.Explosion; //for (int i = 0; i < 10; i++) //{ // Emitter SparkEmitter = new Emitter(RoundSparkTexture, // new Vector2(explosion.Position.X, explosion.Position.Y), // new Vector2(0, 0), // new Vector2(1, 2), new Vector2(180 * 16, 200 * 16), 0.8f, true, new Vector2(0, 360), new Vector2(1, 3), // new Vector2(0.1f, 0.3f), Color.Orange, Color.OrangeRed, 0.05f, 0.5f, 10, 5, false, // new Vector2(explosion.Position.Y + 16, explosion.Position.Y + 16), null, 0, // false, false, new Vector2(3, 5), new Vector2(90 - 40, 90 + 40), 0.2f, true); // EmitterList.Add(SparkEmitter); //} Emitter ExplosionEmitter = new Emitter(ExplosionParticle2, new Vector2(explosion.Position.X, explosion.Position.Y + 16), new Vector2(20, 160), new Vector2(0.3f, 0.8f), new Vector2(500, 1000), 0.85f, true, new Vector2(-2, 2), new Vector2(-1, 1), new Vector2(0.15f, 0.25f), FireColor, Color.Black, -0.2f, 0.1f, 5, 1, false, new Vector2(0, 720), false, 0f, null, null, null, null, null, null, new Vector2(0.1f, 0.2f), true, true, null, null, null, true); EmitterList2.Add(ExplosionEmitter); Emitter ExplosionEmitter3 = new Emitter(ExplosionParticle2, new Vector2(explosion.Position.X, explosion.Position.Y + 16), new Vector2(85, 95), new Vector2(2, 4), new Vector2(400, 640), 0.35f, true, new Vector2(0, 0), new Vector2(0, 0), new Vector2(0.085f, 0.2f), FireColor, ExplosionColor3, -0.1f, 0.05f, 5, 1, false, new Vector2(0, 720), true, 0f, null, null, null, null, null, null, new Vector2(0.0025f, 0.0025f), true, true, 50); EmitterList2.Add(ExplosionEmitter3); //Emitter DebrisEmitter = new Emitter(SplodgeParticle, // new Vector2(explosion.Position.X, explosion.Position.Y), // new Vector2(70, 110), new Vector2(5, 7), new Vector2(480, 1760), 1f, true, new Vector2(0, 360), // new Vector2(1, 3), new Vector2(0.007f, 0.05f), Color.DarkSlateGray, Color.DarkSlateGray, // 0.2f, 0.2f, 5, 1, true, new Vector2(0, 720), null, 0f); //EmitterList.Add(DebrisEmitter); foreach (Player player in Players.Where(Player => Player != null)) { float dist = Vector2.Distance(new Vector2(player.DestinationRectangle.Center.X, player.DestinationRectangle.Center.Y), explosion.Position); if (dist < explosion.BlastRadius) { Gore1.Play(); player.CurrentHP = 0; for (int i = 0; i < 40; i++) { Vector2 myDir = new Vector2(player.DestinationRectangle.Center.X, player.DestinationRectangle.Center.Y) - explosion.Position; myDir.Normalize(); float angle = (float)Math.Atan2(myDir.Y, myDir.X) + MathHelper.ToRadians((float)RandomDouble(-130, 130)); Vector2 dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); dir.Normalize(); Gib newGib = new Gib(Splodge, new Vector2(player.DestinationRectangle.Center.X, player.DestinationRectangle.Center.Y), dir, 10, RandomTexture(DecalTexture1, DecalTexture2, DecalTexture3, DecalTexture4), Splodge, Color.Maroon); newGib.CurrentLevel = Level1; GibList.Add(newGib); } if (e.Explosion.Source == player) { player.Score--; } else { (e.Explosion.Source as Player).Score++; } player.MakeRumble(250, new Vector2(0.9f, 0.1f)); } } }
protected override void Update(GameTime gameTime) { switch (CurrentGameState) { #region GAME case GameState.Game: { if (Players.Any(Player => Player.Score >= 5)) { CurrentGameState = GameState.EndScreen; } TimeToBonus += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (TimeToBonus >= MaxTimeToBonus) { if (Random.NextDouble() > 0.5f) { if (AmmoList.Count <= Players.Count()) { //Add ammo pack //Get list of tiles which are not solid List <List <Tile> > emptyList; List <Tile> deadList = new List <Tile>(); emptyList = Level1.MainTileList; foreach (List <Tile> tileList in emptyList) { foreach (Tile tile in tileList) { if (Level1.CollisionTileList.Any(Collision => Collision.DestinationRectangle.Intersects(tile.DestinationRectangle))) { deadList.Add(tile); } } } Vector2 newPos = new Vector2(Random.Next(33, 1247), Random.Next(33, 703)); while (deadList.Any(Tile => Tile.DestinationRectangle.Contains(new Point((int)newPos.X, (int)newPos.Y)))) { newPos = new Vector2(Random.Next(33, 1247), Random.Next(33, 703)); } AmmoPack newPack = new AmmoPack(newPos, AmmoPackTexture); newPack.CurrentLevel = Level1; AmmoList.Add(newPack); } } else { //Add health pack } TimeToBonus = 0; MaxTimeToBonus = Random.Next(4000, 10000); } foreach (AmmoPack pack in AmmoList) { pack.Update(gameTime); } foreach (HealthPack pack in HealthList) { pack.Update(gameTime); } foreach (Gib gib in GibList) { gib.Update(gameTime); } GibList.RemoveAll(Gib => Gib.Active == false && Gib.EmitterList.All(Emitter => Emitter.Active == false && Emitter.ParticleList.Count == 0)); foreach (Emitter emitter in EmitterList) { emitter.Update(gameTime); } foreach (Emitter emitter in EmitterList2) { emitter.Update(gameTime); } EmitterList.RemoveAll(Emitter => Emitter.AddMore == false && Emitter.ParticleList.Count == 0); EmitterList2.RemoveAll(Emitter => Emitter.AddMore == false && Emitter.ParticleList.Count == 0); foreach (Player player in Players.Where(Player => Player != null)) { player.Update(gameTime); if (AmmoList.Any(Pack => Pack.CollisionRectangle.Intersects(player.DestinationRectangle)) && player.GrenadeAmmo < 3) { player.GrenadeAmmo = 3; } AmmoList.RemoveAll(Pack => Pack.CollisionRectangle.Intersects(player.DestinationRectangle)); } #region Update Rockets foreach (Rocket rocket in RocketList) { rocket.Update(gameTime); //Home to nearest player Player[] otherPlayers; otherPlayers = Players.Where(Player => Player != rocket.SourcePlayer).ToArray(); Player nearestPlayer = otherPlayers.OrderBy(Player => Vector2.Distance(Player.Position, rocket.StartPosition)).First(); Vector2 dirToPlayer = rocket.StartPosition - nearestPlayer.Position; dirToPlayer.Normalize(); rocket.Velocity.Y -= MathHelper.Clamp(dirToPlayer.Y * 0.5f, -0.1f, 0.1f); if (Level1.CollisionTileList.Any(Tile => Tile.BoundingBox.Intersects(rocket.DestinationRectangle))) { GunCollision1.Play(0.5f, 0, 0); rocket.Active = false; Emitter sparkEmitter = new Emitter(SparkTexture, rocket.Position, new Vector2(0, 360), new Vector2(2, 3), new Vector2(250, 450), 1f, true, new Vector2(0, 0), new Vector2(0, 0), Vector2.One, Color.Orange, Color.OrangeRed, 0.2f, 0.1f, 1, 2, false, new Vector2(0, 720), false, 0f, false, false, null, null, null, true); EmitterList.Add(sparkEmitter); } if (Players.Any(Player => Player != null && rocket.SourcePlayer != Player && rocket.Active == true && Player.DestinationRectangle.Intersects(rocket.DestinationRectangle))) { rocket.Active = false; Player hitPlayer = Players.First(Player => Player.DestinationRectangle.Intersects(rocket.DestinationRectangle) && Player != rocket.SourcePlayer); if (hitPlayer.CurrentHP > 0) { GunCollision1.Play(0.2f, 0, 0); for (int i = 0; i < 20; i++) { float angle = (float)Math.Atan2(rocket.Velocity.Y, rocket.Velocity.X) + MathHelper.ToRadians((float)RandomDouble(-100, 100)); Vector2 dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); dir.Normalize(); Gib newGib = new Gib(Splodge, new Vector2(hitPlayer.DestinationRectangle.Center.X, hitPlayer.DestinationRectangle.Center.Y), dir, 10, RandomTexture(DecalTexture1, DecalTexture2, DecalTexture3, DecalTexture4), Splodge, Color.Maroon); newGib.CurrentLevel = Level1; GibList.Add(newGib); } //Hit in the head if (rocket.DestinationRectangle.Bottom < hitPlayer.DestinationRectangle.Top + 13) { float angle2 = (float)Math.Atan2(rocket.Velocity.Y, rocket.Velocity.X) + MathHelper.ToRadians((float)RandomDouble(-100, 100)); Vector2 dir2 = new Vector2((float)Math.Cos(angle2), (float)Math.Sin(angle2)); dir2.Normalize(); Gib newGib2 = new Gib(Player1Head, new Vector2(hitPlayer.DestinationRectangle.Center.X, hitPlayer.DestinationRectangle.Center.Y), dir2, 10, RandomTexture(DecalTexture1, DecalTexture2, DecalTexture3, DecalTexture4), Splodge, Color.White); newGib2.CurrentLevel = Level1; GibList.Add(newGib2); } } hitPlayer.MakeRumble(250, new Vector2(0.1f, 0.9f)); hitPlayer.CurrentHP = 0; //Gore1.Play(); PlayRandomSound(Gore2); rocket.SourcePlayer.Score++; } } #endregion #region Update Bullets foreach (Bullet bullet in BulletList) { bullet.Update(gameTime); if (Level1.CollisionTileList.Any(Tile => Tile.BoundingBox.Intersects(bullet.CollisionRectangle))) { GunCollision1.Play(0.5f, 0, 0); bullet.Active = false; Emitter sparkEmitter = new Emitter(SparkTexture, bullet.Position, new Vector2(0, 360), new Vector2(2, 3), new Vector2(250, 450), 1f, true, new Vector2(0, 0), new Vector2(0, 0), Vector2.One, Color.Orange, Color.OrangeRed, 0.2f, 0.1f, 1, 2, false, new Vector2(0, 720), false, 0f, false, false, null, null, null, true); EmitterList.Add(sparkEmitter); } if (Players.Any(Player => Player != null && bullet.SourcePlayer != Player && bullet.Active == true && Player.DestinationRectangle.Intersects(bullet.DestinationRectangle))) { bullet.Active = false; Player hitPlayer = Players.First(Player => Player.DestinationRectangle.Intersects(bullet.DestinationRectangle) && Player != bullet.SourcePlayer); if (hitPlayer.CurrentHP > 0) { GunCollision1.Play(0.2f, 0, 0); for (int i = 0; i < 20; i++) { float angle = (float)Math.Atan2(bullet.Velocity.Y, bullet.Velocity.X) + MathHelper.ToRadians((float)RandomDouble(-100, 100)); Vector2 dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); dir.Normalize(); Gib newGib = new Gib(Splodge, new Vector2(hitPlayer.DestinationRectangle.Center.X, hitPlayer.DestinationRectangle.Center.Y), dir, 10, RandomTexture(DecalTexture1, DecalTexture2, DecalTexture3, DecalTexture4), Splodge, Color.Maroon); newGib.CurrentLevel = Level1; GibList.Add(newGib); } //Hit in the head if (bullet.DestinationRectangle.Bottom < hitPlayer.DestinationRectangle.Top + 13) { float angle2 = (float)Math.Atan2(bullet.Velocity.Y, bullet.Velocity.X) + MathHelper.ToRadians((float)RandomDouble(-100, 100)); Vector2 dir2 = new Vector2((float)Math.Cos(angle2), (float)Math.Sin(angle2)); dir2.Normalize(); Gib newGib2 = new Gib(hitPlayer.HeadTexture, new Vector2(hitPlayer.DestinationRectangle.Center.X, hitPlayer.DestinationRectangle.Center.Y), dir2, 10, RandomTexture(DecalTexture1, DecalTexture2, DecalTexture3, DecalTexture4), Splodge, Color.White); newGib2.CurrentLevel = Level1; GibList.Add(newGib2); } } hitPlayer.CurrentHP = 0; hitPlayer.MakeRumble(250, new Vector2(0.1f, 0.9f)); //Gore1.Play(); PlayRandomSound(Gore2); bullet.SourcePlayer.Score++; } } #endregion foreach (Grenade grenade in GrenadeList) { grenade.Update(gameTime); if (grenade.Active == false) { CreateExplosion(new Explosion() { Position = grenade.Position, BlastRadius = grenade.BlastRadius, Damage = 1, Source = grenade.Source }, grenade); } } RocketList.RemoveAll(Rocket => Rocket.Active == false); BulletList.RemoveAll(Bullet => Bullet.Active == false); GrenadeList.RemoveAll(Grenade => Grenade.Active == false); } break; #endregion #region PAUSED case GameState.Paused: { } break; #endregion #region MAIN MENU case GameState.MainMenu: { foreach (Player player in Players) { player.Update(gameTime); if (player.DPadDown == true) { MenuIndex++; } if (player.DPadUp == true) { MenuIndex--; } if (player.PressedStart) { Level1 = new Level(); Level1 = Load(MainMenu.Files[MenuIndex]); Level1.LoadContent(Content); CheckPlayers(); foreach (Player otherPlayers in Players) { otherPlayers.Active = true; otherPlayers.LoadContent(Content); } CurrentGameState = GameState.Game; } } } break; #endregion #region END SCREEN case GameState.EndScreen: { foreach (Player player in Players) { player.Active = false; player.Update(gameTime); if (player.DPadDown == true) { MenuIndex++; } if (player.DPadUp == true) { MenuIndex--; } if (player.PressedStart) { foreach (Player otherPlayers in Players) { otherPlayers.Score = 0; otherPlayers.GrenadeAmmo = 3; otherPlayers.Active = false; } GibList.Clear(); Level1 = null; EmitterList.Clear(); EmitterList2.Clear(); AmmoList.Clear(); HealthList.Clear(); CurrentGameState = GameState.MainMenu; } } } break; #endregion } base.Update(gameTime); }