Exemplo n.º 1
0
        void create_new_level()
        {
            max_x = level_texture.width;
            max_y = level_texture.height;
            texture_2d_instance = new Texture2D(max_x, max_y);


            grid = new node[max_x, max_y];

            for (int x = 0; x < max_x; x++)
            {
                for (int y = 0; y < max_y; y++)
                {
                    node n = new node();
                    n.x = x;
                    n.y = y;

                    Color c = level_texture.GetPixel(x, y);

                    texture_2d_instance.SetPixel(x, y, c);
                    n.is_empty = (c.a == 0);

                    grid[x, y] = n;
                }
            }

            texture_2d_instance.Apply();
            Rect rectangle = new Rect(0, 0, max_x, max_y);

            level_renderer.sprite = Sprite.Create(texture_2d_instance, rectangle, Vector2.zero);
        }
Exemplo n.º 2
0
    void afficher(node[,] t, int n)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (t[i, j].up == 0)
                {
                    //printf("up i = %d j = %d\n",i,j);
                    //SDL_RenderDrawLine(renderer, c+gap*j, c+gap*i, c+gap*(j+1), c+gap*i);
                    (Instantiate(Wall, new Vector3(j, 0.5f, i), Quaternion.Euler(0f, 90f, 0f)) as GameObject).transform.parent = Labyrinth.transform;
                }
            }

            for (int j = 0; j < n; j++)
            {
                if (t[i, j].left == 0)
                {
                    (Instantiate(Wall, new Vector3(j, 0.5f, i), Quaternion.Euler(0f, 0f, 0f)) as GameObject).transform.parent = Labyrinth.transform;
                }
            }
        }
        for (int j = 0; j < n; j++)
        {
            (Instantiate(Wall, new Vector3(n, 0.5f, j), Quaternion.Euler(0f, 0f, 0f)) as GameObject).transform.parent = Labyrinth.transform;
        }
        for (int j = 0; j < n; j++)
        {
            (Instantiate(Wall, new Vector3(j, 0.5f, n), Quaternion.Euler(0f, 90f, 0f)) as GameObject).transform.parent = Labyrinth.transform;
        }

        jX = (float)Random.Range(0, n);
        jZ = (float)Random.Range(0, n);
        Instantiate(Jewel, new Vector3(jX + 0.5f, 0.2f, jZ + 0.5f), Quaternion.identity);
    }
Exemplo n.º 3
0
        }//end of setdimval

        //SET STATUSE OF MY NODE
        static void setstatus(node [,] a, int hp, int wp, Color[,] pixel, int gx, int gy, int sx, int sy)
        {
            for (int j = 0; j < hp; j++)
            {
                for (int i = 0; i < wp; i++)
                {
                    Color pix = pixel[i, j];

                    if (i == gx && j == gy)
                    {
                        a[i, j].status = "GOAL";
                    }
                    else if (i == sx && j == sy)
                    {
                        a[i, j].status = "START";
                    }
                    else if (pix.G == 0 && pix.R == 0 && pix.B == 0)
                    {
                        a[i, j].status = "OBSTACLE";
                    }
                    else
                    {
                        a[i, j].status = "CLEAR";
                    }
                }
            }
        }//end of set status
Exemplo n.º 4
0
        public void ClearReferences()
        {
            if (mapObject != null)
            {
                Destroy(mapObject);
            }
            if (playerObj != null)
            {
                Destroy(playerObj);
            }
            if (appleObj != null)
            {
                Destroy(appleObj);
            }

            foreach (var t in tail)
            {
                if (t.obj != null)
                {
                    Destroy(t.obj);
                }
            }
            tail.Clear();
            avaliableNode.Clear();
            grid = null;
        }
Exemplo n.º 5
0
 public AStarPathfinder(MyAI _player)
 {
     Xdim   = _player.Tissue.Width;
     Ydim   = _player.Tissue.Height;
     Map    = new node[Xdim, Ydim];
     States = new int[Xdim, Ydim];
     fs     = new double[Xdim, Ydim];
     GetMap(Xdim, Ydim, _player);
 }
Exemplo n.º 6
0
        public void CreateMap()
        {
            mapObject = new GameObject("Map");
            mapObject.transform.position = new Vector3(0, 0, 0);
            mapRenderer = mapObject.AddComponent <SpriteRenderer>();
            grid        = new node[maxWidth, maxHeight];
            Texture2D txt = new Texture2D(maxWidth, maxHeight);

            for (int i = 0; i < maxWidth; i++)
            {
                for (int j = 0; j < maxHeight; j++)
                {
                    Vector3 tp = Vector3.zero;
                    tp.x = i;
                    tp.y = j;

                    node n = new node()
                    {
                        x             = i,
                        y             = j,
                        worldPosition = tp
                    };
                    grid[i, j] = n;
                    avaliableNode.Add(n);
                    #region Visual
                    if (i % 2 != 0)
                    {
                        if (j % 2 != 0)
                        {
                            txt.SetPixel(i, j, color1);
                        }
                        else
                        {
                            txt.SetPixel(i, j, color2);
                        }
                    }
                    else
                    {
                        if (j % 2 != 0)
                        {
                            txt.SetPixel(i, j, color2);
                        }
                        else
                        {
                            txt.SetPixel(i, j, color1);
                        }
                    }
                    #endregion
                }
            }
            txt.filterMode = FilterMode.Point;
            txt.Apply();
            Rect   rect   = new Rect(0, 0, maxWidth, maxHeight);
            Sprite sprite = Sprite.Create(txt, rect, Vector2.zero, 1, 0, SpriteMeshType.FullRect);
            sprite.name        = "Map";
            mapRenderer.sprite = sprite;
        }
Exemplo n.º 7
0
 public AStarPathfinder(MyAI _player)
 {
     Xdim = _player.Tissue.Width;
     Ydim = _player.Tissue.Height;
     Map = new node[Xdim, Ydim];
     States = new int[Xdim, Ydim];
     fs = new double[Xdim, Ydim];
     GetMap(Xdim, Ydim, _player);
 }
Exemplo n.º 8
0
 //SET TAG OF MY NODE
 static void settag(node[,] a, int hp, int wp)
 {
     for (int j = 0; j < hp; j++)
     {
         for (int i = 0; i < wp; i++)
         {
             a[i, j].tag = "NEW";
         }
     }
 }//end of settag
Exemplo n.º 9
0
    position randum(node[, ] t, int n)
    {
        int b = 0;
        int a = 0;
        int i = 0;
        int j = 0;

        while (b == 0)
        {
            i = Random.Range(0, n);
            j = Random.Range(0, n);
            a = Random.Range(0, 4);

            switch (a)
            {
            case 0:
                //0 = up
                if ((i > 0) && (t[i, j].up == 0))
                {
                    b = 1;
                }
                break;

            case 3:
                //3 = down
                if ((i < n - 1) && (t[i, j].down == 0))
                {
                    b = 1;
                }
                break;

            case 1:
                //1 = right
                if ((j < n - 1) && (t[i, j].right == 0))
                {
                    b = 1;
                }
                break;

            case 2:
                //2 = left
                if ((j > 0) && (t[i, j].left == 0))
                {
                    b = 1;
                }
                break;
            }
        }
        position temp;

        temp.i    = i;
        temp.j    = j;
        temp.side = a;
        return(temp);
    }
Exemplo n.º 10
0
 public void CreateMap(int size_x, int size_y)
 {
     mapdata = new node[size_y, size_x];
     for (int yi = 1; yi <= mapdata.GetLength(0); yi++)
     {
         for (int xi = 1; xi <= mapdata.GetLength(1); xi++)
         {
             mapdata[yi - 1, xi - 1] = new node(xi, yi);
         }
     }
 }
Exemplo n.º 11
0
    //#####################################################################################################
    //########                    pass map info to constructor                                    #########
    //#####################################################################################################

    public pathFinder(Vector2 leftUpCorner, int width, int height, float offset, CollisionDetectionMode CDM)
    {
        CollisionMode    = CDM;
        NodeArray        = new node[height, width];
        map_leftUpCorner = leftUpCorner;
        map_width        = width;
        map_height       = height;
        map_offset       = offset;
        CreateMap();
        ResetForNewPath();
    }
Exemplo n.º 12
0
        }//end of settag

        //SET DIMATION VALUE OF MY NODE
        static void setdimval(node[,] a, int hp, int wp)
        {
            for (int j = 0; j < hp; j++)
            {
                for (int i = 0; i < wp; i++)
                {
                    a[i, j].ni = i;
                    a[i, j].nj = j;
                }
            }
        }//end of setdimval
Exemplo n.º 13
0
    int jewelConnected(node[,] t, int n, int i1, int j1, int i2, int j2)
    {
        int i, j;

        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                verif[i, j] = 0;
            }
        }
        return(jewelPos(t, n, i1, j1, i2, j2, 0, steps));
    }
Exemplo n.º 14
0
    int connected(node[, ] t, int n, int i1, int j1, int i2, int j2)
    {
        int i, j;

        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                verif[i, j] = 0;
            }
        }
        return(find(t, n, i1, j1, i2, j2));
    }
Exemplo n.º 15
0
    public void createGrid()
    {
        grid = new node[gridSizeX, gridSizeY];
        Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;

        for (int x = 0; x < gridSizeX; x++)
        {
            for (int y = 0; y < gridSizeY; y++)
            {
                Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius);
                bool    walkable   = !(Physics.CheckSphere(worldPoint, nodeRadius, unwalkableMask));
                grid[x, y] = new node(walkable, worldPoint, x, y);
            }
        }
    }
Exemplo n.º 16
0
    void createGrid()
    {
        mainGrid = new node[gridSizeX,gridSizeY];
        Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x/2 - Vector3.forward* 	gridWorldSize.y/2;

        for (int x = 0; x < gridSizeX; x ++)
        {
            for (int y = 0; y < gridSizeY; y ++)
            {
                Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius);
                bool Walkable = !(Physics.CheckSphere(worldPoint,nodeRadius,unwalkableMask));
                mainGrid[x,y] = new node(Walkable,worldPoint,x,y);
            }
        }
    }
Exemplo n.º 17
0
    //if u didnt understand what the method doas f*****g read the method name morron -_-"
    public void CreateGrid()
    {
        Grid = new node[gridSizeX, gridSizeY];
        Vector3 WorldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.up * gridWorldSize.y / 2;//chacks the bottom left corrner of the map

        //deffy the grid and nodes orders on it
        for (int x = 0; x < gridSizeX; x++)
        {
            for (int y = 0; y < gridSizeY; y++)
            {
                Vector3 worldPoint = WorldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.up * (y * nodeDiameter + nodeRadius);
                bool    walkable   = !(Physics.CheckSphere(worldPoint, nodeRadius, unWalkableMask));
                Grid[x, y] = new node(walkable, worldPoint, x, y);
            }
        }
    }
Exemplo n.º 18
0
        public dpTable(GeneSequence aSequence, GeneSequence bSequence)
        {
            X = aSequence.Sequence;
            Y = bSequence.Sequence;

            setDimensions();

            results = new node[width, height];

            this.SetCell(0, 0, 0, "start");

            for (int i = 1; i < width; ++i)
                this.SetCell(i, 0, indel * i, "left");

            for (int j = 1; j < height; ++j)
                this.SetCell(0, j, indel * j, "top");
        }
Exemplo n.º 19
0
    int jewelPos(node[,] t, int n, int i1, int j1, int i2, int j2, int counter, int[] steps)
    {
        verif[i1, j1] = 1;
        counter++;

        if ((i1 == i2) && (j1 == j2))
        {
            return(1);
        }

        if ((t[i1, j1].down == 1) && (verif[i1 + 1, j1] == 0))
        {
            if (jewelPos(t, n, i1 + 1, j1, i2, j2, counter, steps) >= 1)
            {
                steps[counter - 1] = 3;
                return(1);
            }
        }
        if ((t[i1, j1].up == 1) && (verif[i1 - 1, j1] == 0))
        {
            if (jewelPos(t, n, i1 - 1, j1, i2, j2, counter, steps) >= 1)
            {
                steps[counter - 1] = 0;
                return(1);
            }
        }
        if ((t[i1, j1].left == 1) && (verif[i1, j1 - 1] == 0))
        {
            if (jewelPos(t, n, i1, j1 - 1, i2, j2, counter, steps) >= 1)
            {
                steps[counter - 1] = 2;
                return(1);
            }
        }
        if ((t[i1, j1].right == 1) && (verif[i1, j1 + 1] == 0))
        {
            if (jewelPos(t, n, i1, j1 + 1, i2, j2, counter, steps) >= 1)
            {
                steps[counter - 1] = 1;
                return(1);
            }
        }

        counter--;
        return(0);
    }
Exemplo n.º 20
0
    void init(node[, ] t, int n)
    {
        int i, j;

        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                t[i, j].up    = 0;
                t[i, j].down  = 0;
                t[i, j].left  = 0;
                t[i, j].right = 0;
            }
        }
        // creation of verification table
        verif = new int[n, n];
    }
Exemplo n.º 21
0
    //create a copy of the table but using nodes instead of X gameobject
    public void CreateTable(int _width, int _height)
    {
        if (m_map == null)
        {
            m_map = new node[_width, _height];
        }

        for (int i = 0; i < _width; ++i)
        {
            for (int j = 0; j < _height; ++j)
            {
                node newnode = new node(i, j);
                m_map[i, j] = newnode;
            }
        }
        m_width  = _width;
        m_height = _height;
    }
Exemplo n.º 22
0
    void sorted(node[, ] maze, position[] p, int n)
    {
        int      i = 0, max = n * (n - 1) * 2;
        position pos;

        i = 0;
        while (i < max)
        {
            pos = randum(maze, n);
            //printf("i: %d j: %d side: %d i : %d \n ",pos.i,pos.j,pos.side,i);
            p[i].i    = pos.i;
            p[i].j    = pos.j;
            p[i].side = pos.side;
            //printf("i: %d j: %d side: %d i : %d \n",p[i].i,p[i].j,p[i].side,i);
            destruction(maze, n, pos.i, pos.j, pos.side);
            i++;
        }
    }
Exemplo n.º 23
0
        }//end of set status

        //SORT ELEMENT OF QUEUE INCRESING
        static void sortqueue(Queue OpenList, node[,] state)
        {
            int ind = OpenList.Count;

            double[] kk = new double[ind];
            int[]    ii = new int[ind];
            int[]    jj = new int[ind];

            node d = new node();

            for (int i = 0; i < ind; i++)
            {
                d     = (node)OpenList.Dequeue();
                kk[i] = d.k;
                ii[i] = d.ni;
                jj[i] = d.nj;
            }

            for (int i = 0; i < ind; i++)
            {
                for (int j = 0; j < ind; j++)
                {
                    if (kk[i] < kk[j])
                    {
                        double tempk = kk[i];
                        kk[i] = kk[j];
                        kk[j] = tempk;

                        int tempi = ii[i];
                        ii[i] = ii[j];
                        ii[j] = tempi;

                        int tempj = jj[i];
                        jj[i] = jj[j];
                        jj[j] = tempj;
                    }
                }
            }

            for (int i = 0; i < ind; i++)
            {
                OpenList.Enqueue(state[ii[i], jj[i]]);
            }
        }//end of sortqueue
Exemplo n.º 24
0
    void CreateGrid()
    {
        Grid = new node[GridSizeX, GridSizeY];
        Vector2 CornerLeftDown = transform.position - (Vector3.right * GridWorldSize.x / 2) - Vector3.up * GridWorldSize.y / 2;

        for (int x = 0; x < GridSizeX; x++)
        {
            for (int y = 0; y < GridSizeY; y++)
            {
                Vector2 p = CornerLeftDown + Vector2.right * (x * NodeDiamiter + node_radius)
                            + Vector2.up * (y * NodeDiamiter + node_radius);
                bool walkable      = rayCast(p, node_radius);
                bool diagonal_move = rayCast(p, node_radius * 2);

                float penalty = 0;

                /*
                 * if (walkable)
                 * {
                 *  for (float k = 4, b = 0.95f ; k > 1.2f; k *= b, b -= 0.03f)
                 *  {
                 *      if (!rayCast(p, node_radius * k))
                 *      penalty += 3 - b;
                 *  }
                 * }
                 * else
                 *  penalty = 30;
                 */
                //print(penalty);
                Grid[x, y] = new node(p, walkable, diagonal_move, x, y, Mathf.RoundToInt(penalty));

                if (penalty > penaltyMax)
                {
                    penaltyMax = Mathf.RoundToInt(penalty);
                }
                if (penalty < penaltyMin)
                {
                    penaltyMin = Mathf.RoundToInt(penalty);
                }
            }
        }
        //BlurPenaltyMap(3, true);
    }
Exemplo n.º 25
0
    public override void _Ready()
    {
        nodes = new node[gridWidth, gridHeight];
        //create Grid [25 x 14]
        for (int y = 0; y < gridHeight; y++)
        {
            for (int x = 0; x < gridWidth; x++)
            {
                //create Node
                Node2D newNode = (Node2D)node.Instance();
                newNode.Position = new Vector2((x + 1) * gridNodeWidth, (y + 1) * gridNodeHeight);
                AddChild(newNode);

                node nodeInstance = (node)newNode;
                nodes[x, y]          = nodeInstance;
                nodeInstance.posGrid = new Vector2(x, y);
            }
        }
    }
Exemplo n.º 26
0
 static private void modifyMap(node[,] map) {
     int[,] terrain = {
         {2, 4},
         {3, 3},
         {3, 4},
         {4, 3},
         {4, 4},
         {4, 5},
         {5, 3},
         {5, 4},
         {5, 5},
         {6, 2},
         {6, 3},
         {6, 4},
         {6, 5}
     };
     for (int i = 0; i < terrain.GetLength(0); i++) {
         map[terrain[i, 0], terrain[i, 1]].terrain = 1;
     }
 }
Exemplo n.º 27
0
    void destruction(node[, ] t, int n, int i, int j, int side)
    {
        switch (side)
        {
        case 0:
            //0 = up
            if (i > 0)
            {
                t[i, j].up       = 1;
                t[i - 1, j].down = 1;
            }
            break;

        case 3:
            //3 = down
            if (i < n - 1)
            {
                t[i, j].down   = 1;
                t[i + 1, j].up = 1;
            }
            break;

        case 1:
            //1 = right
            if (j < n - 1)
            {
                t[i, j].right    = 1;
                t[i, j + 1].left = 1;
            }
            break;

        case 2:
            //2 = left
            if (j > 0)
            {
                t[i, j].left      = 1;
                t[i, j - 1].right = 1;
            }
            break;
        }
    }
Exemplo n.º 28
0
    void Start()
    {
        this.nodes = new node[this.size, this.size];

        float hs = (this.distance * (this.size - 1)) / 2.0f;

        float cd = 1.0f / (float)this.size;

        for (int x = 0; x < this.size; x++)
        {
            for (int y = 0; y < this.size; y++)
            {
                var go = Instantiate(this.node_prefab, this.transform) as GameObject;
                go.name = "node{" + x + ", " + y + "}";
                go.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);

                this.nodes[x, y] = go.GetComponent <node>();
                this.nodes[x, y].initialise(new Vector3(x * this.distance - hs, y * this.distance - hs));
            }
        }
    }
Exemplo n.º 29
0
    int find(node[, ] t, int n, int i1, int j1, int i2, int j2)
    {
        verif[i1, j1] = 1;

        if ((i1 == i2) && (j1 == j2))
        {
            return(1);
        }

        if ((t[i1, j1].down == 1) && (verif[i1 + 1, j1] == 0))
        {
            if (find(t, n, i1 + 1, j1, i2, j2) >= 1)
            {
                return(1);
            }
        }
        if ((t[i1, j1].up == 1) && (verif[i1 - 1, j1] == 0))
        {
            if (find(t, n, i1 - 1, j1, i2, j2) >= 1)
            {
                return(1);
            }
        }
        if ((t[i1, j1].left == 1) && (verif[i1, j1 - 1] == 0))
        {
            if (find(t, n, i1, j1 - 1, i2, j2) >= 1)
            {
                return(1);
            }
        }
        if ((t[i1, j1].right == 1) && (verif[i1, j1 + 1] == 0))
        {
            if (find(t, n, i1, j1 + 1, i2, j2) >= 1)
            {
                return(1);
            }
        }

        return(0);
    }
Exemplo n.º 30
0
    bool initHouseData()
    {
        housePosArray = new List <Vector2Int>();
        table         = new node[width, height];
        visTable      = new bool[width, height];
        g             = new int[sizeOfHouse, sizeOfHouse];
        posToHouse    = new Dictionary <Vector2Int, GameObject>();
        posToFog      = new Dictionary <Vector2Int, GameObject>();
        houseOfOwner  = new int[Scene.instance.sizeOfHouse];
        ligVis        = new float[width, height];
        soldierSet    = new HashSet <GameObject>();

        // 0 stop 1 go 2 house 四个角的house数相同
        int allowTry = 100;

        int[] offsetX = new int[] { 0, width >> 1, width >> 1, 0 };
        int[] offsetY = new int[] { 0, height >> 1, 0, height >> 1 };
        for (int i = 0; i < sizeOfHouse; i++)
        {
            int index = i % 4;
            houseOfOwner[i] = index;
            int x = Random.Range(1, (width >> 1) - 1) + offsetX[index];
            int y = Random.Range(1, (height >> 1) - 1) + offsetY[index];

            if (!placeHouse(new Vector2Int(x, y)))
            {
                i--;
                if (allowTry-- <= 0)
                {
                    Debug.Log("house error restart");
                    SceneManager.LoadScene(2);
                    return(false);
                }
                continue;
            }
        }
        return(true);
    }
Exemplo n.º 31
0
 static private List<node> successorNodes(node startNode, node[,] map) {
     List<node> successorNodes = new List<node>();
     for (int i = -1; i < 2; i++) {
         for (int j = -1; j < 2; j++) {
             /*
             Here needs to check 5 things:
             1. successorNodes.x needs cannot be -1 or larger than map
             2. successorNodes.y needs cannot be -1 or larger than map
             3. successorNodes cannot be their parent nodes
             4. successorNodes cannot be the startNode
             5. if terrain =1, means that successorNodes cannot pass the terrain
             */
             if ((startNode.selfNodexy.x + i>=0 && startNode.selfNodexy.x + i <= map.GetLength(0)-1) &&
                 (startNode.selfNodexy.y + j >= 0 && startNode.selfNodexy.y + j <= map.GetLength(1) - 1) &&
                 map[startNode.selfNodexy.x + i, startNode.selfNodexy.y + j].selfNodexy != startNode.parentNodexy &&
                 map[startNode.selfNodexy.x + i, startNode.selfNodexy.y + j].selfNodexy != startNode.selfNodexy &&
                 map[startNode.selfNodexy.x + i, startNode.selfNodexy.y + j].terrain != 1) {
                 successorNodes.Add(map[startNode.selfNodexy.x + i, startNode.selfNodexy.y + j]);
             }
         }
     }
     return successorNodes;
 }
Exemplo n.º 32
0
        private void button3_Click(object sender, EventArgs e)
        {
            op1.Filter = "Image Files(*.bmp)|*.bmp";

            if (op1.ShowDialog() == DialogResult.OK)
            {
                orb       = new Bitmap(op1.FileName);
                pb1.Image = orb;
                hp        = orb.Height;
                wp        = orb.Width;

                state = new node[hp, wp];
                pixel = new Color[hp, wp];

                for (int y = 0; y < hp; y++)
                {
                    for (int x = 0; x < wp; x++)
                    {
                        pixel[x, y] = orb.GetPixel(x, y);
                    }
                }
            }
        }
Exemplo n.º 33
0
    void CreateGrid()
    {
        //creates a 2 dimensional array of nodes.

        gridlist = new node[gridx, gridy];

        //places a point to the bottom left of the map to mark the first node.

        Vector3 BottomLeft = transform.position - Vector3.right * gridSize.x / 2 - Vector3.up * gridSize.y / 2;


        //Creates the node grid and checks if there is a wall for each node.

        for (int x = 0; x < gridx; x++)
        {
            for (int y = 0; y < gridy; y++)
            {
                Vector3 Worldpoint = BottomLeft + Vector3.right * (x * diameter + radius) + Vector3.up * (y * diameter + radius);
                bool    walking    = !(Physics.CheckSphere(Worldpoint, radius, walls));
                gridlist[x, y] = new node(walking, Worldpoint, x, y);
            }
        }
    }
Exemplo n.º 34
0
        private void add_nodes(int x, int y)//добавляем все вершины
        {
            int wid1=50;
            int wid2=50;
            if (x - 50 < 0)
                wid1 = x;
            if (x + 50 > wid)
                wid2 = Math.Max(wid - x,0);

            int heid1 = 50;
            int heid2 = 50;
            if (y - 50 < 0)
                heid1 = y;
            if (y + 50 > heid)
                heid2 = Math.Max(heid - y,0);

            nodes = new node[wid1 + wid2, heid1 + heid2];
            int indexx = x - 50;
            if (x - 50 <= 0)
                indexx = 0;
            int indexy = y - 50;
            if (y - 50 <= 0)
                indexy = 0;
            for (int i = 0; i < nodes.GetLength(0); ++i)
                for (int j = 0; j < nodes.GetLength(1); ++j)
                {
                    nodes[i, j] = new node(indexx + i, indexy + j, i, j);//i-столбец(в изображении), j-Строка
                }
            s = nodes[Math.Min(Math.Max(wid1,0),nodes.GetLength(0)-1),Math.Min( Math.Max(heid1,0),nodes.GetLength(1)-1)];//seed node
            
        }
Exemplo n.º 35
0
 public void create_grid(float x_len, float y_len, uint x_cell_height, uint y_cell_width)
 {
     int number_of_x_cells = (int)(x_len / x_cell_height);
     int number_of_y_cells = (int)(y_len / y_cell_width);
     grid = new node[number_of_x_cells, number_of_y_cells];
 }