public void CheckForCollision(Hero Player, Zombie Zombie, int NumberOfZombies, int NumberOfZombiesKilled, Vector2 scrollOffset) { collision = false; #region Bullets to Zombies Matrix bulletTransform = Matrix.CreateTranslation(new Vector3(-center, 0.0f)) * Matrix.CreateRotationZ(rotation) * Matrix.CreateTranslation(new Vector3(position + scrollOffset, 0.0f)); Rectangle bulletRectangle = CalculateBoundingRectangle( new Rectangle(0, 0, sprite.Width, sprite.Height), bulletTransform); Matrix zombieTransform = Matrix.CreateTranslation(new Vector3(-Zombie.center, 0.0f)) * Matrix.CreateRotationZ(Zombie.rotation) * Matrix.CreateTranslation(new Vector3(Zombie.position + scrollOffset, 0.0f)); Rectangle zombieRectangle = CalculateBoundingRectangle( new Rectangle(0, 0, Zombie.sprite.Width, Zombie.sprite.Height), zombieTransform); if (bulletRectangle.Intersects(zombieRectangle)) { if (IntersectPixels(bulletTransform, sprite.Width, sprite.Height, textureData, zombieTransform, Zombie.sprite.Width, Zombie.sprite.Height, Zombie.textureData)) { Zombie.health -= 100; collision = true; if (Zombie.health <= 0) { NumberOfZombiesKilled++; NumberOfZombies--; Zombie.alive = false; Zombie.health = Zombie.fullHealth; } alive = false; if (Player.playerCharacter == Character.Sir_Edward) { Player.score += 10; } } } #endregion numberOfZombies = NumberOfZombies; numberOfZombiesKilled = NumberOfZombiesKilled; }
public void Update(M4Bullet[] M4Bullets, Hero Player, int NumberOfPlayersLeft, Zombie[] Zombies, int NumberOfZombies, int NumberOfZombiesKilled, Vector2 scrollOffset) { numberOfZombies = NumberOfZombies; numberOfZombiesKilled = NumberOfZombiesKilled; foreach (M4Bullet m4Bullet in M4Bullets) { if (m4Bullet.alive) { //this actually moves the bullet across the screen m4Bullet.position += m4Bullet.velocity; if (Vector2.Distance(Player.position + scrollOffset, m4Bullet.position + scrollOffset) > 1200.0f) { m4Bullet.alive = false; continue; } else { foreach (Zombie zombie in Zombies) { if (zombie.alive) { m4Bullet.CheckForCollision(Player, zombie, NumberOfZombies, NumberOfZombiesKilled, scrollOffset); if (m4Bullet.collision) { numberOfZombies = m4Bullet.numberOfZombies; numberOfZombiesKilled = m4Bullet.numberOfZombiesKilled; break; } } } } } } }
public void Update(ShotgunBullet[] ShotgunBullets, Hero Player, int NumberOfPlayersLeft, Zombie[] Zombies, int NumberOfZombies, int NumberOfZombiesKilled, Vector2 scrollOffset) { numberOfZombies = NumberOfZombies; numberOfZombiesKilled = NumberOfZombiesKilled; foreach(ShotgunBullet shotgunBullet in ShotgunBullets) { if (shotgunBullet.alive) { //this actually moves the bullet across the screen shotgunBullet.position += shotgunBullet.velocity; if (Vector2.Distance(Player.position + scrollOffset, shotgunBullet.position + scrollOffset) > Player.sprite.Width * 3) { shotgunBullet.alive = false; continue; } else { foreach (Zombie zombie in Zombies) { if (zombie.alive) { shotgunBullet.CheckForCollision(Player, zombie, NumberOfZombies, NumberOfZombiesKilled, scrollOffset); if (shotgunBullet.collision) { numberOfZombies = shotgunBullet.numberOfZombies; numberOfZombiesKilled = shotgunBullet.numberOfZombiesKilled; break; } } } } } } }
public override void LoadContent() { Viewport viewportRect = ScreenManager.GraphicsDevice.Viewport; spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice); safeBounds = new Rectangle( (int)(viewportRect.Width * SafeAreaPortion), (int)(viewportRect.Height * SafeAreaPortion), (int)(viewportRect.Width * (1 - 2 * SafeAreaPortion)), (int)(viewportRect.Height * (1 - 2 * SafeAreaPortion))); #region load zombie stuff zombies = new Zombie[maxzombies]; foreach (Zombie zombie in zombies) { for (int i = 0; i <= 10; i++) { zombies[i] = new Zombie(content.Load<Texture2D>("Sprites\\Zombies\\Images\\zombie1")); } for (int i = 11; i <= 20; i++) { zombies[i] = new Zombie(content.Load<Texture2D>("Sprites\\Zombies\\Images\\zombie2")); } for (int i = 21; i <= 30; i++) { zombies[i] = new Zombie(content.Load<Texture2D>("Sprites\\Zombies\\Images\\zombie3")); } for (int i = 31; i <= 40; i++) { zombies[i] = new Zombie(content.Load<Texture2D>("Sprites\\Zombies\\Images\\zombie4")); } } #endregion switch (numberOfPlayers) { case 1: #region TextureData if (player1 == Player.Tyrone) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player1 == Player.Sir_Edward) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player1 == Player.Wilhelm) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } if (player1 == Player.Bob) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Images\\Bob")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Halo\\Bob-Halo")); } player1TextureData = new Color[players[0].sprite.Width * players[0].sprite.Height]; players[0].sprite.GetData(player1TextureData); #endregion #region Position players[0].position.X = (safeBounds.Width - players[0].sprite.Width) / 2; players[0].position.Y = safeBounds.Height - players[0].sprite.Height; #endregion #region Health if (handicap1 == Handicap.Easy) { players[0].health = 20; } else if (handicap1 == Handicap.Medium) { players[0].health = 15; } else if (handicap1 == Handicap.Hard) { players[0].health = 10; } else if (handicap1 == Handicap.VeryHard) { players[0].health = 5; } fullPlayer1Health = players[0].health; #endregion break; case 2: #region TextureData if (player1 == Player.Tyrone) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player1 == Player.Sir_Edward) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player1 == Player.Wilhelm) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } if (player1 == Player.Bob) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Images\\Bob")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Halo\\Bob-Halo")); } player1TextureData = new Color[players[0].sprite.Width * players[0].sprite.Height]; players[0].sprite.GetData(player1TextureData); if (player2 == Player.Tyrone) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player2 == Player.Sir_Edward) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player2 == Player.Wilhelm) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } if (player2 == Player.Bob) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Images\\Bob")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Halo\\Bob-Halo")); } player2TextureData = new Color[players[1].sprite.Width * players[1].sprite.Height]; players[1].sprite.GetData(player2TextureData); #endregion #region Positions players[0].position.X = (safeBounds.Width - players[0].sprite.Width) / 2; players[0].position.Y = safeBounds.Height - players[0].sprite.Height; players[1].position.X = (safeBounds.Width - players[1].sprite.Width) / 2 + 150; players[1].position.Y = safeBounds.Height - players[1].sprite.Height; #endregion #region Health if (handicap1 == Handicap.Easy) { players[0].health = 20; } else if (handicap1 == Handicap.Medium) { players[0].health = 15; } else if (handicap1 == Handicap.Hard) { players[0].health = 10; } else if (handicap1 == Handicap.VeryHard) { players[0].health = 5; } if (handicap2 == Handicap.Easy) { players[1].health = 20; } else if (handicap2 == Handicap.Medium) { players[1].health = 15; } else if (handicap2 == Handicap.Hard) { players[1].health = 10; } else if (handicap2 == Handicap.VeryHard) { players[1].health = 5; } fullPlayer1Health = players[0].health; fullPlayer2Health = players[1].health; #endregion break; case 3: #region TextureData if (player1 == Player.Tyrone) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player1 == Player.Sir_Edward) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player1 == Player.Wilhelm) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } if (player1 == Player.Bob) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Images\\Bob")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Halo\\Bob-Halo")); } player1TextureData = new Color[players[0].sprite.Width * players[0].sprite.Height]; players[0].sprite.GetData(player1TextureData); if (player2 == Player.Tyrone) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player2 == Player.Sir_Edward) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player2 == Player.Wilhelm) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } if (player2 == Player.Bob) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Images\\Bob")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Halo\\Bob-Halo")); } player2TextureData = new Color[players[1].sprite.Width * players[1].sprite.Height]; players[1].sprite.GetData(player2TextureData); if (player3 == Player.Tyrone) { players[2] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[2] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player3 == Player.Sir_Edward) { players[2] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[2] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player3 == Player.Wilhelm) { players[2] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[2] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } if (player3 == Player.Bob) { players[2] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Images\\Bob")); playerHalos[2] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Bob\\Halo\\Bob-Halo")); } player3TextureData = new Color[players[2].sprite.Width * players[2].sprite.Height]; players[2].sprite.GetData(player3TextureData); #endregion #region Positions players[0].position.X = (safeBounds.Width - players[0].sprite.Width) / 2; players[0].position.Y = safeBounds.Height - players[0].sprite.Height; players[1].position.X = (safeBounds.Width - players[1].sprite.Width) / 2 + 150; players[1].position.Y = safeBounds.Height - players[1].sprite.Height; players[2].position.X = (safeBounds.Width - players[2].sprite.Width) / 2 + 300; players[2].position.Y = safeBounds.Height - players[2].sprite.Height; #endregion #region Health if (handicap1 == Handicap.Easy) { players[0].health = 20; } else if (handicap1 == Handicap.Medium) { players[0].health = 15; } else if (handicap1 == Handicap.Hard) { players[0].health = 10; } else if (handicap1 == Handicap.VeryHard) { players[0].health = 5; } if (handicap2 == Handicap.Easy) { players[1].health = 20; } else if (handicap2 == Handicap.Medium) { players[1].health = 15; } else if (handicap2 == Handicap.Hard) { players[1].health = 10; } else if (handicap2 == Handicap.VeryHard) { players[1].health = 5; } if (handicap3 == Handicap.Easy) { players[2].health = 20; } else if (handicap3 == Handicap.Medium) { players[2].health = 15; } else if (handicap3 == Handicap.Hard) { players[2].health = 10; } else if (handicap3 == Handicap.VeryHard) { players[2].health = 5; } fullPlayer1Health = players[0].health; fullPlayer2Health = players[1].health; fullPlayer3Health = players[2].health; #endregion break; case 4: #region TextureData if (player1 == Player.Tyrone) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player1 == Player.Sir_Edward) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player1 == Player.Wilhelm) { players[0] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[0] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } player1TextureData = new Color[players[0].sprite.Width * players[0].sprite.Height]; players[0].sprite.GetData(player1TextureData); if (player2 == Player.Tyrone) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player2 == Player.Sir_Edward) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player2 == Player.Wilhelm) { players[1] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[1] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } player2TextureData = new Color[players[1].sprite.Width * players[1].sprite.Height]; players[1].sprite.GetData(player2TextureData); if (player3 == Player.Tyrone) { players[2] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[2] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player3 == Player.Sir_Edward) { players[2] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[2] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player3 == Player.Wilhelm) { players[2] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[2] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } player3TextureData = new Color[players[2].sprite.Width * players[2].sprite.Height]; players[2].sprite.GetData(player3TextureData); if (player4 == Player.Tyrone) { players[3] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Images\\Tyrone")); playerHalos[3] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Tyrone\\Halo\\Tyrone-Halo")); } if (player4 == Player.Sir_Edward) { players[3] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[3] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (player4 == Player.Wilhelm) { players[3] = new Players(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Images\\Wilhelm")); playerHalos[3] = new PlayerHalo(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Wilhelm\\Halo\\Wilhelm-Halo")); } player4TextureData = new Color[players[3].sprite.Width * players[3].sprite.Height]; players[3].sprite.GetData(player4TextureData); #endregion #region Positions players[0].position.X = (safeBounds.Width - players[0].sprite.Width) / 2; players[0].position.Y = safeBounds.Height - players[0].sprite.Height; players[1].position.X = (safeBounds.Width - players[1].sprite.Width) / 2 + 150; players[1].position.Y = safeBounds.Height - players[1].sprite.Height; players[2].position.X = (safeBounds.Width - players[2].sprite.Width) / 2 + 300; players[2].position.Y = safeBounds.Height - players[2].sprite.Height; players[3].position.X = (safeBounds.Width - players[3].sprite.Width) / 2 + 450; players[3].position.Y = safeBounds.Height - players[3].sprite.Height; #endregion #region Health if (handicap1 == Handicap.Easy) { players[0].health = 20; } else if (handicap1 == Handicap.Medium) { players[0].health = 15; } else if (handicap1 == Handicap.Hard) { players[0].health = 10; } else if (handicap1 == Handicap.VeryHard) { players[0].health = 5; } if (handicap2 == Handicap.Easy) { players[1].health = 20; } else if (handicap2 == Handicap.Medium) { players[1].health = 15; } else if (handicap2 == Handicap.Hard) { players[1].health = 10; } else if (handicap2 == Handicap.VeryHard) { players[1].health = 5; } if (handicap3 == Handicap.Easy) { players[2].health = 20; } else if (handicap3 == Handicap.Medium) { players[2].health = 15; } else if (handicap3 == Handicap.Hard) { players[2].health = 10; } else if (handicap3 == Handicap.VeryHard) { players[2].health = 5; } if (handicap4 == Handicap.Easy) { players[3].health = 20; } else if (handicap4 == Handicap.Medium) { players[3].health = 15; } else if (handicap4 == Handicap.Hard) { players[3].health = 10; } else if (handicap4 == Handicap.VeryHard) { players[3].health = 5; } fullPlayer1Health = players[0].health; fullPlayer2Health = players[1].health; fullPlayer3Health = players[2].health; fullPlayer4Health = players[3].health; #endregion break; } }
public override void LoadContent() { if (ScreenManager.Game.Content == null) ScreenManager.Game.Content = new ContentManager(ScreenManager.Game.Services, "Content"); redRectangle = ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Misc\\redRectangle"); players = new Hero[NumberOfPlayers]; playerHalos = new OtherObject[NumberOfPlayers]; shotgunBullets = new ShotgunBullet[numberOfshotgunBullets]; miniUziBullets = new MiniUziBullet[numberOfminiUziBullets]; m4Bullets = new M4Bullet[numberOfm4Bullets]; g36cBullets = new G36CBullet[numberOfg36cBullets]; zombies = new Zombie[MaxZombies]; for (int i = 0; i < NumberOfPlayers; i++) { //Load the texture data from the Sprite folder depending on who the player is #region Texture Data if (PlayerCharacters[i] == Character.Sayid) { players[i] = new Hero(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Sayid\\Images\\Sayid")); playerHalos[i] = new OtherObject(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Sayid\\Halo\\Sayid-Halo")); } if (PlayerCharacters[i] == Character.Sir_Edward) { players[i] = new Hero(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Sir_Edward\\Images\\Sir_Edward")); playerHalos[i] = new OtherObject(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Sir_Edward\\Halo\\Sir_Edward-Halo")); } if (PlayerCharacters[i] == Character.Wilhelm) { players[i] = new Hero(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Wilhelm\\Images\\Wilhelm")); playerHalos[i] = new OtherObject(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Wilhelm\\Halo\\Wilhelm-Halo")); } if (PlayerCharacters[i] == Character.Juan) { players[i] = new Hero(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Juan\\Images\\Juan")); playerHalos[i] = new OtherObject(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Players\\Juan\\Halo\\Juan-Halo")); } #endregion //give a position for the player to start out at #region Position //bottom left first players[i].position = new Vector2(players[i].sprite.Width * xSignedPosition + (totalFieldWidth / 2), players[i].sprite.Height * ySignedPosition + (totalFieldHeight / 2)); if (xSignedPosition == -1 && ySignedPosition == -1) { //then bottom right xSignedPosition *= -1; } else if (xSignedPosition == 1 && ySignedPosition == -1) { //then top right ySignedPosition *= -1; } else if (xSignedPosition == 1 && ySignedPosition == 1) { //then top left xSignedPosition *= -1; } #endregion //give the correct health for the player depending on the handicap #region Health if (players[i].playerHandicap == Handicap.Easy) { players[i].health = 20; } else if (players[i].playerHandicap == Handicap.Medium) { players[i].health = 15; } else if (players[i].playerHandicap == Handicap.Hard) { players[i].health = 10; } else if (players[i].playerHandicap == Handicap.VeryHard) { players[i].health = 5; } //reference giving origina2 health for sca2e factoring 2ater players[i].fullHealth = players[i].health; #endregion players[i].playerCharacter = PlayerCharacters[i]; players[i].playerHandicap = PlayerHandicaps[i]; players[i].triggerSensitivity = sen[i]; LoadBullets(players[i].playerCharacter); players[i].LoadUpBulletManager(); } #region Zombies for (int i = 0; i < MaxZombies; i++) { zombies[i] = new Zombie(ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Zombies\\Images\\zombie1(1)")); } #endregion healthBar = ScreenManager.Game.Content.Load<Texture2D>("Sprites\\Misc\\HealthBar"); gameBackgroundTexture = ScreenManager.Game.Content.Load<Texture2D>("Background\\GrassBackground"); Active = true; //sleep for a little so the game can load Thread.Sleep(1000); //resets so xbox doesnt try to catch up with lost time in thread ScreenManager.Game.ResetElapsedTime(); }
public void CheckForCollision(Hero Player, int NumberOfPlayersLeft, int NumberOfZombies, Vector2 scrollOffset) { numberOfZombies = NumberOfZombies; numberOfPlayersLeft = NumberOfPlayersLeft; #region Transformations and Rectangles Matrix zombieTransform = Matrix.CreateTranslation(new Vector3(-center, 0.0f)) * Matrix.CreateRotationZ(rotation) * Matrix.CreateTranslation(new Vector3(position + scrollOffset, 0.0f)); Rectangle zombieRectangle = CalculateBoundingRectangle( new Rectangle(0, 0, sprite.Width, sprite.Height), zombieTransform); Matrix rectangleTransform = Matrix.CreateTranslation(new Vector3(-Player.center, 0.0f)) * Matrix.CreateRotationZ(Player.rotation) * Matrix.CreateTranslation(new Vector3(Player.position + scrollOffset, 0.0f)); Rectangle gunRect = CalculateBoundingRectangle( new Rectangle((int)3.5, (int)47.4, 2, 2), rectangleTransform); Rectangle rightForearmRect = CalculateBoundingRectangle( new Rectangle((int)28.9, (int)34.1, 2, 2), rectangleTransform); Rectangle rightElbowRect = CalculateBoundingRectangle( new Rectangle(46, (int)21.5, 2, 2), rectangleTransform); Rectangle rightShoulderRect = CalculateBoundingRectangle( new Rectangle((int)82.2, (int)28.2, 2, 2), rectangleTransform); Rectangle headRect = CalculateBoundingRectangle( new Rectangle((int)94.7, (int)47.4, 2, 2), rectangleTransform); Rectangle leftShoulderRect = CalculateBoundingRectangle( new Rectangle(84, (int)69.4, 2, 2), rectangleTransform); Rectangle leftElbowRect = CalculateBoundingRectangle( new Rectangle((int)45.6, (int)74.3, 2, 2), rectangleTransform); Rectangle leftForearmRect = CalculateBoundingRectangle( new Rectangle((int)29.3, (int)66.6, 2, 2), rectangleTransform); #endregion if (zombieRectangle.Intersects(gunRect) || zombieRectangle.Intersects(rightForearmRect) || zombieRectangle.Intersects(rightElbowRect) || zombieRectangle.Intersects(rightShoulderRect) || zombieRectangle.Intersects(headRect) || zombieRectangle.Intersects(leftShoulderRect) || zombieRectangle.Intersects(leftElbowRect) || zombieRectangle.Intersects(leftForearmRect)) { alive = false; NumberOfZombies--; Player.health--; if (Player.health <= 0) { Player.alive = false; NumberOfPlayersLeft--; } } numberOfZombies = NumberOfZombies; numberOfPlayersLeft = NumberOfPlayersLeft; zombie = this; player = Player; }