Example #1
0
        /// <summary>
        /// Create the tile layer as a child entity
        /// </summary>
        /// <param name="tmxLayer">The tmx layer.</param>
        /// <param name="layerIndex">The layer index</param>
        /// <param name="previousEntities">previousEntities</param>
        private void CreateChildTileLayer(TmxLayer tmxLayer, int layerIndex, IList <Entity> previousEntities)
        {
            var tmxLayerName = tmxLayer.Name;

            Entity        layerEntity  = null;
            TiledMapLayer tileMapLayer = null;

            if (previousEntities != null)
            {
                layerEntity = previousEntities.FirstOrDefault(e => e.Tag.StartsWith(TileLayerTag) && e.Name == tmxLayerName);
                previousEntities.Remove(layerEntity);
            }

            var tileLayerOffset = new Vector2((float)tmxLayer.OffsetX, (float)tmxLayer.OffsetY);

            if (layerEntity != null)
            {
                var tileMapTransform = layerEntity.FindComponent <Transform2D>();
                tileMapLayer = layerEntity.FindComponent <TiledMapLayer>();

                if (tileMapTransform != null &&
                    tileMapLayer != null)
                {
                    tileMapTransform.LocalPosition = tileLayerOffset;
                    tileMapLayer.TmxLayerName      = tmxLayerName;
                    layerEntity.Name = tmxLayerName;
                }
                else
                {
                    this.Owner.RemoveChild(layerEntity.Name);
                    layerEntity = null;
                }
            }

            if (layerEntity == null)
            {
                tileMapLayer = new TiledMapLayer()
                {
                    TmxLayerName = tmxLayerName
                };

                layerEntity = new Entity(tmxLayerName)
                {
                    Tag = TileLayerTag
                }
                .AddComponent(tileMapLayer)
                .AddComponent(new Transform2D()
                {
                    LocalPosition = tileLayerOffset,
                    Origin        = this.transform.Origin,
                    Opacity       = (float)tmxLayer.Opacity
                })
                .AddComponent(new TiledMapLayerRenderer());
            }

            this.Owner.AddChild(layerEntity);
            this.tileLayers.Add(tmxLayerName, tileMapLayer);
        }
        protected override void Initialize()
        {
            base.Initialize();

            this.groundLayer = this.tiledMap.TileLayers["Ground"];

            this.mouseOverTileEntity = this.CreateMouseOverEntity(this.overTileColor, 17);
            this.Owner.AddChild(this.mouseOverTileEntity);
        }
Example #3
0
        /// <summary>
        /// Create the tile layer as a child entity
        /// </summary>
        /// <param name="tmxLayer">The tmx layer.</param>
        /// <param name="layerIndex">The layer index</param>
        private void CreateChildTileLayer(TmxLayer tmxLayer, int layerIndex)
        {
            var tag          = "TileLayer_" + layerIndex;
            var tmxLayerName = tmxLayer.Name;

            Entity        layerEntity  = null;
            TiledMapLayer tileMapLayer = null;

            layerEntity = this.Owner.FindChildrenByTag(tag).FirstOrDefault();
            var tileLayerOffset = new Vector2((float)tmxLayer.OffsetX, (float)tmxLayer.OffsetY);

            if (layerEntity != null)
            {
                var tileMapTransform = layerEntity.FindComponent <Transform2D>();
                tileMapLayer = layerEntity.FindComponent <TiledMapLayer>();

                if (tileMapTransform != null &&
                    tileMapLayer != null)
                {
                    tileMapTransform.LocalPosition = tileLayerOffset;
                    tileMapLayer.TmxLayerName      = tmxLayerName;
                    layerEntity.Name = tmxLayerName;
                }
                else
                {
                    this.Owner.RemoveChild(layerEntity.Name);
                    layerEntity = null;
                }
            }

            if (layerEntity == null)
            {
                tileMapLayer = new TiledMapLayer()
                {
                    TmxLayerName = tmxLayerName
                };

                layerEntity = new Entity(tmxLayerName)
                {
                    Tag = tag
                }
                .AddComponent(tileMapLayer)
                .AddComponent(new Transform2D()
                {
                    LocalPosition = tileLayerOffset,
                    Origin        = this.transform.Origin,
                    Opacity       = (float)tmxLayer.Opacity
                })
                .AddComponent(new TiledMapLayerRenderer());
                this.Owner.AddChild(layerEntity);
            }

            this.tileLayers.Add(tmxLayerName, tileMapLayer);
        }
Example #4
0
        /// <summary>
        /// Create the tile layer as a child entity
        /// </summary>
        /// <param name="tmxLayer">the tmx parsed layer.</param>
        private void CreateChildTileLayer(TmxLayer tmxLayer)
        {
            var tileMapLayer = new TiledMapLayer(tmxLayer);

            this.tileLayers.Add(tmxLayer.Name, tileMapLayer);

            Entity layerEntity = new Entity(tmxLayer.Name)
            {
                IsVisible = tmxLayer.Visible
            }
            .AddComponent(new Transform2D()
            {
                Opacity = (float)tmxLayer.Opacity
            })
            .AddComponent(tileMapLayer)
            .AddComponent(new TiledMapLayerRenderer(this.layerType, this.samplerMode));

            this.Owner.AddChild(layerEntity);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IsometricNeighbours"/> class.
 /// </summary>
 /// <param name="tileMapLayer">The tile map layer.</param>
 /// <param name="center">The center.</param>
 public IsometricNeighbours(TiledMapLayer tileMapLayer, LayerTile center)
     : base(tileMapLayer, center)
 {
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrthogonalNeighbours"/> class.
 /// </summary>
 /// <param name="tileMapLayer">The tile map layer.</param>
 /// <param name="center">The center.</param>
 public OrthogonalNeighbours(TiledMapLayer tileMapLayer, LayerTile center)
     : base(tileMapLayer, center)
 {
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StaggeredNeighbours"/> class.
 /// </summary>
 /// <param name="tileMapLayer">The tile map layer.</param>
 /// <param name="center">The center.</param>
 /// <param name="staggerAxis">The stagger axis.</param>
 /// <param name="staggerIndex">Index of the stagger.</param>
 public StaggeredNeighbours(TiledMapLayer tileMapLayer, LayerTile center, TiledMapStaggerAxisType staggerAxis, TiledMapStaggerIndexType staggerIndex)
     : base(tileMapLayer, center)
 {
     this.staggerAxis  = staggerAxis;
     this.staggerIndex = staggerIndex;
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NeighboursCollection"/> class.
 /// </summary>
 /// <param name="tileMapLayer">The tile map layer.</param>
 /// <param name="center">The tile reference (center).</param>
 public NeighboursCollection(TiledMapLayer tileMapLayer, LayerTile center)
 {
     this.tileMapLayer = tileMapLayer;
     this.center       = center;
 }
Example #9
0
        /// <summary>
        /// Create the tile layer as a child entity
        /// </summary>
        /// <param name="tmxLayer">the tmx parsed layer.</param>
        private void CreateChildTileLayer(TmxLayer tmxLayer)
        {
            var tileMapLayer = new TiledMapLayer(tmxLayer);
            this.tileLayers.Add(tmxLayer.Name, tileMapLayer);

            Entity layerEntity = new Entity(tmxLayer.Name)
            {
                IsVisible = tmxLayer.Visible
            }
            .AddComponent(new Transform2D()
            {
                Opacity = (float)tmxLayer.Opacity
            })
            .AddComponent(tileMapLayer)
            .AddComponent(new TiledMapLayerRenderer(this.layerType, this.samplerMode));

            this.Owner.AddChild(layerEntity);
        }
Example #10
0
        protected override void Initialize()
        {
            base.Initialize();

            // Generate the Adjacency Matrix based on the TiledMapLayer
            this.groundTiledLayer = this.tiledMap.TileLayers["Ground"];

            this.pathFinder.AdjacencyMatrix = this.GetAdjacencyMatrixFromTiledMapLayer(this.groundTiledLayer, this.weightsByTileId);

            // TODO: NOT NECESSARY
            this.pathFindingAlgorithm.AdjacencyMatrix = this.pathFinder.AdjacencyMatrix;

            this.currentTile = this.groundTiledLayer.GetLayerTileByMapCoordinates(2, 3);

            // Move to starting tile
            this.SetTransformPosition(this.currentTile.LocalPosition);
        }
Example #11
0
        private AdjacencyMatrix<LayerTile> GetAdjacencyMatrixFromTiledMapLayer(TiledMapLayer tiledMapLayer, IDictionary<int, int> weights)
        {
            var result = new AdjacencyMatrix<LayerTile>();

            foreach (var tile in tiledMapLayer.Tiles)
            {
                if (weights.ContainsKey(tile.Id))
                {
                    foreach (var neighbour in tiledMapLayer.GetNeighboursFromTile(tile))
                    {
                        if (neighbour != null && weights.ContainsKey(neighbour.Id))
                        {
                            result.AddAdjacent(tile, neighbour, weights[neighbour.Id]);
                        }
                    }
                }
            }

            return result;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OrthogonalNeighbours"/> class.
 /// </summary>
 /// <param name="tileMapLayer">The tile map layer.</param>
 /// <param name="center">The center.</param>
 public OrthogonalNeighbours(TiledMapLayer tileMapLayer, LayerTile center)
     : base(tileMapLayer, center)
 {
 }
Example #13
0
        /// <summary>
        /// Create the tile layer as a child entity
        /// </summary>
        /// <param name="tmxLayer">The tmx layer.</param>
        /// <param name="layerIndex">The layer index</param>
        private void CreateChildTileLayer(TmxLayer tmxLayer, int layerIndex)
        {
            var tag = "TileLayer_" + layerIndex;
            var tmxLayerName = tmxLayer.Name;

            Entity layerEntity = null;
            TiledMapLayer tileMapLayer = null;
            layerEntity = this.Owner.FindChildrenByTag(tag).FirstOrDefault();
            var tileLayerOffset = new Vector2((float)tmxLayer.OffsetX, (float)tmxLayer.OffsetY);

            if (layerEntity != null)
            {
                var tileMapTransform = layerEntity.FindComponent<Transform2D>();
                tileMapLayer = layerEntity.FindComponent<TiledMapLayer>();

                if (tileMapTransform != null
                 && tileMapLayer != null)
                {
                    tileMapTransform.LocalPosition = tileLayerOffset;
                    tileMapLayer.TmxLayerName = tmxLayerName;
                    layerEntity.Name = tmxLayerName;
                }
                else
                {
                    this.Owner.RemoveChild(layerEntity.Name);
                    layerEntity = null;
                }
            }

            if (layerEntity == null)
            {
                tileMapLayer = new TiledMapLayer()
                {
                    TmxLayerName = tmxLayerName
                };

                layerEntity = new Entity(tmxLayerName)
                {
                    Tag = tag
                }
                    .AddComponent(tileMapLayer)
                    .AddComponent(new Transform2D()
                    {
                        LocalPosition = tileLayerOffset,
                        Origin = this.transform.Origin,
                        Opacity = (float)tmxLayer.Opacity
                    })
                    .AddComponent(new TiledMapLayerRenderer());
                this.Owner.AddChild(layerEntity);
            }

            this.tileLayers.Add(tmxLayerName, tileMapLayer);
        }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsometricNeighbours"/> class.
 /// </summary>
 /// <param name="tileMapLayer">The tile map layer.</param>
 /// <param name="center">The center.</param>
 public IsometricNeighbours(TiledMapLayer tileMapLayer, LayerTile center)
     : base(tileMapLayer, center)
 {
 }