Ejemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            PrevKey    = CurrentKey;
            CurrentKey = Keyboard.GetState();
            prevms     = ms;
            ms         = Mouse.GetState();
            string username = Login.userName;

            switch (gameState)
            {
            case GameStates.TitleScreen:
                if (playButton.Contains(ms.Position))
                {
                    if (ms.LeftButton == ButtonState.Pressed && prevms.LeftButton == ButtonState.Released)
                    {
                        loginForm.Show();
                        System.Threading.Thread.Sleep(300);
                        gameState = GameStates.GameLobby;
                    }
                }
                if (exitButton.Contains(ms.Position))
                {
                    if (ms.LeftButton == ButtonState.Pressed && prevms.LeftButton == ButtonState.Released)
                    {
                        Exit();
                    }
                }
                break;

            case GameStates.GameLobby:
                Network.Update(this);
                ChatManager.Update();
                GameLobby.Update(gameTime, ms);

                if (Login.IsConnected)
                {
                    if (CurrentKey.IsKeyDown(Keys.E) && PrevKey.IsKeyUp(Keys.E))
                    {
                        chatBox.Show();
                    }
                }

                if (GameLobby.timer <= 0)
                {
                    Random randX = new Random();
                    Random randY = new Random();
                    int    x, y;

                    x = randX.Next(0, 500);
                    y = randY.Next(0, 400);

                    Network.outmsg = Network.Client.CreateMessage();
                    Network.outmsg.Write("CharacterSelection");
                    Network.outmsg.Write(Login.userName);
                    Network.outmsg.Write(GameLobby.selectedHero);
                    Network.outmsg.Write(x);
                    Network.outmsg.Write(y);
                    Network.Client.SendMessage(Network.outmsg, NetDeliveryMethod.ReliableOrdered);
                    gameState = GameStates.PlayingState;
                }
                break;

            case GameStates.PlayingState:
                Network.Update(this);
                collisionManager.Update(this);
                Player.Update(gameTime);
                shotManager.Update();
                break;

            case GameStates.EndGameScreen:
                Network.Update(this);
                break;
            }
            base.Update(gameTime);
        }