private Asteroid CreateNewAsteroid(AsteroidType asteroidType) { Asteroid asteroid; switch (asteroidType) { case AsteroidType.GOLDEN: asteroid = new Asteroid(this, -1); break; case AsteroidType.NORMAL: asteroid = new Asteroid(this, -1); break; case AsteroidType.SPAWNED: asteroid = new MinorAsteroid(this, -1); break; case AsteroidType.UNSTABLE: asteroid = new UnstableAsteroid(this, -1); break; default: asteroid = new Asteroid(this, -1); break; } asteroid.AsteroidType = asteroidType; return(asteroid); }
public static Asteroid CreateNewRandomAsteroid(ServerMgr mgr, bool headingRight) { Random randomGenerator = mgr.GetRandomGenerator(); Asteroid s; int chance = randomGenerator.Next(100); if (chance <= SharedDef.ASTEROID_GOLD_CHANCE) { s = new Asteroid(null, IdMgr.GetNewId(0)); s.AsteroidType = AsteroidType.GOLDEN; s.TextureId = randomGenerator.Next(1, 6); s.Radius = randomGenerator.Next(SharedDef.MIN_ASTEROID_RADIUS, SharedDef.MAX_ASTEROID_RADIUS); s.Gold = (s.Radius / 2) * SharedDef.GOLD_ASTEROID_BONUS_MULTIPLY; } else if (chance <= SharedDef.ASTEROID_UNSTABLE_CHANCE) { s = new UnstableAsteroid(null, IdMgr.GetNewId(0)); s.AsteroidType = AsteroidType.UNSTABLE; s.TextureId = randomGenerator.Next(1, 6); s.Radius = randomGenerator.Next(SharedDef.MIN_ASTEROID_RADIUS, SharedDef.MAX_ASTEROID_RADIUS); s.Gold = s.Radius / 2; } else { s = new Asteroid(null, IdMgr.GetNewId(0)); s.AsteroidType = AsteroidType.NORMAL; s.TextureId = randomGenerator.Next(1, 18); s.Radius = randomGenerator.Next(SharedDef.MIN_ASTEROID_RADIUS, SharedDef.MAX_ASTEROID_RADIUS); s.Gold = s.Radius / 2; } s.IsHeadingRight = headingRight; s.Direction = headingRight ? new Vector(1, 0) : new Vector(-1, 0); s.Position = GetRandomPositionInOrbitArea(randomGenerator, s.Radius); s.Color = Color.FromRgb((byte)randomGenerator.Next(40, 255), (byte)randomGenerator.Next(40, 255), (byte)randomGenerator.Next(40, 255)); s.Rotation = mgr.GetRandomGenerator().Next(360); SphereCollisionShape cs = new SphereCollisionShape(); cs.Center = s.Center; cs.Radius = s.Radius; s.CollisionShape = cs; CreateAsteroidControls(mgr, s); return(s); }
private void ReceivedMinorAsteroidSpawnMsg(NetIncomingMessage msg) { float speed = msg.ReadFloat(); int radius = msg.ReadInt32(); Vector direction = msg.ReadVector(); Vector center = msg.ReadVector(); int rot = msg.ReadInt32(); int textureId = msg.ReadInt32(); int destoryerId = msg.ReadInt32(); MinorAsteroid a1 = SceneObjectFactory.CreateSmallAsteroid(this, direction, center, rot, textureId, radius, speed, Math.PI / 12); a1.Id = msg.ReadInt64(); MinorAsteroid a2 = SceneObjectFactory.CreateSmallAsteroid(this, direction, center, rot, textureId, radius, speed, 0); a2.Id = msg.ReadInt64(); MinorAsteroid a3 = SceneObjectFactory.CreateSmallAsteroid(this, direction, center, rot, textureId, radius, speed, -Math.PI / 12); a3.Id = msg.ReadInt64(); long parentId = msg.ReadInt64(); UnstableAsteroid p = GetSceneObject(parentId) as UnstableAsteroid; if (p == null) { p = new UnstableAsteroid(this, parentId); } p.Destroyer = destoryerId; a1.Parent = p; a2.Parent = p; a3.Parent = p; DelayedAttachToScene(a1); DelayedAttachToScene(a2); DelayedAttachToScene(a3); SyncReceivedObject(a1, msg); SyncReceivedObject(a2, msg); SyncReceivedObject(a3, msg); }