示例#1
0
 void OnTriggerEnter(Collider col)
 {
     if (Input.GetMouseButton(0))
     {
         enterEdge = GetEdge(Input.mousePosition);
     }
 }
        private static List <TileEdge> _ConvertChordlessPolygonToPolyEdges(ImmutableArray <Vector2> outerPerim, Dictionary <PolyEdge, TileEdge> polyToTileMap)
        {
            var outerEdges = new List <TileEdge>();

            for (int i = 0; i < outerPerim.Length - 1; i++)
            {
                Vector2 thisVertex = outerPerim[i];
                Vector2 nextVertex = outerPerim[i + 1];
                foreach (PolyEdge polyEdge in polyToTileMap.Keys)
                {
                    if (polyEdge.a == thisVertex && polyEdge.b == nextVertex ||
                        polyEdge.b == thisVertex && polyEdge.a == nextVertex)
                    {
                        TileEdge tileEdge = polyToTileMap[polyEdge];
                        if (polyEdge.a == thisVertex)
                        {
                            outerEdges.Add(tileEdge);
                        }
                        else
                        {
                            var reverseEdge = tileEdge.GetReverseEdge() as TileEdge;
                            outerEdges.Add(reverseEdge);
                        }
                    }
                }
            }
            return(outerEdges);
        }
        /// <summary>
        /// Converts an outer perimeter represented by PolygonSplittingGraphNodes to a list of PolyEdges in the same order.
        /// </summary>
        /// <param name="outerNodes">List of PolygonSplittingGraphNodes in order forming an outer perimeter.</param>
        /// <param name="polyToTileMap">A Dictionary mapping PolyEdges to their respective TileEdges.</param>
        /// <returns>List of PolyEdges forming the same outer perimeter described by <param>outerNodes</param>.</returns>
        private static List <TileEdge> _ConvertPolygonNodesToPolyEdges(List <PolygonSplittingGraphNode> outerNodes, Dictionary <PolyEdge, TileEdge> polyToTileMap)
        {
            var outerEdges = new List <TileEdge>();

            for (int i = 0; i < outerNodes.Count - 1; i++)
            {
                var thisVertex = new Vector2(outerNodes[i].x, outerNodes[i].y);
                var nextVertex = new Vector2(outerNodes[i + 1].x, outerNodes[i + 1].y);
                foreach (PolyEdge polyEdge in polyToTileMap.Keys)
                {
                    if (polyEdge.a == thisVertex && polyEdge.b == nextVertex ||
                        polyEdge.b == thisVertex && polyEdge.a == nextVertex)
                    {
                        TileEdge tileEdge = polyToTileMap[polyEdge];
                        if (polyEdge.a == thisVertex)
                        {
                            outerEdges.Add(tileEdge);
                        }
                        else
                        {
                            var reverseEdge = tileEdge.GetReverseEdge() as TileEdge;
                            outerEdges.Add(reverseEdge);
                        }
                    }
                }
            }
            return(outerEdges);
        }
示例#4
0
 void SetTileEdges(Sprite sprite)
 {
     for (int edgeIndex = 0; edgeIndex < (int)ETileEdge.COUNT; ++edgeIndex)
     {
         edge[edgeIndex] = new TileEdge(sprite, (ETileEdge)edgeIndex, tileFlags);
     }
 }
    private void computeOxyLevel()
    {
        int   deriver = 1;
        float value   = o2Level;

        if (TileEdge.IsPassable(down) && downNeighbour != null && TileEdge.IsPassable(downNeighbour.up))
        {
            deriver++;
            value += downNeighbour.o2Level;
        }
        if (TileEdge.IsPassable(up) && upNeighbour != null && TileEdge.IsPassable(upNeighbour.down))
        {
            deriver++;
            value += upNeighbour.o2Level;
        }
        if (TileEdge.IsPassable(left) && leftNeighbour != null && TileEdge.IsPassable(leftNeighbour.right))
        {
            deriver++;
            value += leftNeighbour.o2Level;
        }
        if (TileEdge.IsPassable(right) && rightNeighbour != null && TileEdge.IsPassable(rightNeighbour.left))
        {
            deriver++;
            value += rightNeighbour.o2Level;
        }
        o2Level = value / deriver;
    }
示例#6
0
        /// <summary>Draw a tile border.</summary>
        /// <param name="spriteBatch">The sprite batch to which to draw.</param>
        /// <param name="origin">The top-left pixel position of the tile relative to the screen.</param>
        /// <param name="edge">The tile edge to draw.</param>
        /// <param name="color">The border color.</param>
        /// <param name="width">The border width.</param>
        /// <returns>Returns whether a border was drawn. This may return false if the width is zero, or the edge is invalid.</returns>
        private bool DrawBorder(SpriteBatch spriteBatch, Vector2 origin, TileEdge edge, Color color, int width)
        {
            if (width <= 0)
            {
                return(false);
            }

            switch (edge)
            {
            case TileEdge.Left:
                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)origin.X, (int)origin.Y, width, Game1.tileSize), color);
                return(true);

            case TileEdge.Right:
                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)(origin.X + Game1.tileSize - width), (int)origin.Y, width, Game1.tileSize), color);
                return(true);

            case TileEdge.Top:
                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)origin.X, (int)origin.Y, Game1.tileSize, width), color);
                return(true);

            case TileEdge.Bottom:
                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)origin.X, (int)(origin.Y + Game1.tileSize - width), Game1.tileSize, width), color);
                return(true);
            }

            return(false);
        }
示例#7
0
        /// <summary>
        /// Checks if a ledge would be valid if superimposed to a higher tilemap by checking if said higher
        /// tilemap contains a tile either:
        ///     1. Above (on the superimposed tile map) the tile that the ledge originated from (on base tilemap)
        ///     2. Above and adjacent (on superimposed tilemap) the tile that the ledge originated from IN THE
        ///        DIRECTION that the ledge is in.
        /// </summary>
        /// <param name="ledge">Ledge being checked for validity.</param>
        /// <param name="baseTileMap">TileMap that the ledge is on.</param>
        /// <param name="superTileMap">TileMap that ledge would be superimposed to if valid.</param>
        /// <returns>True is valid, false otherwise.</returns>
        private static bool _IsLedgeValid(TileEdge ledge, TileMap baseTileMap, TileMap superTileMap)
        {
            Vector2 aboveTile    = TileFuncs.GetTileAboveOrBelow(ledge.tileCoords, baseTileMap.ZIndex, superTileMap.ZIndex);
            Vector2 adjAboveTile = TileFuncs.GetTileAdjacent(aboveTile, ledge.tileSide);

            return(superTileMap.GetCellv(aboveTile) == TileMap.InvalidCell &&
                   superTileMap.GetCellv(adjAboveTile) == TileMap.InvalidCell);
        }
示例#8
0
 public void SetEdge(int Index, TileEdge Edge)
 {
     Configuration.SetEdge(Index, Edge);
     if (NeighborTiles[Index] != null && NeighborTiles[Index].Configuration.GetEdge((Index + 3) % 6) != Edge)
     {
         NeighborTiles[Index].SetEdge((Index + 3) % 6, Edge);
     }
 }
示例#9
0
    public GameObject GetEdge(TileEdge edge)
    {
        if (edge == TileEdge.Count) {
            throw new ArgumentException("Invalid Tile Edge", "edge");
        }

        return _edges[(int)edge];
    }
 public RobotPosition Rotate(TileEdge heading)
 {
     if (heading.tile != tile)
     {
         Debug.LogError(string.Format("Trying to rotate while on other tile {0}:{1} but on {2}", heading, heading.tile, tile));
         return(this);
     }
     return(new RobotPosition(tile, heading));
 }
示例#11
0
        /// <summary>
        /// Given some input edge, grabs the tile it originated from and attempts to calculate coordinates
        /// for some adjacent tile on the observed layer (which should be lower than the current layer).
        /// </summary>
        /// <param name="edge">Edge that is checked for what tile it originated from.</param>
        /// <param name="currentLayer">Layer of edge.</param>
        /// <param name="observedLayer">Layer of the tile that this func calcs coords for.</param>
        /// <returns>Coordinates of some adjacent tile on the observed layer, even if it does not exist.</returns>
        private static Vector2 _GetAdjLowerCoords(TileEdge edge, int currentLayer, int observedLayer)
        {
            Vector2 currentTile = edge.tileCoords;
            int     side        = edge.tileSide;

            Vector2 belowTile    = TileFuncs.GetTileAboveOrBelow(currentTile, currentLayer, observedLayer);
            Vector2 adjBelowTile = TileFuncs.GetTileAdjacent(belowTile, side);

            return(adjBelowTile);
        }
示例#12
0
 protected override void Initialize()
 {
     // refactor
     viewState    = GameObject.Find("GameController").GetComponent <ViewStateController>();
     tileCollider = GetComponent <BoxCollider>();
     boundsCenter = tileCollider.bounds.center;
     boundsMin    = tileCollider.bounds.min;
     boundsMax    = tileCollider.bounds.max;
     enterEdge    = exitEdge = TileEdge.None;
 }
示例#13
0
        Color EdgeColor(TileEdge Edge, bool Higher, int Elevation)
        {
            Color c = _EdgeColors[(int)Edge];

            if (c.A > 0)
            {
                return(c);
            }
            return(Higher ? _ElevationColors[Math.Min(_ElevationColors.Length - 1, Math.Max(0, Elevation))] : c);
        }
示例#14
0
    public override bool Equals(object obj)
    {
        TileEdge otherTE = obj as TileEdge;

        if (otherTE == null)
        {
            return(false);
        }

        return(this.tile.Equals(otherTE.tile));
    }
示例#15
0
文件: Tile.cs 项目: addonovan/viciv
    /// <summary>
    /// Sets this cell's neighbor in the given direction to the given tile.
    /// Also reciprocates and sets the opposite neighbor of the given tile
    /// to this tile.
    /// </summary>
    /// <param name="direction">The direction `tile` is in.</param>
    /// <param name="tile">The new neighbor! Howdy!</param>
    public void SetNeighbor(TileEdge direction, Tile tile)
    {
        neighbors[( int )direction] = tile;

        // avoid NRE
        if (tile == null)
        {
            return;
        }

        tile.neighbors[( int )direction.Opposite()] = this;    // update it for that tile as well
    }
 public TileEdge Forward(TileEdge entry)
 {
     for (int i = 0; i < entries.Length; i++)
     {
         if (entries[i] == entry)
         {
             return(exits[i]);
         }
     }
     Debug.LogError(string.Format("Looking for Forward from {0}:{1} on {2}", entry.name, entry.tile.name, name));
     throw new MissingComponentException();
 }
 public TileEdge Right(TileEdge heading, int steps = 1)
 {
     for (int i = 0; i < exits.Length; i++)
     {
         if (exits[i] == heading)
         {
             return(exits[i + steps >= exits.Length ? i + steps - exits.Length : i + steps]);
         }
     }
     Debug.LogError(string.Format("Looking for Right from {0}:{1} on {2}", heading.name, heading.tile.name, name));
     throw new MissingComponentException();
 }
示例#18
0
 /// <summary>
 /// Checks if the input collection contains the edge. Required because the Edge class is more than just Points A and B (it also
 /// includes the tile it originated from and tile side) but we only care about those two properties.
 /// </summary>
 /// <param name="collection">Collection being checked for whether it contains Edge (but just the points).</param>
 /// <param name="edge">Edge being checked.</param>
 /// <returns>Index of identical edge in collection with matching points to the input edge, or -1 if no match found.</returns>
 private static int _ContainsEdge(IReadOnlyList <TileEdge> collection, TileEdge edge)
 {
     for (int i = 0; i < collection.Count; i++)
     {
         TileEdge examinee = collection[i];
         if (examinee.IsIdentical(edge))
         {
             return(i);
         }
     }
     return(-1);
 }
    public TileEffect Bump(TileEdge fromDirection, bool flameBurning)
    {
        if (flameBurning)
        {
            var tileFire = GetComponentInChildren <TileFire>();
            if (tileFire)
            {
                tileFire.StartFire();
                tileEffect = TileEffect.Burning;
            }
        }

        return(TileEffect);
    }
示例#20
0
        /// <summary>
        /// Given some input EdgeCollection, iterates through its edges and adds 'valid' ones to a new
        /// collection, which is then returned.
        /// Validity is determined through the _IsLedgeValid function.
        /// </summary>
        /// <param name="ledgeColl"></param>
        /// <param name="preTileMap"></param>
        /// <param name="superTileMap"></param>
        /// <returns></returns>
        private static EdgeCollection <TileEdge> _BuildHoleGroupValidLedges(EdgeCollection <TileEdge> ledgeColl, TileMap preTileMap, TileMap superTileMap)
        {
            var validLedges = new EdgeCollection <TileEdge>();

            foreach (TileEdge ledge in ledgeColl)
            {
                if (_IsLedgeValid(ledge, preTileMap, superTileMap))
                {
                    TileEdge superimposedLedge = ledge.GetShiftedByN(SHIFT_DIST);
                    if (!validLedges.HasEdgePoints(superimposedLedge))
                    {
                        validLedges.Add(superimposedLedge);
                    }
                }
            }
            return(validLedges);
        }
示例#21
0
    public void addNeighbor(Tile start, Tile end, float edgeCost)
    {
        if (!outgoingEdges.ContainsKey(start))
        {
            outgoingEdges.Add(start, new HashSet <TileEdge>());
        }
        // Add a new edge from start pointing towards end
        TileEdge newOutEdge = new TileEdge(end, Mathf.RoundToInt(edgeCost));

        outgoingEdges[start].Add(newOutEdge);

        if (!incomingTiles.ContainsKey(end))
        {
            incomingTiles.Add(end, new HashSet <Tile>());
        }
        // End now has an incoming edge from start
        incomingTiles[end].Add(start);
    }
示例#22
0
        /// <summary>
        /// From some input edge, grab the tile it originated from and check if there is an adjacent tile
        /// in the direction TO the edge on any lower TileMap.
        /// Basically we are checking if it is possible to move from the original tile in the direction
        /// of the edge and fall to a lower tile.
        /// Should no adjacent tile exist, returns the current tile.
        /// </summary>
        /// <param name="tileMaps">List of all tilemaps.</param>
        /// <param name="edge">Edge that is being examined.</param>
        /// <param name="currentLayer">Current layer that edge is on.</param>
        /// <returns>Coords of the highest adjacent tile, or current tile if no adjacent tile exists.</returns>
        private static Vector2 _GetAdjacentLowerTile(TileMapList tileMaps, TileEdge edge, int currentLayer)
        {
            Vector2 currentTile = edge.tileCoords;
            Vector2 adjTile     = currentTile;

            for (int i = currentLayer; i >= 0; i--)
            {
                Vector2 adjCoords    = _GetAdjLowerCoords(edge, currentLayer, i);
                TileMap lowerTileMap = tileMaps[i];

                if (adjCoords != currentTile && lowerTileMap.GetCellv(adjCoords) != TileMap.InvalidCell)
                {
                    adjTile = adjCoords;
                    break; //no need to continue searching we have the highest adj tile
                }
            }
            return(adjTile);
        }
    public static bool IsPassable(TileEdge edge)
    {
        if (edge == null)
        {
            return(true);
        }

        if (edge.isBroken)
        {
            return(true);
        }

        if (edge is Door && (edge as Door).isOpened)
        {
            return(true);
        }

        return(false);
    }
示例#24
0
    /// <summary>
    /// Tessellates a single part of the hexagonal outline with the given position, color, and thickness.
    /// </summary>
    /// <param name="center"></param>
    /// <param name="outerRadius"></param>
    /// <param name="thickness"></param>
    /// <param name="direction"></param>
    /// <param name="color"></param>
    public void Tessellate2D(Vector3 center, float outerRadius, float thickness, TileEdge direction, Color color)
    {
        float innerRadius = outerRadius - thickness;

        int i = ( int )direction;

        AddTriangle(
            center + (UNIT_HEXAGON[i] * innerRadius),
            center + (UNIT_HEXAGON[i] * outerRadius),
            center + (UNIT_HEXAGON[i + 1] * innerRadius)
            );
        AddTriangleColor(color);

        AddTriangle(
            center + (UNIT_HEXAGON[i] * outerRadius),
            center + (UNIT_HEXAGON[i + 1] * outerRadius),
            center + (UNIT_HEXAGON[i + 1] * innerRadius)
            );
        AddTriangleColor(color);
    }
示例#25
0
    /// <summary>
    /// This pass will create mountain ranges.
    /// </summary>
    /// <param name="tiles">The tiles.</param>
    private static void CreateMountains(Tile[] tiles, int landmass)
    {
        int mountainRanges = random.Next(1, 5) * random.Next(1, (landmass / 50) + 2);

        int range = ( int )(2 * Mathf.Sqrt(landmass / mountainRanges));

        for (int i = 0; i < mountainRanges; i++)
        {
            // find a random land tile by guessing
            Tile start;
            do
            {
                start = tiles[random.Next(0, tiles.Length)];     // choose a random tile
            }while (!start.type.isLand);

            // choose a random direction
            TileEdge direction = ( TileEdge )random.Next(0, 5);

            int size = CreateMountainRangeAt(start, range, direction);
        }
    }
    void GenerateVoidScent()
    {
        Queue <Tile>   queue        = new Queue <Tile> ();
        HashSet <Tile> visitedTiles = new HashSet <Tile> ();

        foreach (Tile tile in tiles)
        {
            if (tile.isVoidGenerator)
            {
                queue.Enqueue(tile);
            }
            tile.voidScent = false;
        }
        while (queue.Count > 0)
        {
            Tile tile = queue.Dequeue();
            tile.voidScent = true;
            visitedTiles.Add(tile);
            if (tile.upNeighbour && !visitedTiles.Contains(tile.upNeighbour) && TileEdge.IsPassable(tile.up) && TileEdge.IsPassable(tile.upNeighbour.down))
            {
                tile.upNeighbour.voidScent = true;
                queue.Enqueue(tile.upNeighbour);
            }
            if (tile.downNeighbour && !visitedTiles.Contains(tile.downNeighbour) && TileEdge.IsPassable(tile.down) && TileEdge.IsPassable(tile.downNeighbour.up))
            {
                tile.downNeighbour.voidScent = true;
                queue.Enqueue(tile.downNeighbour);
            }
            if (tile.leftNeighbour && !visitedTiles.Contains(tile.leftNeighbour) && TileEdge.IsPassable(tile.left) && TileEdge.IsPassable(tile.leftNeighbour.right))
            {
                tile.leftNeighbour.voidScent = true;
                queue.Enqueue(tile.leftNeighbour);
            }
            if (tile.rightNeighbour && !visitedTiles.Contains(tile.rightNeighbour) && TileEdge.IsPassable(tile.right) && TileEdge.IsPassable(tile.rightNeighbour.left))
            {
                tile.rightNeighbour.voidScent = true;
                queue.Enqueue(tile.rightNeighbour);
            }
        }
    }
    void Propagate()
    {
        int firesStarted   = 0;
        int contagiousness = Config.me.FireContagiousness;

        if (tile.system != null)
        {
            tile.system.GetComponent <TileSystem>().isBroken = true;
        }

        if (firesStarted < contagiousness && tile.downNeighbour != null && (TileEdge.IsPassable(tile.down)) && TileEdge.IsPassable(tile.downNeighbour.up))
        {
            if (tile.downNeighbour.StartFire())
            {
                firesStarted++;
            }
        }
        if (firesStarted < contagiousness && tile.upNeighbour != null && TileEdge.IsPassable(tile.up) && TileEdge.IsPassable(tile.upNeighbour.down))
        {
            if (tile.upNeighbour.StartFire())
            {
                firesStarted++;
            }
        }
        if (firesStarted < contagiousness && tile.leftNeighbour != null && TileEdge.IsPassable(tile.left) && TileEdge.IsPassable(tile.leftNeighbour.right))
        {
            if (tile.leftNeighbour.StartFire())
            {
                firesStarted++;
            }
        }
        if (firesStarted < contagiousness && tile.rightNeighbour != null && TileEdge.IsPassable(tile.right) && TileEdge.IsPassable(tile.rightNeighbour.left))
        {
            if (tile.rightNeighbour.StartFire())
            {
                firesStarted++;
            }
        }
        level = 0;
    }
示例#28
0
文件: Tile.cs 项目: StaphiX/TileMap
    public List <TileEdge> GetTileNeighborEdges()
    {
        List <TileEdge> tileEdges = new List <TileEdge>();

        for (int tileEdge = 0; tileEdge < (int)ETileEdge.COUNT; ++tileEdge)
        {
            ETileEdge eTileEdge     = (ETileEdge)tileEdge;
            ETileEdge eOppositeEdge = eTileEdge.Opposite();

            Tile neighbor = GetNeighbor(eTileEdge);
            if (neighbor != null)
            {
                TileEdge neighborEdge = neighbor.GetTileEdge(eOppositeEdge);
                if (neighborEdge != null)
                {
                    tileEdges.Add(neighborEdge);
                }
            }
        }

        return(tileEdges);
    }
示例#29
0
    /// <summary>
    /// Creates a mountain range starting at the given type and spreading out the
    /// given range.
    /// </summary>
    /// <param name="tile"></param>
    /// <param name="range"></param>
    /// <returns></returns>
    private static int CreateMountainRangeAt(Tile tile, int range, TileEdge direction)
    {
        // if the tile doesn't exist, isn't land, or already is a mountain, end the chain
        if (tile == null || !tile.type.isLand || tile.type == TileType.MOUNTAIN)
        {
            return(0);
        }

        // set the type to mountains
        tile.type = TileType.MOUNTAIN;

        int sum = 1;

        if (range >= random.Next(0, 5))
        {
            // expand in the given direction
            CreateMountainRangeAt(tile.GetNeighbor(direction), range - random.Next(0, 5), direction);

            // expand backwards too
            CreateMountainRangeAt(tile.GetNeighbor(direction.Opposite()), range - random.Next(0, 5), direction);

            // create mountains in the given directions
            for (int i = 0; i < 6; i++)
            {
                // expand mostly in the given direction and the opposite direction
                if (i == ( int )direction || i == ( int )direction.Opposite())
                {
                    CreateMountainRangeAt(tile.GetNeighbor(( TileEdge )i), range - random.Next(0, 5), direction);
                }
                // 70% chance that it will branch off in another direction, but will suffer massive hits to the range
                else if (random.Next(1, 10) <= 7)
                {
                    CreateMountainRangeAt(tile.GetNeighbor(( TileEdge )i), range - random.Next(5, 15), direction);
                }
            }
        }

        return(sum);
    }
示例#30
0
    Boolean checkIfCanMove(InGamePosition pos, bool up, bool down, bool left, bool right)
    {
        Ship ship = GameObject.FindGameObjectWithTag("ship").GetComponent <Ship>();
        Tile tile = ship.GetTileOnPosition(pos);

        if (left &&
            TileEdge.IsPassable(tile.down) &&
            tile.downNeighbour != null &&
            TileEdge.IsPassable(tile.downNeighbour.up))
        {
            return(true);
        }

        if (right &&
            TileEdge.IsPassable(tile.up) &&
            tile.upNeighbour != null &&
            TileEdge.IsPassable(tile.upNeighbour.down))
        {
            return(true);
        }

        if (down &&
            TileEdge.IsPassable(tile.left) &&
            tile.leftNeighbour != null &&
            TileEdge.IsPassable(tile.leftNeighbour.right))
        {
            return(true);
        }

        if (up &&
            TileEdge.IsPassable(tile.right) &&
            tile.rightNeighbour != null &&
            TileEdge.IsPassable(tile.rightNeighbour.left))
        {
            return(true);
        }

        return(false);
    }
 public TileEdge Backward(TileEdge heading)
 {
     return(Forward(heading));
 }
示例#32
0
 public EdgeRotation(TileEdge edge, Quaternion rotation)
 {
     Edge = edge;
     Rotation = rotation;
 }
示例#33
0
    public void SetEdge(TileEdge edge, GameObject prefab)
    {
        if (edge == TileEdge.Count) {
            throw new ArgumentException("Invalid Tile Edge", "edge");
        }

        _edges[(int)edge] = prefab;
    }