private void GenerateAsteroidCluster(Vector3 position) { int initalRockAmount = FrameworkCore.r.Next(4, 12); int fieldSize = FrameworkCore.r.Next(24, 56); //shotgun the level with tons of asteroids. for (int i = 0; i < initalRockAmount; i++) { Vector3 rockPos = new Vector3( FrameworkCore.r.Next(-fieldSize, fieldSize), FrameworkCore.r.Next(-fieldSize, fieldSize), FrameworkCore.r.Next(-fieldSize, fieldSize)); rockPos = position + rockPos; asteroidInfo mesh = null; int randMesh = FrameworkCore.r.Next(2); if (randMesh == 0) { mesh = asteroidTypes.asteroid1; } else { mesh = asteroidTypes.asteroid2; } FrameworkCore.hulkManager.AddAsteroid(rockPos, mesh); } }
public void AddAsteroid(Vector3 position, asteroidInfo asteroidType) { Hulk item = new Hulk(); item.modelMesh = asteroidType.model; item.Position = position; item.Rotation = Quaternion.CreateFromYawPitchRoll( Helpers.randFloat(-3, 3), Helpers.randFloat(-3, 3), Helpers.randFloat(-3, 3)); item.permanent = true; item.BSphere = new BoundingSphere(item.Position, FrameworkCore.ModelArray[(int)item.modelMesh].Meshes[0].BoundingSphere.Radius); item.CollisionSpheres = new CollisionSphere[asteroidType.collisionSpheres.Length]; for (int i = 0; i < asteroidType.collisionSpheres.Length; i++) { item.CollisionSpheres[i] = new CollisionSphere(asteroidType.collisionSpheres[i].sphere, asteroidType.collisionSpheres[i].offset); } item.UpdateCollisionSpheres(); hulks.Add(item); }
/// <summary> /// public function that generates asteroid field. /// </summary> public void GenerateAsteroidField(int min, int max) { //asteroids. int clusterAmount = FrameworkCore.r.Next(min, max); for (int i = 0; i < clusterAmount; i++) { int clusterRange = 256; Vector3 clusterPos = new Vector3( FrameworkCore.r.Next(-clusterRange, clusterRange), FrameworkCore.r.Next(-clusterRange / 2, clusterRange / 2), FrameworkCore.r.Next(-clusterRange, clusterRange)); GenerateAsteroidCluster(clusterPos); } //junk chunks. int junkAmount = FrameworkCore.r.Next(4, 12); for (int i = 0; i < junkAmount; i++) { int clusterRange = 256; Vector3 clusterPos = new Vector3( FrameworkCore.r.Next(-clusterRange, clusterRange), FrameworkCore.r.Next(-clusterRange / 2, clusterRange / 2), FrameworkCore.r.Next(-clusterRange, clusterRange)); asteroidInfo mesh = null; int randMesh = FrameworkCore.r.Next(2); if (randMesh == 0) { mesh = asteroidTypes.junk1; } else { mesh = asteroidTypes.junk2; } FrameworkCore.hulkManager.AddAsteroid(clusterPos, mesh); } //Remove asteroids that too close to ships. List <Collideable> toDelete = new List <Collideable>(); foreach (Collideable hulk in FrameworkCore.hulkManager.Hulks) { if (!Helpers.IsHulk(hulk)) { continue; } foreach (Collideable ship in FrameworkCore.level.Ships) { if (!Helpers.IsSpaceship(ship)) { continue; } if (Vector3.Distance(hulk.Position, ship.Position) < 40) { toDelete.Add(hulk); } } } for (int x = toDelete.Count - 1; x >= 0; x--) { FrameworkCore.hulkManager.Hulks.Remove(toDelete[x]); } //remove asteroids that are too close to one another. for (int x = FrameworkCore.hulkManager.Hulks.Count - 1; x >= 0; x--) { if (!Helpers.IsHulk(FrameworkCore.hulkManager.Hulks[x])) { continue; } for (int i = FrameworkCore.hulkManager.Hulks.Count - 1; i >= 0; i--) { if (!Helpers.IsHulk(FrameworkCore.hulkManager.Hulks[i])) { continue; } if (x == i) { continue; } if (Vector3.Distance(FrameworkCore.hulkManager.Hulks[x].Position, FrameworkCore.hulkManager.Hulks[i].Position) < 25) { FrameworkCore.hulkManager.Hulks.RemoveAt(i); break; } } } for (int x = FrameworkCore.hulkManager.Hulks.Count - 1; x >= 0; x--) { if (!Helpers.IsHulk(FrameworkCore.hulkManager.Hulks[x])) { continue; } FrameworkCore.hulkManager.hulks[x].isStatic = true; FrameworkCore.playbackSystem.AddItem(FrameworkCore.hulkManager.Hulks[x], objectType.hulk, Color.White); } }