Example #1
0
File: Module.cs Project: jo215/Iso
 /// <summary>
 /// Reads a Module from the give stream.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="iso"></param>
 /// <returns></returns>
 public static Module ReadModule(TextReader stream, Isometry iso)
 {
     Module mod = new Module();
     stream.ReadLine();  //  <Module>
     mod.Map = MapDefinition.ReadMap(stream, iso);
     stream.ReadLine();  //  <Roster>
     int numUnits = int.Parse(stream.ReadLine());
     for (int i = 0; i < numUnits; i++)
     {
         mod.Roster.Add(Unit.ReadUnit(stream));
         //  Mark the corresponding map cell as occupied
         mod.Map.Cells[mod.Roster[mod.Roster.Count - 1].X, mod.Roster[mod.Roster.Count - 1].Y].IsOccupied = true;
     }
     stream.ReadLine();  //  </Roster>
     stream.ReadLine();  //  </Module>
     return mod;
 }
Example #2
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);
            }

        }