protected override void CreateAsteroids() { int asteroidAmount = ((Game.Level + 1)/ 2); asteroids.Clear(); for (int i = 0; i < asteroidAmount; i++) { Asteroid newAsteroid = new Asteroid(Game, 150); asteroids.Add(newAsteroid); } }
protected override void SplitAsteroid(Asteroid a) { if (a.Radius >= 100) { for (int i = 0; i < 20; i++) { Asteroid newAsteroid = new Asteroid(Game, Game.Random.Next(5, 50)); newAsteroid.Position = a.Position; asteroids.Add(newAsteroid); } } else { base.SplitAsteroid(a); } }
/// <summary> /// An asteroid has been destroyed, so split it in two /// </summary> /// <param name="a">Asteroid to split</param> protected virtual void SplitAsteroid(Asteroid a) { float newRadius = a.Radius / 2; if (newRadius > 4) { for (int i = 0; i < 2; i++) { Asteroid newAsteroid = new Asteroid(Game, newRadius); newAsteroid.Position = a.Position; asteroids.Add(newAsteroid); } } asteroids.Remove(a); }
/// <summary> /// Create a new batch of asteroids /// </summary> protected virtual void CreateAsteroids() { asteroids.Clear(); // Generate an amount of asteroids based on level for (int i = 0; i < 4 + Game.Level; i++) { int radius = Game.Random.Next(5, 50); Asteroid newAsteroid = new Asteroid(Game, radius); asteroids.Add(newAsteroid); } }
public Asteroid[] Destroy() { if (Size == AsteroidSize.Small) { return(new Asteroid[0]); } else if (Size == AsteroidSize.Normal) { // Generate two small asteroids float angle = (float)(10 * rand.Next(-9, 9)); Vector3 firstVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(angle))); firstVector.Normalize(); Vector3 secondVector = -firstVector; Asteroid a1 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(firstVector.X, firstVector.Y), LinSpeed, Scale * 0.5f); Asteroid a2 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(secondVector.X, secondVector.Y), LinSpeed, Scale * 0.5f); return(new Asteroid[] { a1, a2 }); } else if (Size == AsteroidSize.Large) { float angle = (float)(10 * rand.Next(-9, 9)); Vector3 firstVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(angle))); firstVector.Normalize(); Vector3 secondVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(-angle))); secondVector.Normalize(); Vector3 thirdVector = -firstVector; Vector3 fourthVector = -secondVector; Asteroid a1 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(firstVector.X, firstVector.Y), LinSpeed, Scale * 0.42f); Asteroid a2 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(secondVector.X, secondVector.Y), LinSpeed, Scale * 0.42f); Asteroid a3 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(thirdVector.X, thirdVector.Y), LinSpeed, Scale * 0.42f); Asteroid a4 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(fourthVector.X, fourthVector.Y), LinSpeed, Scale * 0.42f); return(new Asteroid[] { a1, a2, a3, a4 }); } else { float angle = (float)(10 * rand.Next(-9, 9)); Vector3 firstVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(angle))); firstVector.Normalize(); Vector3 secondVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(-angle))); secondVector.Normalize(); Vector3 thirdVector = -firstVector; Vector3 fourthVector = -secondVector; Asteroid a1 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(firstVector.X, firstVector.Y), LinSpeed, Scale * 0.71f); Asteroid a2 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(secondVector.X, secondVector.Y), LinSpeed, Scale * 0.71f); Asteroid a3 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(thirdVector.X, thirdVector.Y), LinSpeed, Scale * 0.71f); Asteroid a4 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(fourthVector.X, fourthVector.Y), LinSpeed, Scale * 0.71f); return(new Asteroid[] { a1, a2, a3, a4 }); } }
public Asteroid[] Destroy() { if (Size == AsteroidSize.Small) return new Asteroid[0]; else if (Size == AsteroidSize.Normal) { // Generate two small asteroids float angle = (float)(10 * rand.Next(-9, 9)); Vector3 firstVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(angle))); firstVector.Normalize(); Vector3 secondVector = -firstVector; Asteroid a1 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(firstVector.X, firstVector.Y), LinSpeed, Scale * 0.5f); Asteroid a2 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(secondVector.X, secondVector.Y), LinSpeed, Scale * 0.5f); return new Asteroid[] { a1, a2 }; } else if (Size == AsteroidSize.Large) { float angle = (float)(10 * rand.Next(-9, 9)); Vector3 firstVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(angle))); firstVector.Normalize(); Vector3 secondVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(-angle))); secondVector.Normalize(); Vector3 thirdVector = -firstVector; Vector3 fourthVector = -secondVector; Asteroid a1 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(firstVector.X, firstVector.Y), LinSpeed, Scale * 0.42f); Asteroid a2 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(secondVector.X, secondVector.Y), LinSpeed, Scale * 0.42f); Asteroid a3 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(thirdVector.X, thirdVector.Y), LinSpeed, Scale * 0.42f); Asteroid a4 = new Asteroid(AsteroidSize.Small, (Shape)Body.Clone(), Position, Rotation, new Vector2(fourthVector.X, fourthVector.Y), LinSpeed, Scale * 0.42f); return new Asteroid[] { a1, a2, a3, a4 }; } else { float angle = (float)(10 * rand.Next(-9, 9)); Vector3 firstVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(angle))); firstVector.Normalize(); Vector3 secondVector = Vector3.Transform( new Vector3(Direction, 0f), Matrix.CreateRotationZ(MathHelper.ToRadians(-angle))); secondVector.Normalize(); Vector3 thirdVector = -firstVector; Vector3 fourthVector = -secondVector; Asteroid a1 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(firstVector.X, firstVector.Y), LinSpeed, Scale * 0.71f); Asteroid a2 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(secondVector.X, secondVector.Y), LinSpeed, Scale * 0.71f); Asteroid a3 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(thirdVector.X, thirdVector.Y), LinSpeed, Scale * 0.71f); Asteroid a4 = new Asteroid(AsteroidSize.Normal, (Shape)Body.Clone(), Position, Rotation, new Vector2(fourthVector.X, fourthVector.Y), LinSpeed, Scale * 0.71f); return new Asteroid[] { a1, a2, a3, a4 }; } }
/// <summary> /// Generates an asteroid with a convex body /// </summary> /// <param name="rand">Random number generator</param> /// <param name="pos">Initial position of the asteroid</param> /// <param name="rot">Initial rotation of the asteroid (in radians)</param> /// <param name="linSpeed">Speed of the asteroid</param> /// <param name="dir">Initial direction of the asteroid</param> /// <returns>An asteroid with a convex body</returns> public static Asteroid GetConvexAsteroid(int index, Vector2 pos, float rot, float linSpeed, Vector2 dir, AsteroidSize size) { Shape s; float scale; float effectiveWidth; float effectiveHeight; // Use the index to find a random asteroid shape // The scale, effectiveWidth, and effectiveHeight are based on an asteroid of normal size switch (index) { case 0: s = convexAsteroids[0]; effectiveHeight = 40f; effectiveWidth = 45f; scale = 150f; break; case 1: s = convexAsteroids[1]; effectiveHeight = 60f; effectiveWidth = 60f; scale = 80f; break; case 2: s = convexAsteroids[2]; effectiveHeight = 40f; effectiveWidth = 40f; scale = 80f; break; case 3: s = convexAsteroids[3]; effectiveHeight = 40f; effectiveWidth = 40f; scale = 75f; break; case 4: s = convexAsteroids[4]; effectiveHeight = 40f; effectiveWidth = 40f; scale = 75f; break; default: throw new ArgumentOutOfRangeException(); } // If the asteroid size isn't normal, we adjust the size variables switch (size) { case AsteroidSize.Small: scale *= 0.5f; effectiveHeight *= 0.6f; effectiveWidth *= 0.6f; break; case AsteroidSize.Large: scale *= 1.2f; effectiveHeight *= 1.1f; effectiveWidth *= 1.1f; break; case AsteroidSize.Huge: scale *= 1.5f; effectiveHeight *= 1.4f; effectiveWidth *= 1.4f; break; default: break; } // Return the asteroid Asteroid a = new Asteroid(size, s, pos, rot, dir, linSpeed, scale); a.EffectiveHeight = effectiveHeight; a.EffectiveWidth = effectiveWidth; return(a); }