Inheritance: FlxObject
Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public FlxTilemap loadMap(String CSVdataFile, Texture2D Graphic, int TileWidth, int TileHeight, int 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 List <int>();

            int row = 0;
            int column;

            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)
                {
                    _data.Add(Convert.ToInt32(columns[column++]));
                }
            }

            totalTiles = heightInTiles * widthInTiles;

            tileGraphic = _tiles = 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);
        }
Ejemplo n.º 3
0
        public FlxTilemap loadMap(String CSVdataFile, Texture2D Graphic, int TileWidth, int TileHeight, int 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 List<int>();

            int row = 0;
            int column;
            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)
                    _data.Add(Convert.ToInt32(columns[column++]));
            }

            totalTiles = heightInTiles * widthInTiles;

            tileGraphic = _tiles = 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;
        }