Exemplo n.º 1
0
    private void input(InRec inp)
    {
        if (!active)
        {
            return;
        }

        // check if a move leads out of bounds or through a wall
        if (!isAllowedMove(inp))
        {
            audioData.PlayOneShot(fail);
            reset();
            return;
        }

        // move
        currentPosition += inp.toVector();

        start.SetActive(false);

        if (foundSolution())
        {
            audioData.PlayOneShot(win);
            reset();
            if ((completed++) == 3)
            {
                OnGameComplete.Invoke();
            }
        }
    }
Exemplo n.º 2
0
    public bool blocks(Vector2 start, Vector2 target, InRec move)
    {
        if (start != pos && target != pos)
        {
            return(false);
        }

        Vector2 a      = start;
        Vector2 b      = target;
        bool    invert = false;

        if (target == pos)
        {
            a      = target;
            b      = start;
            invert = true;
        }

        int dir;

        if (invert)
        {
            dir = (move.rec + 2) % 4;
        }
        else
        {
            dir = move.rec;
        }

        return(block[dir]);
    }
Exemplo n.º 3
0
    private bool isAllowedMove(InRec input)
    {
        Vector2 nextPosition = currentPosition + input.toVector();

        if (nextPosition.x > 5f || nextPosition.x < 0f || nextPosition.y > 5f || nextPosition.y < 0f)
        {
            return(false);
        }

        // check for walls
        Wall blockingWall = Array.Find(walls[mazeNr], element => element.blocks(currentPosition, nextPosition, input));

        return(blockingWall == null);
    }