コード例 #1
0
ファイル: Level.cs プロジェクト: danielzmud1/MonoGame2D
 private void LoadTile(List<string> lines, Tile[,] tiles, DelegateLoadTile LoadTile)
 {
     for (int y = 0; y < _tilesHeight; ++y)
         for (int x = 0; x < _tilesWidth; ++x)
         {
             char tileType = lines[y][x];
             tiles[x, y] = LoadTile(tileType, x, y);
         }
 }
コード例 #2
0
ファイル: Level.cs プロジェクト: danielzmud1/MonoGame2D
        private void DrawTiles(Tile[,] tiles)
        {
            _helperStruct.isPlayerStartX = false;
            _helperStruct.isPlayerEndX = false;
            _helperStruct.isPlayerStartY = false;
            _helperStruct.isPlayerEndY = false;

            int startX = 0;
            int startY = 0;
            int endX = _numberOfTilesWidth;
            int endY = _numberOfTilesHeight;

            var tmpX = (int)_numberOfTilesWidth / 2;
            var tmpY = (int)_numberOfTilesHeight / 2;

            _posPreX = _posX;
            _posPreY = _posY;

            if (_player.IsAnimationContinue)
                _posX = _player.PlayerPositionInMapPreX / Tile.Width;
            else _posX = _player.PlayerPositionInMapX / Tile.Width;

            if (_player.IsAnimationContinue)
                _posY = _player.PlayerPositionInMapPreY / Tile.Height;
            else _posY = _player.PlayerPositionInMapY / Tile.Height;

            // player is not near on start and end axis X
            startX = _posX - tmpX;
            // player is near 0 index in axis X
            if (_posX < tmpX)
            {
                startX = 0;
                _helperStruct.isPlayerStartX = true;
            }
            // player is near end of map in axis X
            if (_tilesWidth - _posX < tmpX)
            {
                startX = _tilesWidth - _numberOfTilesWidth;
                _helperStruct.isPlayerEndX = true;
            }

            // Axis Y
            // player is not near on start and end axis X
            startY = _posY - tmpY;
            // player is near 0 index in axis X
            if (_posY < tmpY)
            {
                startY = 0;
                _helperStruct.isPlayerStartY = true;
            }
            // player is near end of map in axis X
            if (_tilesHeight - _posY < tmpY)
            {
                startY = _tilesHeight - _numberOfTilesHeight;
                _helperStruct.isPlayerEndY = true;
            }

            endX = startX + _numberOfTilesWidth;
            endY = startY + _numberOfTilesHeight;
            for (int y = startY, i = 0; y < endY; ++y, ++i)
            {
                for (int x = startX, j = 0; x < endX; ++x, ++j)
                {
                    Texture2D texture = tiles[x, y].Texture;
                    if (texture != null)
                    {
                        Vector2 position = new Vector2(j, i) * Tile.Size;
                        _spriteBatch.Draw(texture, position, Color.White);
                    }
                }
            }
        }