void CenterMap(int index)
    {
        var camPos = Camera.main.transform.position;
        var width  = Map.row; //May need to change to Map.row

        PositionUtil.CalcPosition(index, width, out tempX, out tempY);

        camPos.x = tempX * TileSize.x;
        camPos.y = -(tempY * TileSize.y);
        Camera.main.transform.position = camPos;
    }
Ejemplo n.º 2
0
    public void MoveInDir(Vector2 dir)
    {
        PositionUtil.CalcPosition(currentTile, map.row, out tempX, out tempY);

        tempX += (int)dir.x;
        tempY += (int)dir.y;

        PositionUtil.CalcIndex(tempX, tempY, map.row, out tempIndex);

        //Debug.Log("Moving to: " + tempIndex);
        MoveTo(tempIndex, true);
    }
    void VisitTile(int index)
    {
        int column, newX, newY, row = 0;

        PositionUtil.CalcPosition(index, Map.col, out tempX, out tempY);
        var half = Mathf.FloorToInt(viewDistance / 2f);

        tempX -= half;
        tempY -= half;

        var total  = viewDistance * viewDistance;
        var maxCol = viewDistance - 1;

        for (int i = 0; i < total; i++)
        {
            column = i % viewDistance;

            newX = column + tempX;
            newY = row + tempY;

            PositionUtil.CalcIndex(newX, newY, Map.col, out index);
            if (index > -1 && index < Map.mapTiles.Length)
            {
                var tile = Map.mapTiles[index];
                tile.visited = true;
                DecorateTile(index);

                foreach (var neighbor in tile.Neighbors)
                {
                    if (neighbor != null)
                    {
                        if (!neighbor.visited)
                        {
                            neighbor.CalcFOWAutoTileID();
                            DecorateTile(neighbor.TileID);
                        }
                    }
                }
            }

            if (column == maxCol)
            {
                row++;
            }
        }
    }
Ejemplo n.º 4
0
    public void MoveTo(int index, bool animate = false)
    {
        if (!CanMove(index))
        {
            return;
        }

        if (MoveActionCallback != null)
        {
            MoveActionCallback();
        }
        currentTile = index;

        PositionUtil.CalcPosition(index, map.row, out tempX, out tempY);

        tempX *= (int)tileSize.x;
        tempY *= -(int)tileSize.y;

        var newPos = new Vector3(tempX, tempY, 0);

        if (!animate)
        {
            transform.position = newPos;

            if (TileActionCallback != null)
            {
                TileActionCallback(map.mapTiles[currentTile].AutoTileID);
            }
        }
        else
        {
            startPos = transform.position;
            endPos   = newPos;
            dt       = 0;
            moving   = true;
        }
    }