/// <summary> /// Creates a specific ammount of /// **Asteroids** /// **Gems** /// in the a level depending which level it is /// </summary> /// <param name="numOfAsteroids"></param> public void LoadLevel(int newNumOfAsteroids, int nexEnemy) { player.Initialize(); player.LoadContent(this.Content, "hi"); enemy = new Enemy[nexEnemy]; for (int i = 0; i < nexEnemy; i++) { enemy[i] = new Enemy(); enemy[i].Initialize(); enemy[i].LoadContent(this.Content); } // enemy.Initialize(); numOfAsteroids = newNumOfAsteroids; int asteroidsInLevel = numOfAsteroids * 2 * 3; gem = new Gem[asteroidsInLevel]; for (int i = 0; i < asteroidsInLevel; i++) { gem[i] = new Gem(); gem[i].LoadContent(this.Content, "GreenGem"); } asteroids = new Asteroids[asteroidsInLevel]; for (int i = 0; i < asteroidsInLevel; i++) { asteroids[i] = new Asteroids(); } //make passed value of asteroid in the level spawn for (int i = 0; i < numOfAsteroids; i++) { asteroids[i].MakeAsteroid(Asteroids.AsteroidType.Big, new Vector2(), this.Content); } //gems }
/// <summary> /// giving the gem values /// to be alive and the position to spawn at /// after an asteroid has been destroyed /// </summary> /// <param name="gemType"></param> /// <param name="asteroidPos"></param> public void MakeGem(Asteroids asteroid, int randomPercentage, TypeOfGem gemType, int chance) { switch (gemType) { case TypeOfGem.None: break; case TypeOfGem.Green: worthMoney = 30; texture = content.Load <Texture2D>("GreenGem"); break; case TypeOfGem.Red: worthMoney = 60; texture = content.Load <Texture2D>("RedGem"); break; case TypeOfGem.Orange: worthMoney = 100; texture = content.Load <Texture2D>("OrangeGem"); break; case TypeOfGem.Silver: worthMoney = 200; texture = content.Load <Texture2D>("SilverGem"); break; case TypeOfGem.Purple: worthMoney = 500; texture = content.Load <Texture2D>("PurpleGem"); break; default: break; } orignin.X = texture.Width / 2; orignin.Y = texture.Height / 2; if (randomPercentage < chance) { alive = true; position = asteroid.Position; } // orignin = asteroid.Origin; }
public void AsteroidCollision(Asteroids asteroid, Texture2D shipTexture, ref float elap) { if (alive && !shield && asteroid.Alive) { int width = shipTexture.Width / 5; int height = shipTexture.Height; Vector2 asteroidPos = asteroid.Position; if (position.X + width < asteroidPos.X || position.Y + height < asteroidPos.Y || position.X > asteroidPos.X + asteroid.Texture.Width || position.Y > asteroidPos.Y + asteroid.Texture.Height) { } else { alive = false; elap = 0; } } }
/// <summary> /// Comutes the collision between an asteroid and bullet /// </summary> /// <param name="asteroid"></param> /// <param name="gem"></param> /// <param name="chanceForGem"></param> public void BulletAsteroidCollision(Asteroids asteroid, Asteroids nextAsteroids, Gem gem, int chanceForGem, Gem.TypeOfGem type, ref int numOfAsteroids, ContentManager content) { int chance = Asteroids.rnd.Next(1, 101); switch (asteroid.currentAsteroid) { case Asteroids.AsteroidType.Small: #region SmallCollision if (asteroid.Alive && alive) { int width = texture.Width; int height = texture.Height; Vector2 asteroidPos = asteroid.Position; if (position.X + width < asteroidPos.X || position.Y + height < asteroidPos.Y || position.X > asteroidPos.X + asteroid.Texture.Width || position.Y > asteroidPos.Y + asteroid.Texture.Height) { } else { collide.Play(); alive = false; asteroid.Alive = false; gem.MakeGem(asteroid, Asteroids.rnd.Next(1, 101), type, chanceForGem); } } #endregion break; case Asteroids.AsteroidType.Medium: #region MediumCollision if (asteroid.Alive && alive) { int width = texture.Width; int height = texture.Height; Vector2 asteroidPos = asteroid.Position; if (position.X + width < asteroidPos.X || position.Y + height < asteroidPos.Y || position.X > asteroidPos.X + asteroid.Texture.Width - 25 || position.Y > asteroidPos.Y + asteroid.Texture.Height - 23) { } else { collide.Play(); alive = false; nextAsteroids.MakeAsteroid(Asteroids.AsteroidType.Small, asteroid.Position, content); asteroid.currentAsteroid = Asteroids.AsteroidType.Small; numOfAsteroids++; } } #endregion break; case Asteroids.AsteroidType.Big: #region BigCollision if (asteroid.Alive && alive) { int width = 24; int height = 10; Vector2 asteroidPos = asteroid.Position; if (position.X + width < asteroidPos.X || position.Y + height < asteroidPos.Y || position.X > asteroidPos.X + asteroid.Texture.Width || position.Y > asteroidPos.Y + asteroid.Texture.Height) { } else { collide.Play(); alive = false; nextAsteroids.MakeAsteroid(Asteroids.AsteroidType.Medium, asteroid.Position, content); asteroid.currentAsteroid = Asteroids.AsteroidType.Medium; numOfAsteroids++; } } #endregion break; default: break; } }