コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        gs.leaveSpace(pos);

        transform.position = gs.getGridPosition(pos);

        Debug.Log(safeToGiveBirth(pos) + " " + pos);


        if (Input.GetKeyDown(KeyCode.W) && pos.y < gs.maxY)
        {
            pos.y += 1;
        }
        if (Input.GetKeyDown(KeyCode.S) && pos.y > 0)
        {
            pos.y -= 1;
        }
        if (Input.GetKeyDown(KeyCode.D) && pos.x < gs.maxX)
        {
            pos.x += 1;
        }
        if (Input.GetKeyDown(KeyCode.A) && pos.x > 0)
        {
            pos.x -= 1;
        }

        gs.occupySpace(pos);
    }
コード例 #2
0
    bool getNextPos()
    {
        int choice = Random.Range(0, 4);

        lastPos = gs.getGridPosition(prevPos);
        prevPos = pos;
        if (choice == 0 && pos.x < gs.maxX)
        {
            pos.x += 1;
        }
        else if (choice == 1 && pos.x > 0)
        {
            pos.x -= 1;
        }
        else if (choice == 2 && pos.y < gs.maxX)
        {
            pos.y += 1;
        }
        else if (choice == 3 && pos.y > 0)
        {
            pos.y -= 1;
        }
        if (!notInPath(gs.getGridPosition(pos)))
        {
            pos = prevPos;
            return(false);
        }
        path.Add(gs.getGridPosition(pos));
        gs.occupySpace(prevPos);
        return(true);
    }
コード例 #3
0
 bool getStartPos()
 {
     pos = new Vector2(Random.Range(0, gs.grid.GetLength(1)), Random.Range(0, gs.grid.GetLength(0)));
     if (!gs.isOccupied(pos))
     {
         transform.position = gs.getGridPosition(pos);
         gs.occupySpace(pos);
         return(true);
     }
     return(false);
 }