Ejemplo n.º 1
0
    public void init(worldScript _myWorldScript, int x, int y, int w, int h, int _i)
    {
        myWorldScript = _myWorldScript;
        posX          = x;
        posY          = y;
        width         = w;
        height        = h;
        tFactor       = 0f;
        id            = _i;

        currentTile = myWorldScript.getTileXY(posX, posY);

        myDirection   = getInitialDirection(currentTile, myDirection);
        prevDirection = myDirection;

        switch (myDirection)
        {
        case directions.NORTH:
            transform.Rotate(new Vector3(1, 0, 0), 90f);
            transform.localPosition = new Vector3(transform.localPosition.x + 0.5f, transform.localPosition.y, transform.localPosition.z);
            nextPos = new Vector3((posX - (width / 2)) * 2 + 0.5f, 1.5f, (((posY - 1) - (height / 2)) * -1) * 2);
            break;

        case directions.SOUTH:
            transform.Rotate(new Vector3(1, 0, 0), 270f);
            transform.localPosition = new Vector3(transform.localPosition.x - 0.5f, transform.localPosition.y, transform.localPosition.z);
            nextPos = new Vector3((posX - (width / 2)) * 2 - 0.5f, 1.5f, (((posY + 1) - (height / 2)) * -1) * 2);
            break;

        case directions.WEST:
            transform.Rotate(new Vector3(1, 0, 0), 0f);
            transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + 0.5f);
            nextPos = new Vector3(((posX - 1) - (width / 2)) * 2, 1.5f, ((posY - (height / 2)) * -1) * 2 + 0.5f);
            break;

        case directions.EAST:
            transform.Rotate(new Vector3(1, 0, 0), 180f);
            transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z - 0.5f);
            nextPos = new Vector3(((posX + 1) - (width / 2)) * 2, 1.5f, ((posY - (height / 2)) * -1) * 2 - 0.5f);
            break;
        }

        currentPos = transform.localPosition;
        prevPos    = currentPos;
    }
Ejemplo n.º 2
0
    void setNewDirection(directions currentDirection)
    {
        prevDirection = currentDirection;

        currentTile = myWorldScript.getTileXY(posX, posY);

        if (currentTile.whichType != tileTypes.NULL)
        {
            switch (currentDirection)
            {
            case directions.NORTH:
            case directions.SOUTH:
                if (Random.Range(0, 10) > 3)
                {
                }                                                                                                                                                               //70% chance of continuing the same direction
                else                                                                                                                                                            //turn left or right, or inverting the direction
                {
                    if ((myWorldScript.getTileXY(posX - 1, posY).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX + 1, posY).whichType == tileTypes.BUILDING)) //horizontal
                    {
                        if (Random.Range(0, 2) == 0)
                        {
                            myDirection = directions.EAST;
                        }
                        else
                        {
                            myDirection = directions.WEST;
                        }
                    }
                    else if ((myWorldScript.getTileXY(posX - 1, posY).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX + 1, posY).whichType != tileTypes.BUILDING))    //WEST
                    {
                        myDirection = directions.WEST;
                    }
                    else if ((myWorldScript.getTileXY(posX + 1, posY).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX - 1, posY).whichType != tileTypes.BUILDING))    //EAST
                    {
                        myDirection = directions.EAST;
                    }
                    else if ((currentDirection == directions.SOUTH) && (myWorldScript.getTileXY(posX, posY - 1).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX, posY + 1).whichType != tileTypes.BUILDING))
                    {
                        myDirection = directions.NORTH;
                    }
                    else if ((currentDirection == directions.NORTH) && (myWorldScript.getTileXY(posX, posY + 1).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX, posY - 1).whichType != tileTypes.BUILDING))
                    {
                        myDirection = directions.SOUTH;
                    }
                }
                break;

            case directions.WEST:
            case directions.EAST:
                if (Random.Range(0, 10) > 3)
                {
                }                                                                                                                                                               //70% chance of continuing the same direction
                else                                                                                                                                                            //turn up or down, or inverting the direction
                {
                    if ((myWorldScript.getTileXY(posX, posY - 1).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX, posY + 1).whichType == tileTypes.BUILDING)) //horizontal
                    {
                        if (Random.Range(0, 2) == 0)
                        {
                            myDirection = directions.NORTH;
                        }
                        else
                        {
                            myDirection = directions.SOUTH;
                        }
                    }
                    else if ((myWorldScript.getTileXY(posX, posY - 1).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX, posY + 1).whichType != tileTypes.BUILDING))
                    {
                        myDirection = directions.NORTH;
                    }
                    else if ((myWorldScript.getTileXY(posX, posY + 1).whichType == tileTypes.BUILDING) && (myWorldScript.getTileXY(posX, posY - 1).whichType != tileTypes.BUILDING))
                    {
                        myDirection = directions.SOUTH;
                    }
                }
                break;
            }

            switch (myDirection)
            {
            case directions.NORTH:
                currentTile = myWorldScript.getTileXY(posX, posY - 1);

                if ((currentTile.whichType == tileTypes.BUILDING) || ((currentTile.whichType == tileTypes.ROAD) && (currentTile.whichRoadType == roadTypes.CROSS_HORIZONTAL)))
                {
                    posY--;
                    nextPos = new Vector3((posX - (width / 2)) * 2 + 0.5f, 1.5f, ((posY - (height / 2)) * -1) * 2);
                }
                else
                {
                    myDirection = directions.SOUTH;
                }
                break;

            case directions.SOUTH:
                currentTile = myWorldScript.getTileXY(posX, posY + 1);

                if ((currentTile.whichType == tileTypes.BUILDING) || ((currentTile.whichType == tileTypes.ROAD) && (currentTile.whichRoadType == roadTypes.CROSS_HORIZONTAL)))
                {
                    posY++;
                    nextPos = new Vector3((posX - (width / 2)) * 2 - 0.5f, 1.5f, ((posY - (height / 2)) * -1) * 2);
                }
                else
                {
                    myDirection = directions.NORTH;
                }
                break;

            case directions.WEST:
                currentTile = myWorldScript.getTileXY(posX - 1, posY);

                if ((currentTile.whichType == tileTypes.BUILDING) || ((currentTile.whichType == tileTypes.ROAD) && (currentTile.whichRoadType == roadTypes.CROSS_VERTICAL)))
                {
                    posX--;
                    nextPos = new Vector3((posX - (width / 2)) * 2, 1.5f, ((posY - (height / 2)) * -1) * 2 + 0.5f);
                }
                else
                {
                    myDirection = directions.EAST;
                }
                break;

            case directions.EAST:
                currentTile = myWorldScript.getTileXY(posX + 1, posY);

                if ((currentTile.whichType == tileTypes.BUILDING) || ((currentTile.whichType == tileTypes.ROAD) && (currentTile.whichRoadType == roadTypes.CROSS_VERTICAL)))
                {
                    posX++;
                    nextPos = new Vector3((posX - (width / 2)) * 2, 1.5f, ((posY - (height / 2)) * -1) * 2 - 0.5f);
                }
                else
                {
                    myDirection = directions.WEST;
                }
                break;
            }
        }

        currentPos = transform.localPosition;

        randomSpeed = Random.Range(-0.015f, +0.015f);
    }
Ejemplo n.º 3
0
    void setNewDirection(directions currentDirection)
    {
        prevDirection = currentDirection;

        currentTile = myWorldScript.getTileXY(posX, posY);

        if (currentTile.whichType != tileTypes.NULL)
        {
            switch (currentDirection)
            {
            case directions.NORTH:
            case directions.SOUTH:
                if (Random.Range(0, 10) > 3)
                {
                }                                                                                   //70% chance of continuing the same direction
                else                                                                                //turn left or right, or inverting the direction
                {
                    if ((currentTile.neighborgs[2] == true) && (currentTile.neighborgs[3] == true)) //horizontal
                    {
                        if (Random.Range(0, 2) == 0)
                        {
                            myDirection = directions.EAST;
                        }
                        else
                        {
                            myDirection = directions.WEST;
                        }
                    }
                    else if ((currentTile.neighborgs[2] == true) && (currentTile.neighborgs[3] == false))    //WEST
                    {
                        myDirection = directions.WEST;
                    }
                    else if ((currentTile.neighborgs[2] == false) && (currentTile.neighborgs[3] == true))    //EAST
                    {
                        myDirection = directions.EAST;
                    }
                    else if ((currentDirection == directions.SOUTH) && (currentTile.neighborgs[0] == true) && (currentTile.neighborgs[1] == false))
                    {
                        myDirection = directions.NORTH;
                    }
                    else if ((currentDirection == directions.NORTH) && (currentTile.neighborgs[0] == false) && (currentTile.neighborgs[1] == true))
                    {
                        myDirection = directions.SOUTH;
                    }
                }
                break;

            case directions.WEST:
            case directions.EAST:
                if (Random.Range(0, 10) > 3)
                {
                }                                                                                   //70% chance of continuing the same direction
                else                                                                                //turn up or down, or inverting the direction
                {
                    if ((currentTile.neighborgs[0] == true) && (currentTile.neighborgs[1] == true)) //vertical
                    {
                        if (Random.Range(0, 2) == 0)
                        {
                            myDirection = directions.NORTH;
                        }
                        else
                        {
                            myDirection = directions.SOUTH;
                        }
                    }
                    else if ((currentTile.neighborgs[0] == true) && (currentTile.neighborgs[1] == false))    //north
                    {
                        myDirection = directions.NORTH;
                    }
                    else if ((currentTile.neighborgs[0] == false) && (currentTile.neighborgs[1] == true))    //south
                    {
                        myDirection = directions.SOUTH;
                    }
                }
                break;
            }

            switch (myDirection)
            {
            case directions.NORTH:
                currentTile = myWorldScript.getTileXY(posX, posY - 1);
                if (prevDirection != directions.NORTH)
                {
                    if (prevDirection == directions.WEST)
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f * 3f);
                    }
                    else
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f);
                    }
                }

                if ((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[0] == true))
                {
                    posY--;
                    nextPos = new Vector3((posX - (width / 2)) * 2 + 0.5f, 1.5f, ((posY - (height / 2)) * -1) * 2);
                }
                else if ((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[0] == false))    //////////////////////
                {
                    transform.Rotate(new Vector3(1, 0, 0), 180f);
                    myDirection = directions.SOUTH;
                }
                break;

            case directions.SOUTH:
                currentTile = myWorldScript.getTileXY(posX, posY + 1);
                if (prevDirection != directions.SOUTH)
                {
                    if (prevDirection == directions.WEST)
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f);
                    }
                    else
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f * 3f);
                    }
                }

                if ((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[1] == true))
                {
                    posY++;
                    nextPos = new Vector3((posX - (width / 2)) * 2 - 0.5f, 1.5f, ((posY - (height / 2)) * -1) * 2);
                }
                else if ((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[1] == false))    //////////////////////
                {
                    transform.Rotate(new Vector3(1, 0, 0), 180f);
                    myDirection = directions.NORTH;
                }
                break;

            case directions.WEST:
                currentTile = myWorldScript.getTileXY(posX - 1, posY);
                if (prevDirection != directions.WEST)
                {
                    if (prevDirection == directions.NORTH)
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f * 3f);
                    }
                    else
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f);
                    }
                }

                if ((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[3] == true))
                {
                    posX--;
                    nextPos = new Vector3((posX - (width / 2)) * 2, 1.5f, ((posY - (height / 2)) * -1) * 2 + 0.5f);
                }
                else if (((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[2] == false)) || (currentTile.whichType != tileTypes.BUILDING))
                {
                    transform.Rotate(new Vector3(1, 0, 0), 180f);
                    myDirection = directions.EAST;
                }
                break;

            case directions.EAST:
                currentTile = myWorldScript.getTileXY(posX + 1, posY);
                if (prevDirection != directions.EAST)
                {
                    if (prevDirection == directions.NORTH)
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f);
                    }
                    else
                    {
                        transform.Rotate(new Vector3(1, 0, 0), 90f * 3f);
                    }
                }

                if ((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[2] == true))
                {
                    posX++;
                    nextPos = new Vector3((posX - (width / 2)) * 2, 1.5f, ((posY - (height / 2)) * -1) * 2 - 0.5f);
                }
                else if (((currentTile.whichType != tileTypes.NULL) && (currentTile.neighborgs[3] == false)) || (currentTile.whichType != tileTypes.BUILDING))
                {
                    transform.Rotate(new Vector3(1, 0, 0), 180f);
                    myDirection = directions.WEST;
                }
                break;
            }
        }

        currentPos = transform.localPosition;
    }