Ejemplo n.º 1
0
        public void Update()
        {
            if (_client.Map.Layer1 == null)
            {
                return;
            }

            if (Core.Input.IsKeyPressed(Keys.O))
            {
                _optionsPanel.ToggleDisplay();
            }

            if (_optionsPanel.Visible)
            {
                _optionsPanel.Update();
                if (_optionsPanel.MouseIsIntersecting())
                {
                    return;
                }
            }

            var mstate = Mouse.GetState();

            _selectedItem = (_selectedItem + Core.Input.GetScrollWheelDelta() + 3) % 3;

            var kstate = Keyboard.GetState();

            Entity.Entity.Direction oldDirection = _client.Player.MovementDirection;

            if (kstate.IsKeyDown(Keys.W) && kstate.IsKeyDown(Keys.A))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.NorthWest);
            }
            else if (kstate.IsKeyDown(Keys.W) && kstate.IsKeyDown(Keys.D))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.NorthEast);
            }
            else if (kstate.IsKeyDown(Keys.S) && kstate.IsKeyDown(Keys.A))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.SouthWest);
            }
            else if (kstate.IsKeyDown(Keys.S) && kstate.IsKeyDown(Keys.D))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.SouthEast);
            }
            else if (kstate.IsKeyDown(Keys.W))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.North);
            }
            else if (kstate.IsKeyDown(Keys.A))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.West);
            }
            else if (kstate.IsKeyDown(Keys.S))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.South);
            }
            else if (kstate.IsKeyDown(Keys.D))
            {
                _client.Player.SetDirection(Entity.Entity.Direction.East);
            }
            else
            {
                _client.Player.SetDirection(Entity.Entity.Direction.None);
            }

            // Send direction update
            if (_client.Player.MovementDirection != oldDirection)
            {
                _client.SendPlayerMove();
            }

            // Send map changes
            if (Core.Input.LeftButtonDown() || Core.Input.RightButtonDown())
            {
                int tileX = (int)Math.Floor(GetMouseTileCoordinates().X);
                int tileY = (int)Math.Floor(GetMouseTileCoordinates().Y);

                int i = (int)Math.Floor(GetMouseTileCoordinates().X);
                int j = (int)Math.Floor(GetMouseTileCoordinates().Y);

                int tileId = -1;
                if (Core.Input.LeftButtonDown())
                {
                    tileId = _selectedItem + 1;
                }

                if (tileX > 0 && tileX < _client.Map.Layer2.GetLength(1) - 1 && tileY > 0 && tileY < _client.Map.Layer2.GetLength(0) - 1)
                {
                    if (_client.Map.Layer2[j, i] != tileId)
                    {
                        _client.Map.Layer2[j, i] = tileId;
                        Networking.Client.Instance.SendMapChange(j, i);
                        Engine.Content.Instance.PlaySound("Temp/hit");
                    }
                }
            }

            // Update each players
            foreach (Entity.Player player in _client.Players.Values)
            {
                player.Update();
            }
        }