Exemplo n.º 1
0
    private Vector3 GetOrientationVector(MouseOrientation orientation)
    {
        int x = 0;
        int y = 0;

        if ((orientation & MouseOrientation.North) != 0)
        {
            y = 1;
        }
        else if ((orientation & MouseOrientation.South) != 0)
        {
            y = -1;
        }

        if ((orientation & MouseOrientation.East) != 0)
        {
            x = 1;
        }
        else if ((orientation & MouseOrientation.West) != 0)
        {
            x = -1;
        }

        return(new Vector3(x, 0, y).normalized);
    }
Exemplo n.º 2
0
    private void Reset()
    {
        cells = new Maze.Cell[Maze.MazeSize.x, Maze.MazeSize.y];
        for (yPos = 0; yPos < Maze.MazeSize.y; yPos++)
        {
            for (xPos = 0; xPos < Maze.MazeSize.x; xPos++)
            {
                cells[xPos, yPos] = new Maze.Cell(xPos, yPos);
            }
        }

        Maze.Cell start = Maze.Cells[0, 0];
        orientation = MouseOrientation.North;
        if (start.HasWall(Maze.Wall.North))
        {
            orientation = MouseOrientation.East;
        }

        GameObject.FindGameObjectsWithTag("Wall").ToList().ForEach(go => go.GetComponent <Renderer>().material.color   = Color.white);
        GameObject.FindGameObjectsWithTag("Ground").ToList().ForEach(go => go.GetComponent <Renderer>().material.color = Color.black);
        GameObject.FindGameObjectsWithTag("End").ToList().ForEach(go => go.GetComponent <Renderer>().material.color    = Color.gray);

        xPos = 0;
        yPos = 0;

        UpdateTransform();
    }
Exemplo n.º 3
0
    private void DetectWall(MouseOrientation orientation)
    {
        var wall = GetWallFromMouseOrientation(orientation);

        if (Maze.Cells[xPos, yPos].HasWall(wall))
        {
            cells[xPos, yPos].InsertWall(wall);

            var adjacentCell = GetAdjacentCell(orientation);
            if (adjacentCell != null)
            {
                cells[adjacentCell.x, adjacentCell.y].InsertWall(Maze.GetOppositeWall(wall));
            }

            var ray     = new Ray(transform.position, GetOrientationVector(orientation));
            var hitInfo = new RaycastHit();
            if (Physics.Raycast(ray, out hitInfo))
            {
                if (hitInfo.transform.tag == "Wall" && hitInfo.distance < sensorDetectionLength)
                {
                    hitInfo.transform.GetComponent <Renderer>().material.color = Color.green;
                }
            }
        }
    }
Exemplo n.º 4
0
    private MouseOrientation GetOrientation(MouseOrientation orientation, int quarters)
    {
        var mouseOrientationLength = Enum.GetNames(typeof(MouseOrientation)).Length;

        if (quarters < 0)
        {
            quarters += mouseOrientationLength;
        }

        int index = (Array.IndexOf(Enum.GetValues(typeof(MouseOrientation)), orientation) + quarters) % mouseOrientationLength;

        return((MouseOrientation)(Enum.GetValues(orientation.GetType())).GetValue(index));
    }
Exemplo n.º 5
0
    public static Maze.Wall GetWallFromMouseOrientation(MouseOrientation mouseOrientation)
    {
        switch (mouseOrientation)
        {
        case MouseOrientation.North:
            return(Maze.Wall.North);

        case MouseOrientation.East:
            return(Maze.Wall.East);

        case MouseOrientation.South:
            return(Maze.Wall.South);

        case MouseOrientation.West:
            return(Maze.Wall.West);
        }

        return(Maze.Wall.None);
    }
Exemplo n.º 6
0
    private Maze.Cell GetAdjacentCell(MouseOrientation orientation)
    {
        int xNew = xPos;
        int yNew = yPos;

        int length = 1;

        if ((orientation & MouseOrientation.North) != 0)
        {
            yNew += 1;
        }

        else if ((orientation & MouseOrientation.South) != 0)
        {
            yNew -= length;
        }

        if ((orientation & MouseOrientation.East) != 0)
        {
            xNew += length;
        }

        else if ((orientation & MouseOrientation.West) != 0)
        {
            xNew -= length;
        }

        if (xNew < 0 || xNew >= Maze.MazeSize.x)
        {
            return(null);
        }

        if (yNew < 0 || yNew >= Maze.MazeSize.y)
        {
            return(null);
        }

        return(cells[xNew, yNew]);
    }
Exemplo n.º 7
0
 // Negative CCW; Positive CW
 private void Rotate(int quarters)
 {
     orientation = GetOrientation(orientation, quarters);
 }