コード例 #1
0
 /// <summary>
 /// Basically, the TiledMap is initialized with default values
 /// </summary>
 /// <param name="groundLayer">The ground layers</param>
 /// <param name="layers">The deco layers</param>
 /// <param name="groundTileWidth">The ground tile width</param>
 /// <param name="groundTileHeight">The ground tile height</param>
 /// <param name="decoTileHeight">The decoration tile height</param>
 public TileMapIso(LayerIso groundLayer, LayerIso[] layers, int groundTileWidth, int groundTileHeight, int decoTileHeight)
 {
     //_tilesetName = groundTilesetName;
     _groundLayer    = groundLayer;
     _layers         = layers;
     _tileWidth      = groundTileWidth;
     _tileHeight     = groundTileHeight;
     _mapWidth       = groundLayer.LayerWidth;
     _mapHeight      = groundLayer.LayerHeight;
     _decoTileHeight = decoTileHeight;
 }
コード例 #2
0
ファイル: TileMapIso.cs プロジェクト: shaoleibo/YnaEngine
 /// <summary>
 /// Basically, the TiledMap is initialized with default values
 /// </summary>
 /// <param name="groundLayer">The ground layers</param>
 /// <param name="layers">The deco layers</param>
 /// <param name="groundTileWidth">The ground tile width</param>
 /// <param name="groundTileHeight">The ground tile height</param>
 /// <param name="decoTileHeight">The decoration tile height</param>
 public TileMapIso(LayerIso groundLayer, LayerIso[] layers, int groundTileWidth, int groundTileHeight, int decoTileHeight)
 {
     //_tilesetName = groundTilesetName;
     _groundLayer = groundLayer;
     _layers = layers;
     _tileWidth = groundTileWidth;
     _tileHeight = groundTileHeight;
     _mapWidth = groundLayer.LayerWidth;
     _mapHeight = groundLayer.LayerHeight;
     _decoTileHeight = decoTileHeight;
 }
コード例 #3
0
 /// <summary>
 /// Basically, the TiledMap is initialized with default values
 /// </summary>
 /// <param name="groundTilesetName">The Tileset file name</param>
 /// <param name="groundLayer">The ground layers</param>
 /// <param name="tileWidth">The tile width</param>
 /// <param name="tileHeight">The tile height</param>
 public TileMapIso(LayerIso groundLayer, int tileWidth, int tileHeight)
     : this(groundLayer, new LayerIso[] { }, tileWidth, tileHeight, 0)
 {
 }
コード例 #4
0
        public void DrawLayer(SpriteBatch spriteBatch, Vector2 camera, Rectangle drawZone, LayerIso layer, int tileWidth, int tileHeight, bool isDeco)
        {
            TileIso   tile;
            Rectangle texRect;
            Vector2   position;
            int       delta;
            int       decoDelta = 0;

            for (int x = 0; x < _mapWidth; x++)
            {
                for (int y = 0; y < _mapHeight; y++)
                {
                    tile      = (TileIso)layer[x, y];
                    decoDelta = 0;

                    // Negative ID represents invisible tiles and do not need to be rendered
                    if (tile.TextureID >= 0)
                    {
                        // Here we get the translated coordinates of the current tile
                        // Note that this position is the simple translation of the tile
                        // position on the map.
                        position = IsometricHelper.ToOrtho(x, y);

                        // To get correct orthogonals coordinates, they're respectively
                        // multiplied by half width and half height
                        position.X *= _tileWidth / 2;
                        position.Y *= _tileHeight / 2;

                        // We're almost done : add the camera position
                        position.X += camera.X;
                        position.Y += camera.Y;

                        // Special translation for decoration tiles. If the tile hieght is
                        // different from the ground tile size, an adjustment is needed

                        /*
                         *                      if(tileset != _tileset)
                         *                      {
                         *                              // Here we have a decoration layer
                         *                              position.Y -= _decoTileHeight/2;
                         *                      }
                         */
                        // Textures may not be rendered entirely if the drawZone parameter
                        // is a smaller rectangle than the game window.
                        texRect = layer.Mapping[tile.TileType() + tile.TextureID * 23];
                        if (drawZone.Width != YnG.Width && drawZone.Height != YnG.Height)
                        {
                            // The tile must be cropped.
                            // If the tile is on the edge of the draw zone, only the portion
                            // of the tile in the zone is rendered

                            // For decoration layers, tile height must be handled too
                            if (isDeco)
                            {
                                position.Y -= _decoTileHeight / 2;
                            }

                            if (position.X < drawZone.X)
                            {
                                // The tile is out on the left side
                                delta          = drawZone.X - (int)position.X;
                                texRect.X     += delta;
                                texRect.Width -= delta;
                                position.X     = drawZone.X;
                            }
                            else if (position.X > drawZone.X + drawZone.Width - tileWidth)
                            {
                                // The tile is out on the right side
                                delta          = drawZone.X + drawZone.Width - (int)position.X;
                                texRect.Width -= tileWidth - delta;
                            }

                            if (position.Y < drawZone.Y)
                            {
                                // The tile is out on the top side
                                delta           = drawZone.Y - (int)position.Y;
                                texRect.Y      += delta;
                                texRect.Height -= delta;
                                position.Y      = drawZone.Y;
                            }
                            else if (position.Y > drawZone.Y + drawZone.Height - tileHeight)
                            {
                                // The tile is out on the bottom side
                                delta           = drawZone.Y + drawZone.Height - (int)position.Y;
                                texRect.Height -= tileHeight - delta;
                            }
                        }



                        spriteBatch.Draw(layer.Tileset, position, texRect, Color.White);
                    }
                }
            }
        }
コード例 #5
0
ファイル: TileMapIso.cs プロジェクト: shaoleibo/YnaEngine
 /// <summary>
 /// Basically, the TiledMap is initialized with default values
 /// </summary>
 /// <param name="groundTilesetName">The Tileset file name</param>
 /// <param name="groundLayer">The ground layers</param>
 /// <param name="tileWidth">The tile width</param>
 /// <param name="tileHeight">The tile height</param>
 public TileMapIso(LayerIso groundLayer, int tileWidth, int tileHeight)
     : this(groundLayer, new LayerIso[] { }, tileWidth, tileHeight, 0)
 {
 }
コード例 #6
0
ファイル: TileMapIso.cs プロジェクト: shaoleibo/YnaEngine
        public void DrawLayer(SpriteBatch spriteBatch, Vector2 camera, Rectangle drawZone, LayerIso layer, int tileWidth, int tileHeight, bool isDeco)
        {
            TileIso tile;
            Rectangle texRect;
            Vector2 position;
            int delta;
            int decoDelta = 0;
            for (int x = 0; x < _mapWidth; x++)
            {
                for (int y = 0; y < _mapHeight; y++)
                {
                    tile = (TileIso)layer[x, y];
                    decoDelta = 0;

                    // Negative ID represents invisible tiles and do not need to be rendered
                    if (tile.TextureID >= 0)
                    {
                        // Here we get the translated coordinates of the current tile
                        // Note that this position is the simple translation of the tile
                        // position on the map.
                        position = IsometricHelper.ToOrtho(x, y);

                        // To get correct orthogonals coordinates, they're respectively 
                        // multiplied by half width and half height
                        position.X *= _tileWidth / 2;
                        position.Y *= _tileHeight / 2;

                        // We're almost done : add the camera position
                        position.X += camera.X;
                        position.Y += camera.Y;

                        // Special translation for decoration tiles. If the tile hieght is
                        // different from the ground tile size, an adjustment is needed
                        /*
						if(tileset != _tileset)
						{
							// Here we have a decoration layer
							position.Y -= _decoTileHeight/2;
						}
						*/
                        // Textures may not be rendered entirely if the drawZone parameter
                        // is a smaller rectangle than the game window.
                        texRect = layer.Mapping[tile.TileType() + tile.TextureID * 23];
                        if (drawZone.Width != YnG.Width && drawZone.Height != YnG.Height)
                        {
                            // The tile must be cropped.
                            // If the tile is on the edge of the draw zone, only the portion
                            // of the tile in the zone is rendered

                            // For decoration layers, tile height must be handled too
                            if (isDeco)
                            {
                                position.Y -= _decoTileHeight / 2;
                            }

                            if (position.X < drawZone.X)
                            {
                                // The tile is out on the left side
                                delta = drawZone.X - (int)position.X;
                                texRect.X += delta;
                                texRect.Width -= delta;
                                position.X = drawZone.X;
                            }
                            else if (position.X > drawZone.X + drawZone.Width - tileWidth)
                            {
                                // The tile is out on the right side
                                delta = drawZone.X + drawZone.Width - (int)position.X;
                                texRect.Width -= tileWidth - delta;
                            }

                            if (position.Y < drawZone.Y)
                            {
                                // The tile is out on the top side
                                delta = drawZone.Y - (int)position.Y;
                                texRect.Y += delta;
                                texRect.Height -= delta;
                                position.Y = drawZone.Y;
                            }
                            else if (position.Y > drawZone.Y + drawZone.Height - tileHeight)
                            {
                                // The tile is out on the bottom side
                                delta = drawZone.Y + drawZone.Height - (int)position.Y;
                                texRect.Height -= tileHeight - delta;
                            }
                        }

                        

                        spriteBatch.Draw(layer.Tileset, position, texRect, Color.White);
                    }
                }
            }
        }