public List <o_node> CheckAroundNode(o_node node, s_pathfind path)
    {
        List <o_node> nodelist = new List <o_node>();
        Vector2Int    nodepos  = NodePositionFromWorld(node);

        int xno = nodepos.x, yno = nodepos.y;

        for (int x = xno + 1; x >= xno - 1; x--)
        {
            if (x == xno)
            {
                continue;
            }

            if (x > 0 && x < gridworldsize.x)
            {
                nodelist.Add(nodes[x, yno]);
            }

            for (int y = yno + 1; y >= yno - 1; y--)
            {
                if (y == yno)
                {
                    continue;
                }

                if (y > 0 && y < gridworldsize.y)
                {
                    nodelist.Add(nodes[xno, y]);
                }
            }
        }
        return(nodelist);
    }
예제 #2
0
 void Awake()
 {
     canvas.gameObject.SetActive(true);
     pathfind = GetComponent <s_pathfind>();
     nl       = this;
     InEditor = false;
     InitializeLoader();
     InitializeGameWorld();
     colmp.color = Color.clear;
     foreach (KeyValuePair <string, int> v in s_globals.GlobalFlags)
     {
         s_globals.SetGlobalFlag(v.Key, 0);
     }
     //LoadMap(maps[0]);
 }
예제 #3
0
    void ICharacter.Intialize()
    {
        defeated      = false;
        current_item  = null;
        actionPoints  = maxActionPoints;
        health        = maxHealth;
        hasdisapeared = false;
        GameObject manager = GameObject.Find("Manager");

        if (GameObject.Find("CharacterManager") != null)
        {
            charctMnger = GameObject.Find("CharacterManager").GetComponent <s_charactermanager>();
        }

        renderer = GetComponent <SpriteRenderer>();
        grid     = manager.GetComponent <s_grid>();
        path     = manager.GetComponent <s_pathfind>();
    }
예제 #4
0
    public override void SetTileMap(s_map mapdat)
    {
        pathNodes.Clear();
        debugNodes.Clear();

        s_map mp = mapdat;
        List <s_map.s_block>   tile    = mp.graphicTiles;
        List <s_map.s_block>   tileMid = mp.graphicTilesMiddle;
        List <s_map.s_block>   tileTop = mp.graphicTilesTop;
        List <s_map.s_tileobj> coll    = mp.tilesdata;

        // base.SetTileMap(mapdat);

        /*
         */
        foreach (s_map.s_block b in tile)
        {
            tm.SetTile(new Vector3Int((int)b.position.x / 20, (int)b.position.y / 20, 0), tilesNew.Find(ti => ti.name == b.sprite));
        }
        foreach (s_map.s_block b in tileMid)
        {
            tm2.SetTile(new Vector3Int((int)b.position.x / 20, (int)b.position.y / 20, 0), tilesNew.Find(ti => ti.name == b.sprite));
        }
        foreach (s_map.s_block b in tileTop)
        {
            tm3.SetTile(new Vector3Int((int)b.position.x / 20, (int)b.position.y / 20, 0), tilesNew.Find(ti => ti.name == b.sprite));
        }

        int nodeID = 0;

        for (int i = 0; i < coll.Count; i++)
        {
            s_map.s_tileobj b        = coll[i];
            string          tilename = "";
            COLLISION_T     tileType = (COLLISION_T)b.enumthing;
            Tile            t        = null;
            s_pathNode      nod2     = new s_pathNode();
            GameObject      go       = null;

            if (InEditor)
            {
                switch (b.TYPENAME)
                {
                case "teleport_object":
                case "keyObj":
                    go = Instantiate(
                        FindOBJ(b.TYPENAME),
                        new Vector3(b.pos_x, b.pos_y),
                        Quaternion.identity);
                    if (go != null)
                    {
                        go.transform.SetParent(tilesObj.transform);
                        go.name = b.name;
                    }
                    break;

                case "Node":
                    go = Instantiate(FindOBJ(b.TYPENAME),
                                     new Vector3(b.pos_x, b.pos_y),
                                     Quaternion.identity);
                    if (go != null)
                    {
                        go.transform.SetParent(tilesObj.transform);
                        go.name = b.name;
                    }

                    o_nodeobj nod = go.GetComponent <o_nodeobj>();

                    nod.nodeID             = nodeID;
                    nod.name               = "Node_" + nod.nodeID;
                    nod.transform.position = new Vector3(b.pos_x, b.pos_y);
                    nod.transform.SetParent(tilesObj.transform);
                    debugNodes.Add(nod);

                    /*
                     * o_nodeobj nod = go.GetComponent<o_nodeobj>();
                     * nod.nodeID = nodeID;
                     * nod.name = "Node_" + nod.nodeID;
                     * debugNodes.Add(nod);
                     */

                    nod2          = new s_pathNode();
                    nod2.position = new Vector2(b.pos_x, b.pos_y);
                    if (b.CustomTypes.Find(x => x.name == "nodeID").name == "")
                    {
                        nod2.id = nodeID;
                    }
                    else
                    {
                        nod2.id = b.CustomTypes.Find(x => x.name == "nodeID").type;
                    }
                    pathNodes.Add(nod2);
                    nodeID++;
                    break;
                }

                /*
                 * switch (tileType)
                 * {
                 *  case COLLISION_T.WALL:
                 *      if (b.TYPENAME == "teleport_object")
                 *          continue;
                 *      colmp.SetTile(new Vector3Int(b.pos_x / 20, b.pos_y / 20, 0), collisionTile);
                 *      break;
                 * }
                 */
            }
            else
            {
                switch (b.TYPENAME)
                {
                case "teleport_object":
                    continue;

                case "keyObj":
                    SpawnObject <o_generic>("keyObj", new Vector2(b.pos_x, b.pos_y), Quaternion.identity);
                    continue;

                case "Node":
                    nod2          = new s_pathNode();
                    nod2.position = new Vector2(b.pos_x, b.pos_y);
                    nod2.id       = nodeID;
                    pathNodes.Add(nod2);
                    nodeID++;
                    break;
                }
            }
            tilename = b.name;
            if (tilename != "")
            {
                colmp.SetTile(new Vector3Int(b.pos_x / 20, b.pos_y / 20, 0), collisionList.Find(ti => ti.name == tilename));
            }
            else
            {
                colmp.SetTile(new Vector3Int(b.pos_x / 20, b.pos_y / 20, 0), t);
            }
        }

        for (int i = 0; i < pathNodes.Count; i++)
        {
            s_pathNode        p             = pathNodes[i];
            List <s_pathNode> nbrs          = new List <s_pathNode>();
            List <int>        GetNeighbours = new List <int>();

            s_map.s_tileobj t = coll[p.id];

            //Gets all the neighbours
            foreach (s_map.s_customType no in t.CustomTypes)
            {
                //Find all the custom values with "node" which resemble the neighbours
                if (no.name == "node")
                {
                    s_pathNode path = pathNodes.Find(x => x.id == no.type);
                    nbrs.Add(path);
                }
            }
            if (InEditor)
            {
                o_nodeobj currentNode = debugNodes.Find(x => x.nodeID == p.id);
                foreach (s_pathNode n in nbrs)
                {
                    o_nodeobj nod = debugNodes.Find(x => x.nodeID == n.id);
                    if (nod != null)
                    {
                        currentNode.nieghbours.Add(nod);
                        GetNeighbours.Add(n.id);

                        //nod.nieghbours.Add(currentNode);
                        if (!currentNode.nieghbours.Find(x => nod))
                        {
                        }
                    }
                }
                foreach (s_pathNode n in nbrs)
                {
                    GetNeighbours.Add(n.id);
                }
                p            = new s_pathNode(p.id, new Vector2(p.position.x, p.position.y), GetNeighbours);
                pathNodes[i] = p;
            }
            else
            {
                foreach (s_pathNode n in nbrs)
                {
                    GetNeighbours.Add(n.id);
                }
                p            = new s_pathNode(p.id, new Vector2(p.position.x, p.position.y), GetNeighbours);
                pathNodes[i] = p;
            }
        }
        pathfind = GetComponent <s_pathfind>();
        pathfind.SetNodes(ref pathNodes);
    }