コード例 #1
0
    //This method is used to retrieve the current cell,
    //check whether a move is possible and remove if its fully initialised.
    private void DoNextGenerationStep(List <Cell> activeCells)
    {
        //Set currCell to the last active cell
        int  currentIndex = activeCells.Count - 1;
        Cell currCell     = activeCells[currentIndex];

        //Remove cell from active cells when all sides are Initialised
        if (currCell.IsFullyInitialised)
        {
            activeCells.RemoveAt(currentIndex);
            return;
        }

        //Set a random map direction
        MapDirection dir = currCell.RandomUninitialisedDirection;
        //set coords to the correct positon
        Vec2 coords = currCell.coordinates + dir.ToIntVec2();

        //Check that the coords are actually viable, eg. the x value should be over 0 but below the size.x
        if (ContainsCoords(coords))
        {
            //Set the neighbour cell to the cell at coords
            Cell neighbor = GetCell(coords);
            if (neighbor == null)
            {
                //Create the cell at the set coords
                neighbor = CreateCell(coords);
                //Create passage between the current cell and its neighbour
                CreatePassage(currCell, neighbor, dir);
                activeCells.Add(neighbor);
            }
            else
            {
                //If the neighbor is not part of the same passage then create a wall between them
                CreateWall(currCell, neighbor, dir);
            }
        }
        else
        {
            //Creates the wall around the perimiter
            CreateWall(currCell, null, dir);
        }
    }
コード例 #2
0
ファイル: Pawn.cs プロジェクト: RyanLewin/BankRobberMazeGame
    //Check whether the pawn is able to move
    protected bool Move()
    {
        do
        {
            if (CheckForWall())
            {
                return(false);
            }
            if (!InRange())
            {
                return(false);
            }
        } while (false);

        otherPos  = currCell.coordinates + dir.ToIntVec2();
        otherCell = cells[otherPos.x, otherPos.y];

        //Check otherCell to see if it contains an enemy or player, if the enemy
        //sees the player in the other cell they will stop to "take a shot"
        for (int i = 0; i < otherCell.transform.childCount; i++)
        {
            string tag = otherCell.transform.GetChild(i).tag;
            if (tag == "Enemy")
            {
                return(false);
            }
            else if (tag == "Player")
            {
                stop = true;
                return(false);
            }
        }

        //move position of pawn and update parentz
        transform.position += dir.ToVec3();
        transform.parent    = otherCell.transform;
        return(true);
    }