Example #1
0
        /// <summary>
        /// Inititalizes a new instance of the TileSystem class.
        /// </summary>
        /// <param name="width">Total amount of tiles in the X axis.</param>
        /// <param name="height">Total amount of tiles in the Y axis.</param>
        /// <param name="tileSize">The tile size in pixels.</param>
        public TileSystem(int width, int height, int tileSize)
        {
            Width = width;
            Height = height;
            TileSize = tileSize;

            Tiles = new Tile[LayerCount][,];

            for(int i = 0; i < LayerCount; i++) Tiles[i] = new Tile[Width,Height];
        }
Example #2
0
        /// <summary>
        /// Sets the tile at XY to the target tile if all conditions are met. The only tile being checked will be the one directly to the given side.
        /// </summary>
        /// <param name="x">The X coord</param>
        /// <param name="y">The Y coord</param>
        /// <param name="side">The side to check</param>
        /// <param name="tileType">The tile type we're searching for</param>
        /// <param name="tileEdgeType">The tile type the neighbour should be.</param>
        /// <param name="setToTile">The tile at XY to set to if conditions are met.</param>
        public void PolishNeighbourExclusive(int x, int y, Tile.TileSide side, Tile.TileId tileType, Tile.TileId tileEdgeType, Tile setToTile, Tile.TileSide? tileEdgeSide)
        {
            if (this.GetTile(x, y).Id != tileType) return;

            if (this.GetNeighbourTile(x, y, side).Id == tileEdgeType)
            {
                if (tileEdgeSide != null)
                {
                    if ((Tile.TileSide)tileEdgeSide == this.GetNeighbourTile(x, y, side).Side) Tiles[0][x, y] = setToTile;

                    return;
                }

                Tiles[0][x, y] = setToTile;
            }
        }
Example #3
0
        /// <summary>
        /// Sets the tile at XY to the target tile if all conditions are met.
        /// </summary>
        /// <param name="x">The X coord</param>
        /// <param name="y">The Y coord</param>
        /// <param name="side">The side to check</param>
        /// <param name="tileType">The tile type we're searching for</param>
        /// <param name="tileEdgeType">The tile type the neighbour should be.</param>
        /// <param name="tileEdgeSide">The tile side the neighbour should have. Pass null if it doesn't matter.</param>
        /// <param name="setToTile">The tile at XY to set to if conditions are met.</param>
        public void PolishNeighbour(int x, int y, Tile.TileSide side, Tile.TileId tileType, Tile.TileId tileEdgeType, Tile setToTile)
        {
            if (this.GetTile(x, y).Id != tileType) return;

            switch (side)
            {
                case Tile.TileSide.BottomRight:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Bottom).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Right).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomRight).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.BottomLeft:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Bottom).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomLeft).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.TopRight:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Top).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Right).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopRight).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.TopLeft:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Top).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopLeft).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.Top:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Top).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.Bottom:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Bottom).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.Left:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.Right:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Right).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.UpperHalf:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopLeft).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Top).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopRight).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Right).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.LowerHalf:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomLeft).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Bottom).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomRight).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Right).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.LeftHalf:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Top).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopLeft).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomLeft).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Bottom).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.RightHalf:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Top).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopRight).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomRight).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Bottom).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
                case Tile.TileSide.All:
                    {
                        if (this.GetNeighbourTile(x, y, Tile.TileSide.Left).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopLeft).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Top).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.TopRight).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Right).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomRight).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.Bottom).Id == tileEdgeType
                            && this.GetNeighbourTile(x, y, Tile.TileSide.BottomLeft).Id == tileEdgeType)
                        {
                            Tiles[0][x, y] = setToTile;
                        }

                        break;
                    }
            }
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="x">The X coord.</param>
        /// <param name="y">The Y coord.</param>
        /// <param name="topLeft">Source rectangle for top left part of sprite.</param>
        /// <param name="topRight">Source rectangle for top right part of sprite.</param>
        /// <param name="bottomLeft">Source rectangle for bottom left part of sprite.</param>
        /// <param name="bottomRight">Source rectangle for bottom right part of sprite.</param>
        public void PolishInnerGrass(int x, int y, Rectangle topLeft, Rectangle topRight, Rectangle bottomLeft, Rectangle bottomRight)
        {
            if (this.GetTile(x, y) == null) return;
            if (this.GetTile(x, y).Id != Tile.TileId.Grass) return;

            Tile tTopLeft = this.GetNeighbourTile(x, y, Tile.TileSide.TopLeft);
            Tile tTopRight = this.GetNeighbourTile(x, y, Tile.TileSide.TopRight);
            Tile tBottomRight = this.GetNeighbourTile(x, y, Tile.TileSide.BottomRight);
            Tile tBottomLeft = this.GetNeighbourTile(x, y, Tile.TileSide.BottomLeft);

            if (this.GetTile(x, y).Side == Tile.TileSide.Middle)
            {
                if (tTopRight.Id != Tile.TileId.Grass && tTopRight != Tile.InvalidTile)
                {
                    Tiles[0][x, y] = new Tile(
                        Tile.TileId.Grass, Tile.Solidity.NonSolid, SourceRects.SandToGrassInnerTopRight, Color.White, Tile.TileSide.TopRight);
                }
                else if (tTopLeft.Id != Tile.TileId.Grass && tTopLeft != Tile.InvalidTile)
                {
                    Tiles[0][x, y] = new Tile(
                        Tile.TileId.Grass, Tile.Solidity.NonSolid, SourceRects.SandToGrassInnerTopLeft, Color.White, Tile.TileSide.TopLeft);
                }
                else if (tBottomRight.Id != Tile.TileId.Grass && tBottomRight != Tile.InvalidTile)
                {
                    Tiles[0][x, y] = new Tile(
                        Tile.TileId.Grass, Tile.Solidity.NonSolid, SourceRects.SandToGrassInnerBottomRight, Color.White, Tile.TileSide.BottomRight);
                }
                else if (tBottomLeft.Id != Tile.TileId.Grass && tBottomLeft != Tile.InvalidTile)
                {
                    Tiles[0][x, y] = new Tile(
                        Tile.TileId.Grass, Tile.Solidity.NonSolid, SourceRects.SandToGrassInnerBottomLeft, Color.White, Tile.TileSide.BottomLeft);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Smooths the terrain when these two tiles are next to eachother.
        /// </summary>
        /// <param name="x">The X coord.</param>
        /// <param name="y">The Y coord.</param>
        /// <param name="tileA">The first tile. This is the outcome of the new <c>Tile</c>.</param>
        /// <param name="tileB">The comparison tile. This is the tile that "surrounds" tileA.</param>
        /// <param name="top">Source rectangle for top part of sprite.</param>
        /// <param name="bottom">Source rectangle for bottom part of sprite.</param>
        /// <param name="left">Source rectangle for left part of sprite.</param>
        /// <param name="right">Source rectangle for right part of sprite.</param>
        /// <param name="topLeft">Source rectangle for top left part of sprite.</param>
        /// <param name="topRight">Source rectangle for top right part of sprite.</param>
        /// <param name="bottomLeft">Source rectangle for bottom left part of sprite.</param>
        /// <param name="bottomRight">Source rectangle for bottom right part of sprite.</param>
        /// <param name="upperHalf">Source rectangle for upper half of sprite. This is when tileA is surrounded by tileB on the upper half.</param>
        /// <param name="lowerHalf">Source rectangle for the lower half of sprite. This is when tileA is surrounded by tileB on the lower half.</param>
        /// <param name="circle">Source rectangle for one lonely tileA. This is when tileA is completely surrounded by tileB.</param>
        public void PolishEdgeCouple(int x, int y, Tile.TileId tileA, Tile.TileId tileB, Rectangle top, Rectangle bottom, Rectangle left, Rectangle right, Rectangle topLeft, Rectangle topRight, Rectangle bottomLeft, Rectangle bottomRight, Rectangle upperHalf, Rectangle lowerHalf, Rectangle circle)
        {
            if (Tiles[0][x, y] == null) return;

            #region Edges

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.Top,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, top, Color.White, Tile.TileSide.Top));

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.Bottom,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, bottom, Color.White, Tile.TileSide.Bottom));

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.Left,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, left, Color.White, Tile.TileSide.Left));

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.Right,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, right, Color.White, Tile.TileSide.Right));

            #endregion

            #region Corners

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.BottomRight,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, bottomRight, Color.White, Tile.TileSide.BottomRight));

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.BottomLeft,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, bottomLeft, Color.White, Tile.TileSide.BottomLeft));

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.TopRight,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, topRight, Color.White, Tile.TileSide.TopRight));

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.TopLeft,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, topLeft, Color.White, Tile.TileSide.TopLeft));

            #endregion

            #region One wide/long tile cases

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.UpperHalf,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, upperHalf, Color.White, Tile.TileSide.UpperHalf));

            PolishNeighbour(
                x,
                y,
                Tile.TileSide.LowerHalf,
                tileA,
                tileB,
                new Tile(tileA, Tile.Solidity.NonSolid, lowerHalf, Color.White, Tile.TileSide.LowerHalf));

            #endregion
        }
Example #6
0
        public Tile GetNeighbourTile(int x, int y, Tile.TileSide side)
        {
            var invalidTile = new Tile(Tile.TileId.Invalid, Tile.Solidity.NonSolid, Rectangle.Empty, Color.White, Tile.TileSide.InvalidSide);

            switch (side)
            {
                case Tile.TileSide.Top:
                    return y - 1 >= 0 ? Tiles[0][x, y - 1] : Tile.InvalidTile;
                case Tile.TileSide.Bottom:
                    return y + 1 < Height ? Tiles[0][x, y + 1] : Tile.InvalidTile;
                case Tile.TileSide.Left:
                    return x - 1 >= 0 ? Tiles[0][x - 1, y] : Tile.InvalidTile;
                case Tile.TileSide.Right:
                    return x + 1 < Width ? Tiles[0][x + 1, y] : Tile.InvalidTile;
                case Tile.TileSide.TopLeft:
                    return x - 1 >= 0 && y - 1 >= 0 ? Tiles[0][x - 1, y - 1] : Tile.InvalidTile;
                case Tile.TileSide.TopRight:
                    return x + 1 < Width && y - 1 >= 0 ? Tiles[0][x + 1, y - 1] : Tile.InvalidTile;
                case Tile.TileSide.BottomLeft:
                    return x - 1 >= 0 && y + 1 < Height ? Tiles[0][x - 1, y + 1] : Tile.InvalidTile;
                case Tile.TileSide.BottomRight:
                    return x + 1 < Width && y + 1 < Height ? Tiles[0][x + 1, y + 1] : Tile.InvalidTile;
                default:
                    return Tile.InvalidTile;
            }
        }
 /// <summary>
 /// Initializes a new instance of the PlayerTileEventArgs class.
 /// </summary>
 /// <param name="player">The player that invoked the event.</param>
 /// <param name="tile">The tile that contained the event.</param>
 /// <param name="containedPlayer">Whether or not the player was inside the tile's area.</param>
 public PlayerTileEventArgs(Player player, Tile tile, bool containedPlayer)
 {
     Player = player;
     Tile = tile;
     ContainedPlayer = containedPlayer;
 }