Exemplo n.º 1
0
        public static void Update()
        {
            if (!Client.Connected)
            {
                return;
            }

            Player.Update(Level);

            GameState state = MakeGameState();

            Client.SendUpdate(state);
            state = Client.ReceiveUpdate();
            if (state != null)
            {
                switch (state.Type)
                {
                case GameState.RequestType.Update:
                    UpdateFromGameState((UpdateRequest)state);
                    break;

                case GameState.RequestType.LevelUpdate:
                    levelInfos = (LevelUpdateRequest)state;
                    LoadLevel();
                    TextureUpdated = true;
                    Respawn();
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public static void Init(GameState state, string name)
        {
            Running    = true;
            Player     = new Player(state.PlayerID, name);
            levelInfos = (LevelUpdateRequest)state;

            LoadLevel();

            state = MakeGameState();
            Client.SendUpdate(state);

            state = Client.ReceiveUpdate();
            for (int i = 0; i < 10 && state == null; ++i)
            {
                Thread.Sleep(300);
                state = Client.ReceiveUpdate();
            }
            if (state == null)
            {
                Client.SendDisconnect();
                return;
            }
            if (state.Type != GameState.RequestType.Update)
            {
                return;
            }

            UpdateFromGameState((UpdateRequest)state);
            Respawn();
        }
Exemplo n.º 3
0
 public Level(LevelUpdateRequest state)
 {
     Bounds = new IntRect(
         left: 0,
         top: 0,
         width: state.Dimensions.X,
         height: state.Dimensions.Y
         );
     Tiles = new List <Tile>();
     for (int i = 0; i < state.TilePos.Length; ++i)
     {
         Tiles.Add(new Tile(state.TilePos[i].X, state.TilePos[i].Y));
     }
     SpawnPoints = new List <Vector2i>();
     for (int i = 0; i < state.SpawnPoints.Length; ++i)
     {
         SpawnPoints.Add(new Vector2i(state.SpawnPoints[i].X, state.SpawnPoints[i].Y));
     }
 }