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 MinorAsteroid CreateSmallAsteroid(SceneMgr mgr, Vector direction, Vector center, int rot, int textureId, int radius, float speed, double rotation) { MinorAsteroid asteroid = new MinorAsteroid(mgr, IdMgr.GetNewId(mgr.GetCurrentPlayer().GetId())); asteroid.AsteroidType = AsteroidType.SPAWNED; asteroid.Rotation = rot; asteroid.Direction = direction.Rotate(rotation); asteroid.Radius = radius; asteroid.Position = center; asteroid.Gold = radius * 2; asteroid.TextureId = textureId; asteroid.Enabled = true; asteroid.SetGeometry(SceneGeometryFactory.CreateAsteroidImage(asteroid)); SphereCollisionShape cs = new SphereCollisionShape(); cs.Center = asteroid.Center; cs.Radius = asteroid.Radius; asteroid.CollisionShape = cs; NewtonianMovementControl nmc = new NewtonianMovementControl(); nmc.Speed = speed; asteroid.AddControl(nmc); LinearRotationControl lrc = new LinearRotationControl(); lrc.RotationSpeed = mgr.GetRandomGenerator().Next(SharedDef.MIN_ASTEROID_ROTATION_SPEED, SharedDef.MAX_ASTEROID_ROTATION_SPEED) / 10.0f; asteroid.AddControl(lrc); asteroid.AddControl(new MinorAsteroidCollisionReactionControl()); asteroid.AddControl(new StickySphereCollisionShapeControl()); return(asteroid); }
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); }
public static void ReadObjectMinorAsteroid(this NetIncomingMessage msg, MinorAsteroid a) { msg.ReadObjectAsteroid(a); a.Direction = msg.ReadVector(); }
public static void WriteObjectMinorAsteroid(this NetOutgoingMessage msg, MinorAsteroid a) { msg.WriteObjectAsteroid(a); msg.Write(a.Direction); msg.Write(a.Parent.Id); }