private ITileLayer[] GetTileLayers()
        {
            bool invalidCache = false;

            if (this.cachedTileLayers.Length == this.ActiveTileLayers.Length)
            {
                for (int i = 0; i < this.ActiveTileLayers.Length; ++i)
                {
                    if (this.cachedTileLayers[i].Name != this.ActiveTileLayers[i])
                    {
                        invalidCache = true;
                    }
                }
            }
            else
            {
                invalidCache = true;
            }

            if (invalidCache)
            {
                ITileLayer[] tileLayers = new ITileLayer[this.ActiveTileLayers.Length];
                for (int i = 0; i < this.ActiveTileLayers.Length; ++i)
                {
                    tileLayers[i] = Root.GameService.GraphicConfig.TileLayers[this.ActiveTileLayers[i]];
                }

                this.cachedTileLayers = tileLayers;
            }

            return(this.cachedTileLayers);
        }
예제 #2
0
 private void ExpandArea(int x, int y, string name, ITileLayer areaLayer)
 {
     if (AreaNames[x][y] != null) return;
     Tile tile = areaLayer.GetActorAt(x,y);
     if (tile is AreaBorder) return;
     AreaNames[x][y] = name;
     ExpandArea(x + 1, y, name, areaLayer);
     ExpandArea(x, y + 1, name, areaLayer);
     ExpandArea(x, y - 1, name, areaLayer);
     ExpandArea(x - 1, y, name, areaLayer);
 }
예제 #3
0
        public AreasCarrier(ITileLayer pathLayer, ITileLayer areaLayer, List <Tuple <Vector2I, string> > positionsNamesTuples)
        {
            Rooms     = ArrayCreator.CreateJaggedArray <Room[][]>(pathLayer.Width, pathLayer.Height);
            AreaNames = ArrayCreator.CreateJaggedArray <string[][]>(pathLayer.Width, pathLayer.Height);

            foreach (Tuple <Vector2I, string> positionNameTuple in positionsNamesTuples)
            {
                Vector2I position = positionNameTuple.Item1;
                string   name     = positionNameTuple.Item2;
                FillNamedArea(position.X, position.Y, name, pathLayer, areaLayer);
            }
        }
예제 #4
0
 private void FillNamedArea(int x, int y, string name, ITileLayer pathLayer, ITileLayer areaLayer)
 {
     Tile tile = pathLayer.GetActorAt(x, y);
     if (tile is RoomTile)
     {
         FillRoom(x, y, name, pathLayer);
     }
     else
     {
         FillArea(x, y, name, areaLayer);
     }
 }
예제 #5
0
        public AreasCarrier(ITileLayer pathLayer, ITileLayer areaLayer, List<Tuple<Vector2I, string>> positionsNamesTuples)
        {
            Rooms = ArrayCreator.CreateJaggedArray<Room[][]>(pathLayer.Width, pathLayer.Height);
            AreaNames = ArrayCreator.CreateJaggedArray<string[][]>(pathLayer.Width, pathLayer.Height);

            foreach (Tuple<Vector2I, string> positionNameTuple in positionsNamesTuples)
            {
                Vector2I position = positionNameTuple.Item1;
                string name = positionNameTuple.Item2;
                FillNamedArea(position.X, position.Y, name, pathLayer, areaLayer);
            }
        }
    public virtual void DrawSprite(int spriteIndex, TTile tile, int i, int j, ITileLayer <TTile> layer, Vector2 drawOffset, float layerDepth = 1f)
    {
        var destRect = GetDestinationRectangle(i, j, layer.DrawOffset + drawOffset);

        if (destRect != null)
        {
            SpriteBatch.Draw(SpriteSheet, position: destRect.Value.Position,
                             sourceRectangle: GetSourceRectangle(spriteIndex),
                             color: layer.DrawColor, rotation: Rotation, effects: SpriteEffects,
                             origin: Vector2.Zero, scale: DrawScale, layerDepth: layerDepth);
        }
    }
예제 #7
0
        private void FillNamedArea(int x, int y, string name, ITileLayer pathLayer, ITileLayer areaLayer)
        {
            Tile tile = pathLayer.GetActorAt(x, y);

            if (tile is RoomTile)
            {
                FillRoom(x, y, name, pathLayer);
            }
            else
            {
                FillArea(x, y, name, areaLayer);
            }
        }
예제 #8
0
    protected override int GetNeighborValue(DungeonTile _tile, int x, int y, ITileLayer <DungeonTile> layer, int neighborValue)
    {
        if (x < 0 || y < 0 || x >= layer.Width || y >= layer.Height)
        {
            return(0);
        }

        if (layer.GetTileValue(x, y) < DungeonTile.WALL_START || DungeonPlayer.Instance.CanSee(x, y) == FogOfWar.Full)
        {
            return(0);
        }

        return(neighborValue);
    }
예제 #9
0
    protected override int GetNeighborValue(MiniMapTile _tile, int x, int y, ITileLayer <MiniMapTile> layer, int neighborValue)
    {
        if (x < 0 || y < 0 || x >= layer.Width || y >= layer.Height)
        {
            return(0);
        }

        if (layer.GetTileValue(x, y) < MiniMapTile.WALL_START)
        {
            return(0);
        }

        return(neighborValue);
    }
예제 #10
0
 private void FillArea(int x, int y, string name, ITileLayer areaLayer)
 {
     if (AreaNames[x][y] != null)
     {
         if (AreaNames[x][y] == name)
         {
             Log.Instance.Info("Area \"" + name + "\" has two AreaLabels.");
         }
         else
         {
             Log.Instance.Warn("Two AreaLabels in one Area: \"" + AreaNames[x][y] + "\", \"" + name + "\".");
         }
     }
     ExpandArea(x, y, name, areaLayer);
 }
예제 #11
0
 private void FillArea(int x, int y, string name, ITileLayer areaLayer)
 {
     if (AreaNames[x][y] != null)
     {
         if (AreaNames[x][y] == name)
         {
             Log.Instance.Info("Area \"" + name + "\" has two AreaLabels.");
         }
         else
         {
             Log.Instance.Warn("Two AreaLabels in one Area: \"" + AreaNames[x][y] + "\", \"" + name + "\".");
         }
     }
     ExpandArea(x, y, name, areaLayer);
 }
예제 #12
0
 private void ExpandRoom(int x, int y, Room room, ITileLayer pathLayer)
 {
     if (Rooms[x][y] != null)
     {
         return;
     }
     if (!(pathLayer.GetActorAt(x, y) is RoomTile))
     {
         return;
     }
     Rooms[x][y] = room;
     room.Size++;
     ExpandRoom(x + 1, y, room, pathLayer);
     ExpandRoom(x, y + 1, room, pathLayer);
     ExpandRoom(x, y - 1, room, pathLayer);
     ExpandRoom(x - 1, y, room, pathLayer);
 }
예제 #13
0
        private void FillRoom(int x, int y, string name, ITileLayer pathLayer)
        {
            if (Rooms[x][y] != null)
            {
                if (Rooms[x][y].Name == name)
                {
                    Log.Instance.Info("RoomTile " + name + " has two AreaLabels.");
                }
                else
                {
                    Log.Instance.Warn("Two AreaLabels in one RoomTile: \"" + Rooms[x][y] + "\", \"" + name + "\".");
                }
                return;
            }
            var room = new Room(name);

            ExpandRoom(x, y, room, pathLayer);
        }
예제 #14
0
    public override void DrawSprite(int spriteIndex, MiniMapTile tile, int i, int j, ITileLayer <MiniMapTile> layer, Vector2 drawOffset, float layerDepth = 1)
    {
        var rect = GetDestinationRectangle(i, j, drawOffset);

        if (rect == null)
        {
            return;
        }

        if (DungeonPlayer.Instance.GetMiniMapTile(i, j) != MiniMapTile.None)
        {
            base.DrawSprite(spriteIndex, tile, i, j, layer, drawOffset, layerDepth);
        }
        if (DungeonPlayer.Instance.CanSee(i, j) == FogOfWar.Half)
        {
            SpriteBatch.FillRectangle(rect.Value, FogOfWarColor, 1f);
        }
    }
예제 #15
0
        private void ExpandArea(int x, int y, string name, ITileLayer areaLayer)
        {
            if (AreaNames[x][y] != null)
            {
                return;
            }
            Tile tile = areaLayer.GetActorAt(x, y);

            if (tile is AreaBorder)
            {
                return;
            }
            AreaNames[x][y] = name;
            ExpandArea(x + 1, y, name, areaLayer);
            ExpandArea(x, y + 1, name, areaLayer);
            ExpandArea(x, y - 1, name, areaLayer);
            ExpandArea(x - 1, y, name, areaLayer);
        }
예제 #16
0
 private void FillRoom(int x, int y, string name, ITileLayer pathLayer)
 {
     if (Rooms[x][y] != null)
     {
         if (Rooms[x][y].Name == name)
         {
             Log.Instance.Info("RoomTile " + name + " has two AreaLabels.");
         }
         else {
             Log.Instance.Warn("Two AreaLabels in one RoomTile: \"" + Rooms[x][y] + "\", \"" + name + "\".");
         }
         return;
     }
     var room = new Room(name);
     ExpandRoom(x, y, room, pathLayer);
 }
예제 #17
0
 public void Add(ITileLayer tile)
 {
     _tiles.Add(tile);
 }
예제 #18
0
        /// <summary>
        /// Loads map from specified path, creates tiles and objects and put them into new Atlas object.
        /// </summary>
        /// <param name="map">Deserialized .tmx file</param>
        /// <param name="tilesetTable">Table of numbers of game object and theirs classes</param>
        /// <param name="initializer"></param>
        /// <returns>Atlas with initial state of ToyWorld</returns>
        public static IAtlas LoadMap(Map map, TilesetTable tilesetTable, Action <GameActor> initializer)
        {
            IAtlas atlas = new Atlas.Layers.Atlas();

            map.Tilesets = map.Tilesets.OrderBy(x => x.Firstgid).ToList();

            foreach (LayerType layerType in Enum.GetValues(typeof(LayerType)).Cast <LayerType>())
            {
                string layerName = Enum.GetName(typeof(LayerType), layerType);

                Debug.Assert(layerName != null);

                int  type       = (int)layerType;
                bool simpleType = type > 0 && (type & (type - 1)) == 0;
                if (!simpleType)
                {
                    continue;
                }

                if (layerName.Contains("Object"))
                {
                    ObjectGroup objectLayer = map.ObjectGroups.FirstOrDefault(x => x.Name == layerName);
                    if (objectLayer == null)    // TMX does not contain such layer
                    {
                        Log.Instance.Warn("Layer " + layerName + " not found in given .tmx file!");
                        continue;
                    }
                    IObjectLayer filledObjectLayer = FillObjectLayer(
                        atlas,
                        objectLayer,
                        layerType,
                        initializer,
                        map.Tilesets,
                        map.Tilewidth,
                        map.Tileheight,
                        map.Height
                        );
                    atlas.ObjectLayers.Add(
                        filledObjectLayer);
                }
                else
                {
                    Layer tileLayer = map.Layers.FirstOrDefault(x => x.Name == layerName);
                    if (tileLayer == null)  // TMX does not contain such layer
                    {
                        Log.Instance.Warn("Layer " + layerName + " not found in given .tmx file!");
                        continue;
                    }
                    Random     rnd             = new Random(); // Shared across all layers
                    ITileLayer filledTileLayer = FillTileLayer(
                        tileLayer,
                        layerType,
                        atlas.StaticTilesContainer,
                        tilesetTable,
                        initializer,
                        rnd);
                    atlas.TileLayers.Add(
                        filledTileLayer);
                }
            }

            FillNamedAreas(atlas, map);

            SetTileRelations(atlas, map);

            return(atlas);
        }
예제 #19
0
 private void ExpandRoom(int x, int y, Room room, ITileLayer pathLayer)
 {
     if (Rooms[x][y] != null) return;
     if (!(pathLayer.GetActorAt(x, y) is RoomTile)) return;
     Rooms[x][y] = room;
     room.Size++;
     ExpandRoom(x + 1, y, room, pathLayer);
     ExpandRoom(x, y + 1, room, pathLayer);
     ExpandRoom(x, y - 1, room, pathLayer);
     ExpandRoom(x - 1, y, room, pathLayer);
 }