示例#1
0
    public void MoveInDirection(Vector2 dir)
    {
        PosUtil.CalculatePos(currentTile, map.columns, out tmpX, out tmpY);

        tmpX += (int)dir.x;
        tmpY += (int)dir.x;
    }
    public void MoveTo(int index, bool animate = false)
    {
        if (!CanMove(index))
        {
            return;
        }

        currentTile = index;

        PosUtil.CalculatePos(index, map.columns, out tmpX, out tmpY);

        tmpX *= (int)tileSize.x;
        tmpY *= -(int)tileSize.y;

        var newPos = new Vector3(tmpX, tmpY, 0);

        if (!animate)
        {
            transform.position = newPos;
        }
        else
        {
            startPos = transform.position;
            endPos   = newPos;
            moveTime = 0;
            moving   = true;
        }
    }
示例#3
0
    public void MoveTo(int index)
    {
        PosUtil.CalculatePos(index, map.columns, out tmpX, out tmpY);

        tmpX *= (int)tileSize.x;
        tmpY *= -(int)tileSize.y;

        transform.position = new Vector3(tmpX, tmpY, 0);
    }
示例#4
0
    public void MoveInDirection(Vector2 dir)
    {
        PosUtil.CalculatePos(currentTile, map.columns, out tmpX, out tmpY);

        tmpX += (int)dir.x;
        tmpY += (int)dir.y;

        PosUtil.CalculateIndex(tmpX, tmpY, map.columns, out tmpIndex);
        MoveTo(tmpIndex, true);
    }
示例#5
0
    void CenterMap(int index)
    {
        var camPos = Camera.main.transform.position;
        var width  = map.columns;

        PosUtil.CalculatePos(index, width, out tmpX, out tmpY);

        camPos.x = tmpX * tileSize.x;
        camPos.y = -tmpY * tileSize.y;
        Camera.main.transform.position = camPos;
    }
    public void MoveInDirection(Vector2 dir)
    {
        PosUtil.CalculatePos(currentTile, map.columns, out tmpX, out tmpY);

        tmpX += (int)dir.x;
        tmpY += (int)dir.y;

        PosUtil.CalculateIndex(tmpX, tmpY, map.columns, out tmpIndex);

        Debug.Log("Move to tile " + tmpIndex);
    }
示例#7
0
    //when we visit a Tile we decorate it AndroidJNI also WebCamFlags redecorate the neighbor tiles
    //to have apropriate FogMode
    void VisitTile(int index)
    {
        int column, newX, newY, row = 0;

        //Calculate position of current tile
        PosUtil.CalculatePos(index, map.columns, out tmpX, out tmpY);

        //Half way of the field of view
        var half = Mathf.FloorToInt(viewDistance / 2f);

        //Shifiting the area that we are going to loop all that area
        tmpX -= half;
        tmpY -= half;

        //find total tile to visit
        var total = viewDistance * viewDistance;
        //Calculate the column
        var maxColumns = viewDistance - 1;

        for (int i = 0; i < total; i++)
        {
            //Find the index OperatingSystemFamily Tile int this Area
            column = i % viewDistance;
            newX   = column + tmpX;
            newY   = row + tmpY;
            PosUtil.CalculateIndex(newX, newY, map.columns, out index);

            if (index > -1 && index < map.tiles.Length)
            {
                var tile = map.tiles [index];
                tile.visited = true;

                DecorateTile(index);

                foreach (var neighbor in tile.neighbors)
                {
                    if (neighbor != null)
                    {
                        if (!neighbor.visited)
                        {
                            neighbor.CalculateFoWAutotileID();
                            DecorateTile(neighbor.id);
                        }
                    }
                }
            }
            if (column == maxColumns)
            {
                row++;
            }
        }
    }
示例#8
0
    public void CreatePlayer()
    {
        player      = Instantiate(playerPrefab);
        player.name = "Player";
        player.transform.SetParent(mapContainer.transform);

        PosUtil.CalculatePos(map.castleTile.id, map.columns, out tmpX, out tmpY);

        tmpX *= (int)tileSize.x;
        tmpY *= -(int)tileSize.y;

        player.transform.position = new Vector3(tmpX, tmpY, 0);
    }
    void VisitTile(int index)
    {
        int column, newX, newY, row = 0;

        PosUtil.CalculatePos(index, map.columns, out tmpX, out tmpY);

        var half = Mathf.FloorToInt(distance / 2f);

        tmpX -= half;
        tmpY -= half;

        var total      = distance * distance;
        var maxColumns = distance - 1;

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

            newX = column + tmpX;
            newY = row + tmpY;

            PosUtil.CalculateIndex(newX, newY, map.columns, out index);

            if (index > -1 && index < map.tiles.Length)
            {
                var tile = map.tiles[index];
                tile.visited = true;
                DecorateTile(index);

                foreach (var neighbor in tile.neighbors)
                {
                    if (neighbor != null)
                    {
                        if (!neighbor.visited)
                        {
                            neighbor.CalculateFoWAutotileID();
                            DecorateTile(neighbor.id);
                        }
                    }
                }
            }

            if (column == maxColumns)
            {
                row++;
            }
        }
    }
示例#10
0
    //centerize the Camera on any tile that we give it Touch the method
    void CenterMap(int index)
    {
        var camPos = Camera.main.transform.position;
        var width  = map.columns;



        PosUtil.CalculatePos(index, width, out tmpX, out tmpY);
        camPos.x = tmpX * tileSize.x;
        camPos.y = -tmpY * tileSize.y;

        //Before using position utility
        //camPos.x = (index % width) * tileSize.x;
        //camPos.y = -((index / width) * tileSize.y);

        Camera.main.transform.position = camPos;
    }
示例#11
0
    public void MoveTo(int index, bool animate = false)
    {
        if (!CanMove(index))
        {
            return;
        }

        if (moveActionCallback != null)
        {
            moveActionCallback();
        }

        currentTile = index;

        PosUtil.CalculatePos(index, map.columns, out tmpX, out tmpY);
        tmpX *= (int)tileSize.x;
        tmpY *= -(int)tileSize.y;

        var newPos = new Vector3(tmpX, tmpY, 0);

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

            if (tileActionCallback != null)
            {
                tileActionCallback(map.tiles[currentTile].autotileID);
            }
        }

        else
        {
            startPos = transform.position;
            endPos   = newPos;
            movetime = 0;
            moving   = true;
        }
    }