Ejemplo n.º 1
0
    public void nPlaceMap(TileMapScript map_data)
    {
        // place each tile
        var map_container = new GameObject("Map");
        for (int i = 0; i < map_data.getMapHeight(); ++i) {
            for (int j = 0; j < map_data.getMapWidth(); ++j) {
                var tile = map_data.getTile(i, j);
                var world_pos = new Vector3(i, 0, j);
                //GameObject new_game_object = null;
                switch (tile.get_type()) {
                    case Type.OVERWORLD_WALKABLE:{
                            GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(new_game_object);
                        }
                        break;
                    case Type.OVERWORLD_NONWALKABLE: {
                            GameObject new_game_object = Instantiate(nonwalkable_tile_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(new_game_object);
                        }
                        break;
                    case Type.ALT_OVERWORLD_WALKABLE:
                    case Type.DUNGEON_PORTAL_BORDER:
                    case Type.ENTRY_PORTAL_BORDER: {
                            GameObject new_game_object = Instantiate(nonwalkable_tile_two_prefab, world_pos, Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(new_game_object);
                        }
                        break;
                    case Type.TOWN: {
                            GameObject new_game_object = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(new_game_object);
                        }
                        break;
                    case Type.TOWN_NPC: {
                            var new_tile = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                            new_tile.transform.SetParent(map_container.transform);

                            GameObject new_game_object = Instantiate(npc_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(new_game_object);
                        }
                        break;
                    case Type.ENTRY_PORTAL: {
                            GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(new_game_object);
                            GameObject portal = Instantiate(portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(portal);
                        }
                        break;
                    case Type.DUNGEON_PORTAL: {
                            GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(new_game_object);
                            var dungeon_portal = Instantiate(dungeon_portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                            NetworkServer.Spawn(dungeon_portal);
                        }
                        break;
                }
                //if (new_game_object != null) {
                //   new_game_object.transform.SetParent(map_container.transform);
                //}
            }
        }
    }
Ejemplo n.º 2
0
    public void findpath()
    {
        if (map.getTile(destination[0], destination[1]).isWalkable())
        {
            return;
        }
        HashSet <Node> tree       = new HashSet <Node>();
        HashSet <Node> frontier   = new HashSet <Node>();
        Node           originNode = addNode(origin, null, null);

        frontier.Add(originNode);
        while (frontier.Count > 0)
        {
            int  minValue = Int16.MaxValue;
            Node minNode  = null;
            foreach (Node n in frontier)
            {
                int value = n.f;
                if (minValue > value)
                {
                    minValue = value;
                    minNode  = n;
                }
            }
            frontier.Remove(minNode);
            tree.Add(minNode);
            foreach (int[] x in directions)
            {
                int[] y = add(minNode.position, x);
                //int newDistance = minNode.pathLengthFromOrigin + 1 + h(y);
                bool found = false;
                if (y[0] < 0 || y[1] < 0)                 //|| y[0] >= map.GetLength(0) || y[1] >= map.GetLength(1))
                {
                    continue;
                }
                if (map.getTile(y[0], y[1]).isWalkable())
                {
                    if (y[0] == destination[0] && y[1] == destination[1])
                    {
                        path = new List <Node>();
                        path.Add(addNode(y, minNode, x));
                        for (Node n = minNode; n != null; n = n.previous)
                        {
                            path.Insert(0, n);
                        }
                        //pathFound = true;
                    }

                    foreach (Node n in tree)
                    {
                        if (n.position[0] == y[0] && n.position[1] == y[1])
                        {
                            found = true;
                            if (n.pathLengthFromOrigin > minNode.pathLengthFromOrigin + 1)
                            {
                                setParent(n, minNode, x);
                            }
                            break;
                        }
                    }
                    if (!found)
                    {
                        Node n = addNode(y, minNode, x);
                        frontier.Add(n);
                        tree.Add(n);
                    }
                }
            }
        }
        return;
    }
Ejemplo n.º 3
0
    public void nPlaceMap(TileMapScript map_data)
    {
        // place each tile
        var map_container = new GameObject("Map");

        for (int i = 0; i < map_data.getMapHeight(); ++i)
        {
            for (int j = 0; j < map_data.getMapWidth(); ++j)
            {
                var tile      = map_data.getTile(i, j);
                var world_pos = new Vector3(i, 0, j);
                //GameObject new_game_object = null;
                switch (tile.get_type())
                {
                case Type.OVERWORLD_WALKABLE: {
                    GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(new_game_object);
                }
                break;

                case Type.OVERWORLD_NONWALKABLE: {
                    GameObject new_game_object = Instantiate(nonwalkable_tile_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(new_game_object);
                }
                break;

                case Type.ALT_OVERWORLD_WALKABLE:
                case Type.DUNGEON_PORTAL_BORDER:
                case Type.ENTRY_PORTAL_BORDER: {
                    GameObject new_game_object = Instantiate(nonwalkable_tile_two_prefab, world_pos, Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(new_game_object);
                }
                break;

                case Type.TOWN: {
                    GameObject new_game_object = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(new_game_object);
                }
                break;

                case Type.TOWN_NPC: {
                    var new_tile = Instantiate(town_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                    new_tile.transform.SetParent(map_container.transform);

                    GameObject new_game_object = Instantiate(npc_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(new_game_object);
                }
                break;

                case Type.ENTRY_PORTAL: {
                    GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(new_game_object);
                    GameObject portal = Instantiate(portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(portal);
                }
                break;

                case Type.DUNGEON_PORTAL: {
                    GameObject new_game_object = Instantiate(walkable_tile_prefab, world_pos, Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(new_game_object);
                    var dungeon_portal = Instantiate(dungeon_portal_prefab, world_pos + new Vector3(0.0f, 1.0f, 0.0f), Quaternion.identity) as GameObject;
                    NetworkServer.Spawn(dungeon_portal);
                }
                break;
                }
                //if (new_game_object != null) {
                //   new_game_object.transform.SetParent(map_container.transform);
                //}
            }
        }
    }