Пример #1
0
    public Vector3 FlowDirectionToVector(CellFlowDirection direction)
    {
        if (direction == CellFlowDirection.Up)
            return new Vector3(0, 1);
        if (direction == CellFlowDirection.Down)
            return new Vector3(0, -1);
        if (direction == CellFlowDirection.Left)
            return new Vector3(-1, 0);
        if (direction == CellFlowDirection.Right)
            return new Vector3(1, 0);

        return Vector3.zero;
    }
Пример #2
0
 public Cell getCellNeighbour(int x, int y, CellFlowDirection direction)
 {
     Vector3 dirVec = FlowDirectionToVector(direction);
     if (isInBounds(new Vector2(x + (int)dirVec.x, y + (int)dirVec.y)))
         return getCell(x + (int)dirVec.x, y + (int)dirVec.y);
     return null;
 }
Пример #3
0
    public void UpdateMovement()
    {
        float dt = Time.deltaTime;
        movement.cursor += dt * movement.speed;
        movement.jitterPhase += dt / movement.jitterPeriod * Mathf.PI;

        if (movement.cursor >= 1)
        {
            movement.cursor = 1;

            int x = (int)movement.nextCell.x;
            int y = (int)movement.nextCell.y;
            Cell nextCell = worldGrid.getCell(x, y);

            //Move in a random direction
            CellFlowDirection[] dirs = new CellFlowDirection[] { };
            int random = UnityEngine.Random.Range(0, 4);
            if (random == 0)
                dirs = new CellFlowDirection[] { CellFlowDirection.Up, CellFlowDirection.Right, CellFlowDirection.Down, CellFlowDirection.Left };
            if (random == 1)
                dirs = new CellFlowDirection[] { CellFlowDirection.Left, CellFlowDirection.Down, CellFlowDirection.Up, CellFlowDirection.Right };
            if (random == 2)
                dirs = new CellFlowDirection[] { CellFlowDirection.Down, CellFlowDirection.Left, CellFlowDirection.Right, CellFlowDirection.Up };
            if (random == 3)
                dirs = new CellFlowDirection[] { CellFlowDirection.Right, CellFlowDirection.Up, CellFlowDirection.Left, CellFlowDirection.Down };

            for (int i = 0; i < 4; i++)
            {
                CellFlowDirection direction = dirs[i];
                if ((nextCell.flow & direction) == direction)
                {
                    Vector3 dirVec = worldGrid.FlowDirectionToVector(direction);
                    movement.cursor = 0;
                    movement.curCell = movement.nextCell;
                    movement.nextCell = new Vector2(x + dirVec.x, y + dirVec.y);

                    OnChangeCell(nextCell, x, y);
                    break;
                }
            }
        }
    }