Пример #1
0
        protected void updateTile(int Index)
        {
            FlxTile tile = _tileObjects[_data[Index]] as FlxTile;

            if ((tile == null) || !tile.Visible)
            {
                _rects[Index] = Rectangle.Empty;
                return;
            }
            int rx = (int)(_data[Index] - _startingIndex) * _tileWidth;
            int ry = 0;

            if (rx >= _tiles.Width)
            {
                ry  = (rx / _tiles.Width) * _tileHeight;
                rx %= _tiles.Width;
            }
            _rects[Index] = (new Rectangle(rx, ry, _tileWidth, _tileHeight));
        }
Пример #2
0
        public FlxTilemap loadMap(String CSVdataFile, String Graphic, int TileWidth, int TileHeight, uint DrawIndex = 0, int CollideIndex = 1)
        {
            collideIndex = CollideIndex;
            //_tileWidth = _tileHeight = tileSize = TileSize;

            //StreamReader stream = new StreamReader(TitleContainer.OpenStream(CSVdataFile));
            //CSVdataFile = stream.ReadToEnd();

            String[] columns;
            String[] rows = new String[] { };
            rows = CSVdataFile.Split('\n');

            heightInTiles = rows.Length;
            _data         = new int[heightInTiles * (rows[0].Split(',').Length)];

            int row = 0;
            int column;
            int counter = 0;

            while (row < heightInTiles)
            {
                columns = rows[row++].Split(',');
                if (columns.Length <= 1)
                {
                    heightInTiles = heightInTiles - 1;
                    continue;
                }
                if (widthInTiles == 0)
                {
                    widthInTiles = columns.Length;
                }
                column = 0;
                while (column < widthInTiles)
                {
                    if (columns [column].Length > 0)
                    {
                        _data [counter++] = Convert.ToInt32(columns [column++]);
                    }
                }
            }

            totalTiles = heightInTiles * widthInTiles;

            tileGraphic = _tiles = FlxS.ContentManager.Load <Texture2D>(Graphic);
            _tileWidth  = TileWidth;
            if (_tileWidth == 0)
            {
                _tileWidth = _tiles.Height;
            }
            _tileHeight = TileHeight;
            if (_tileHeight == 0)
            {
                _tileHeight = _tileWidth;
            }

            //create some tile objects that we'll use for overlap checks, one for each tile
            uint i = 0;
            uint l = (uint)(_tiles.Width / _tileWidth) * (uint)(_tiles.Height / _tileHeight);

            //_tileObjects = new List<FlxTile>
            _tileObjects = new FlxTile[l];

            //FlxG.log("size " + l);

            while (i < l)
            {
                //                           (FlxTilemap Tilemap, int Tx, int Ty, int Index, int Width, int Height, Boolean Visible, uint AllowCollisions)
                _tileObjects[i] = new FlxTile(this, 0, 0, (int)i, _tileWidth, _tileHeight, (i >= DrawIndex), (i >= CollideIndex) ? AllowCollisions : None);
                i++;
            }



            Width  = widthInTiles * _tileWidth;
            Height = heightInTiles * _tileHeight;
            _rects = new Rectangle[totalTiles];

            //create the actual map
            i = 0;
            while (i < totalTiles)
            {
                updateTile((int)i++);
            }



            int ty    = 0;
            int tx    = 0;
            int index = 0;

            for (ty = 0; ty < heightInTiles; ty++)
            {
                for (tx = 0; tx < widthInTiles; tx++)
                {
                    FlxTile _temp = new FlxTile(this, tx, ty, (int)_data[index], _tileWidth, _tileHeight, (_data[index] >= DrawIndex) ? true : false, (_data[index] >= CollideIndex) ? AllowCollisions : None);
                    _tileObjectsForDrawing.Add(_temp);



                    //if (_data[index] >= CollideIndex)
                    //{
                    //    FlxSprite _newTile = new FlxSprite(tx * _tileWidth, ty * _tileHeight);
                    //    _newTile.makeGraphic(_temp.width, _temp.height, FlxColor.BLUE);
                    //    _newTile.solid = _newTile.immovable = true;
                    //    _temp.solid = true;
                    //    add(_newTile);
                    //}

                    if (index < totalTiles)
                    {
                        index++;
                    }
                }
            }



            return(this);
        }
Пример #3
0
        public FlxTilemap loadMap(String CSVdataFile, String Graphic, int TileWidth, int TileHeight, uint DrawIndex = 0, int CollideIndex = 1)
        {
            collideIndex = CollideIndex;
            //_tileWidth = _tileHeight = tileSize = TileSize;

            //StreamReader stream = new StreamReader(TitleContainer.OpenStream(CSVdataFile));
            //CSVdataFile = stream.ReadToEnd();

            String[] columns;
            String[] rows = new String[] { };
            rows = CSVdataFile.Split('\n');

            heightInTiles = rows.Length;
            _data = new int[heightInTiles*(rows[0].Split(',').Length)];

            int row = 0;
            int column;
            int counter = 0;
            while (row < heightInTiles)
            {
                columns = rows[row++].Split(',');
                if (columns.Length <= 1)
                {
                    heightInTiles = heightInTiles - 1;
                    continue;
                }
                if (widthInTiles == 0)
                    widthInTiles = columns.Length;
                column = 0;
                while (column < widthInTiles) {
                    if (columns [column].Length > 0) {
                        _data [counter++] = Convert.ToInt32 (columns [column++]);
                    }
                }
            }

            totalTiles = heightInTiles * widthInTiles;

            tileGraphic = _tiles = FlxS.ContentManager.Load<Texture2D>(Graphic);
            _tileWidth = TileWidth;
            if (_tileWidth == 0)
                _tileWidth = _tiles.Height;
            _tileHeight = TileHeight;
            if (_tileHeight == 0)
                _tileHeight = _tileWidth;

            //create some tile objects that we'll use for overlap checks, one for each tile
            uint i = 0;
            uint l = (uint)(_tiles.Width / _tileWidth) * (uint)(_tiles.Height / _tileHeight);
            //_tileObjects = new List<FlxTile>
            _tileObjects = new FlxTile[l];

            //FlxG.log("size " + l);

            while (i < l)
            {
                //                           (FlxTilemap Tilemap, int Tx, int Ty, int Index, int Width, int Height, Boolean Visible, uint AllowCollisions)
                _tileObjects[i] = new FlxTile(this, 0, 0, (int)i, _tileWidth, _tileHeight, (i >= DrawIndex), (i >= CollideIndex) ? AllowCollisions : None);
                i++;
            }

            Width = widthInTiles * _tileWidth;
            Height = heightInTiles * _tileHeight;
            _rects = new Rectangle[totalTiles];

            //create the actual map
            i = 0;
            while (i < totalTiles)
                updateTile((int)i++);

            int ty = 0;
            int tx = 0;
            int index = 0;
            for (ty = 0; ty < heightInTiles; ty++)
            {
                for (tx = 0; tx < widthInTiles; tx++)
                {
                    FlxTile _temp = new FlxTile(this, tx, ty, (int)_data[index], _tileWidth, _tileHeight, (_data[index] >= DrawIndex) ? true : false, (_data[index] >= CollideIndex) ? AllowCollisions : None);
                    _tileObjectsForDrawing.Add(_temp);

                    //if (_data[index] >= CollideIndex)
                    //{
                    //    FlxSprite _newTile = new FlxSprite(tx * _tileWidth, ty * _tileHeight);
                    //    _newTile.makeGraphic(_temp.width, _temp.height, FlxColor.BLUE);
                    //    _newTile.solid = _newTile.immovable = true;
                    //    _temp.solid = true;
                    //    add(_newTile);
                    //}

                    if (index < totalTiles)
                        index++;
                }
            }

            return this;
        }