예제 #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);
        }
예제 #2
0
        protected override void Initialize()
        {
            base.Initialize();

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

            this.mouseOverTileEntity = this.CreateMouseOverEntity(this.overTileColor, 17);
            this.Owner.AddChild(this.mouseOverTileEntity);
        }
예제 #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);
        }
예제 #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);
        }
예제 #5
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)
 {
 }
예제 #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)
 {
 }
예제 #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;
 }
예제 #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;
 }
예제 #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);
        }
예제 #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);
        }
예제 #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;
        }
예제 #12
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)
 {
 }
예제 #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);
        }
예제 #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)
 {
 }