Ejemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="game"></param>
        public MapScroller(ClientGame game, GameState state)
        {
            RegisterListeners();
            characterAvailable = true;
            _game = game;
            _module = state.Module;
            _iso = _module.Map.Iso;
            _state = state;
            _spriteBatch = game.SpriteBatch;
            _gameFont = game.Content.Load<SpriteFont>("Fonts//gameFont");
            _circle = _game.Content.Load<Texture2D>("Textures//circle");
            _screenSpace = new Rectangle(0, 0, _game.GraphicsDevice.PresentationParameters.BackBufferWidth, _game.GraphicsDevice.PresentationParameters.BackBufferHeight);

            //  World space
            var max = _iso.TilePlotter(new Point(_module.Map.Width - 1, _module.Map.Height - 1));
            _worldSpace = new Rectangle(0, 0, max.X + _module.Map.TileWidth, max.Y + _module.Map.TileHeight);
            //  Anchor space
            _anchorSpace = _worldSpace;
            var horizontal = _screenSpace.Right - _screenSpace.Left;
            _anchorSpace.Width -= horizontal;
            if (_anchorSpace.Right < _anchorSpace.Left)
                _anchorSpace.Width = 0;
            var vertical = _screenSpace.Bottom - _screenSpace.Top;
            _anchorSpace.Height -= vertical;
            if (_anchorSpace.Bottom < _anchorSpace.Top)
                _anchorSpace.Height = 0;
            //  Adjust for staggered maps to eliminate jaggies when scrolling to map edge
            if (_iso.Style == IsometricStyle.Staggered)
            {
                _anchorSpace.Y += _module.Map.TileHeight / 2;
                _anchorSpace.Height -= _module.Map.TileHeight / 2;

                _anchorSpace.X += _module.Map.TileWidth / 2;
                _anchorSpace.Width -= _module.Map.TileWidth / 2;

                _screenAnchor = new Point(_anchorSpace.Left, _anchorSpace.Top);
            }
            else
            {
                //  Screen anchor
                _screenAnchor = new Point(0, 0);
            }

        }