private void ReceivedAllAsteroidsMsg(NetIncomingMessage msg)
        {
            if (objects.Count > 2)
            {
                Logger.Error("Receiving All Asteroids packet but already have " + objects.Count + " objects");
                return;
            }

            int count = msg.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                if (msg.ReadInt32() != (int)PacketType.NEW_ASTEROID)
                {
                    Logger.Error("Corrupted object PacketType.SYNC_ALL_ASTEROIDS");
                    return;
                }
                Asteroid s = CreateNewAsteroid((AsteroidType)msg.ReadByte());
                s.ReadObject(msg);
                s.SetGeometry(SceneGeometryFactory.CreateAsteroidImage(s));
                DelayedAttachToScene(s);
                SyncReceivedObject(s, msg);
            }
            isGameInitialized = true;
        }
        private void ReceivedNewAsteroidMsg(NetIncomingMessage msg)
        {
            Asteroid s = CreateNewAsteroid((AsteroidType)msg.ReadByte());

            s.ReadObject(msg);
            s.SetGeometry(SceneGeometryFactory.CreateAsteroidImage(s));
            DelayedAttachToScene(s);
            SyncReceivedObject(s, msg);
        }
Exemple #3
0
        public void SpawnAsteroid()
        {
            if (AsteroidSpawned)
            {
                return;
            }

            AsteroidSpawned = true;
            me.RemoveControlsOfType <HighlightingControl>();

            Asteroid ast = new Asteroid(me.SceneMgr, IdMgr.GetNewId(me.SceneMgr.GetCurrentPlayer().GetId()));

            ast.Gold      = 0;
            ast.Radius    = 20;
            ast.Position  = new Vector(me.Position.X - ast.Radius, me.Position.Y - ast.Radius);
            ast.Direction = (me as IMovable).Direction;

            ast.AsteroidType = AsteroidType.NORMAL;
            ast.TextureId    = me.SceneMgr.GetRandomGenerator().Next(1, 18);

            SphereCollisionShape cs = new SphereCollisionShape();

            cs.Center          = ast.Center;
            cs.Radius          = ast.Radius;
            ast.CollisionShape = cs;

            ast.SetGeometry(SceneGeometryFactory.CreateAsteroidImage(ast));

            me.SceneMgr.DelayedAttachToScene(ast);

            collided.Add(ast.Id);

            ast.AddControl(new StickySphereCollisionShapeControl());

            NewtonianMovementControl nmc = new NewtonianMovementControl();

            nmc.Speed = me.SceneMgr.GetCurrentPlayer().Data.MineFallingSpeed;
            ast.AddControl(nmc);

            NetOutgoingMessage msg = me.SceneMgr.CreateNetMessage();

            ast.WriteObject(msg);

            me.SceneMgr.SendMessage(msg);
        }