Ejemplo n.º 1
0
 private void ReturnToPreviousRoom()
 {
     firstDepthGrag.Remove(currentRoom);
     if (firstDepthGrag.Count > 1)
     {
         currentRoom = firstDepthGrag[firstDepthGrag.Count - 1];
     }
 }
Ejemplo n.º 2
0
    private void SetCurrentRoom()
    {
        GraphRoom newRoom = dungeon.GetRoomFromPosition(_transform.position);

        if (newRoom != null && newRoom != currentRoom)
        {
            EventDispatcher.DispatchEvent(Events.PLAYER_ENTER_ROOM, newRoom);
            currentRoom = newRoom;
        }
    }
Ejemplo n.º 3
0
 private void CreateRoom(Vector2 pos, Room roomPrefab)
 {
     currentRoom = new GraphRoom();
     currentRoom.pos.Set(pos.x, pos.y);
     currentRoom.roomsConnected = new List <GraphRoom>(roomPrefab.exits.Count);
     currentRoom.roomPrefab     = roomPrefab;
     graph.Add(currentRoom);
     firstDepthGrag.Add(currentRoom);
     MarkMapWithRoom(pos, roomPrefab.size);
     //Debug.Log(roomPrefab.type);
 }
    private void OnPlayerEnterRoom(object roomObj)
    {
        GraphRoom room = (GraphRoom)roomObj;

        if (!exploredRooms.Contains(room))
        {
            exploredRooms.Add(room);
            if (exploredRooms.Count >= roomsNeededNb)
            {
                Unlock();
            }
        }
    }
Ejemplo n.º 5
0
    public void OnGraphCreated(object graphObject)
    {
        List <GraphRoom> graph = (List <GraphRoom>)graphObject;

        for (int i = 0; i < graph.Count; i++)
        {
            currentPos.Set(graph[i].pos.x * roomBaseSize.x, graph[i].pos.y * roomBaseSize.y, 0);
            currentSize.Set(roomBaseSize.x * graph[i].roomPrefab.size.x, roomBaseSize.y * graph[i].roomPrefab.size.y);

            currentRoom = Instantiate(roomPrefab, roomsParent) as RectTransform;
            if (graph[i].roomPrefab.type == RoomType.TREASURE)
            {
                Instantiate(treasureIconPrefab, currentRoom.transform, false);
            }
            else if (graph[i].roomPrefab.type == RoomType.BOSS)
            {
                Instantiate(bossIconPrefab, currentRoom.transform, false);
            }
            else if (graph[i].roomPrefab.type == RoomType.SPECIAL)
            {
                Instantiate(specialIconPrefab, currentRoom.transform, false);
            }

            currentRoom.localPosition = currentPos;
            currentRoom.sizeDelta     = currentSize;

            rooms.Add(graph[i], currentRoom.gameObject);

            for (int j = 0; j < graph[i].roomPrefab.exits.Count; j++)
            {
                Exit      exit         = graph[i].roomPrefab.exits[j];
                int       x            = (int)(graph[i].pos.x + exit.pos.x);
                int       y            = (int)(graph[i].pos.y + exit.pos.y);
                GraphRoom adjacentRoom = dungeon.GetRoomFromMapIndex(x, y);

                if (adjacentRoom != null && adjacentRoom.roomPrefab.exits.Exists(adjExit => Exit.AreExitsConnected(exit, adjExit, graph[i], adjacentRoom)))
                {
                    currentExitPos.Set(Mathf.Max(0, exit.pos.x) * roomBaseSize.x + 0.5f * roomBaseSize.x * Mathf.Abs(exit.dir.y), Mathf.Max(0, exit.pos.y) * roomBaseSize.y + 0.5f * roomBaseSize.y * Mathf.Abs(exit.dir.x), 0);
                    currentExitSize.Set(roomBaseSize.y * (0.10f + 0.38f * Mathf.Abs(exit.dir.y)), roomBaseSize.y * (0.10f + 0.38f * Mathf.Abs(exit.dir.x)));

                    currentExit = Instantiate(exitPrefab, currentRoom.transform) as RectTransform;
                    currentExit.localPosition = currentExitPos;
                    currentExit.sizeDelta     = currentExitSize;
                }
            }

            currentRoom.gameObject.SetActive(showAllRoomsAtStart);
        }
    }
Ejemplo n.º 6
0
    private void GetUnconnectedExit()
    {
        List <int> exitsTocheck = new List <int>();

        exitsTocheck.AddRange(System.Linq.Enumerable.Range(0, currentRoom.roomPrefab.exits.Count));
        while (exitsTocheck.Count > 0)
        {
            int selectedIndex = exitsTocheck[Random.Range(0, exitsTocheck.Count)];
            currentExit = currentRoom.roomPrefab.exits[selectedIndex];
            int x = (int)(currentRoom.pos.x + currentExit.pos.x);
            int y = (int)(currentRoom.pos.y + currentExit.pos.y);

            if (x >= 0 && x < gameData.worldSize.x && y >= 0 && y < gameData.worldSize.y && !map[x, y].notBuildableFlag)
            {
                GraphRoom nextRoom = map[x, y].room;
                if (nextRoom == null)
                {
                    return;
                }
                else if (!currentRoom.roomsConnected.Contains(nextRoom) || !nextRoom.roomsConnected.Contains(currentRoom))
                {
                    int wantedExitPosX = x + (int)currentExit.dir.x * -1;
                    int wantedExitPosY = y + (int)currentExit.dir.y * -1;

                    for (int i = 0; i < nextRoom.roomPrefab.exits.Count; i++)
                    {
                        int exitX = (int)(nextRoom.pos.x + nextRoom.roomPrefab.exits[i].pos.x);
                        int exitY = (int)(nextRoom.pos.y + nextRoom.roomPrefab.exits[i].pos.y);

                        if (wantedExitPosX == exitX && wantedExitPosY == exitY)
                        {
                            currentRoom.roomsConnected.Add(nextRoom);
                            nextRoom.roomsConnected.Add(currentRoom);
                        }
                    }
                }
            }

            exitsTocheck.Remove(selectedIndex);
        }

        ReturnToPreviousRoom();
        if (firstDepthGrag.Count > 1)
        {
            GetUnconnectedExit();
        }
    }
Ejemplo n.º 7
0
    void FixedUpdate()
    {
        if (dungeon != null)
        {
            GraphRoom newRoom = dungeon.GetRoomFromPosition(_transform.position);
            if (newRoom != null && newRoom != currentRoom)
            {
                currentRoom = newRoom;

                Transform enemiesParent = newRoom.roomInstance.enemiesParent;
                if (enemiesParent != null && enemiesParent.childCount > 0)
                {
                    _transform.parent = newRoom.roomInstance.enemiesParent.GetChild(0);
                }
            }
        }
    }
Ejemplo n.º 8
0
    private void OnPlayerEnterRoom(object roomObject)
    {
        GraphRoom         room           = (GraphRoom)roomObject;
        List <GameObject> newActiveRooms = new List <GameObject>();

        int        endX = (int)(room.pos.x + room.roomPrefab.size.x);
        int        endY = (int)(room.pos.y + room.roomPrefab.size.y);
        GameObject testRoom;

        for (int i = (int)room.pos.x - 1; i <= endX; i++)
        {
            for (int j = (int)room.pos.y - 1; j <= endY; j++)
            {
                if (i >= 0 && i < gameData.worldSize.x && j >= 0 && j < gameData.worldSize.y && map[i, j].room != null)
                {
                    testRoom = map[i, j].room.roomInstance.gameObject;

                    if (!activeRooms.Contains(testRoom))
                    {
                        testRoom.SetActive(true);
                        activeRooms.Add(testRoom);
                    }
                    if (!newActiveRooms.Contains(testRoom))
                    {
                        newActiveRooms.Add(testRoom);
                    }
                }
            }
        }

        for (int i = activeRooms.Count - 1; i >= 0; i--)
        {
            if (!newActiveRooms.Contains(activeRooms[i]))
            {
                activeRooms[i].SetActive(false);
                activeRooms.RemoveAt(i);
            }
        }
    }
Ejemplo n.º 9
0
    IEnumerator InstantiateRooms()
    {
        for (int i = 0; i < graph.Count; i++)
        {
            roomWorldPos.Set(graph[i].pos.x * gameData.roomBaseSize.x, graph[i].pos.y * gameData.roomBaseSize.y, 0);
            graph[i].roomInstance = Instantiate(graph[i].roomPrefab, roomWorldPos, Quaternion.identity, roomsParent[map[(int)graph[i].pos.x, (int)graph[i].pos.y].zoneType]) as Room;
            graph[i].roomInstance.gameObject.SetActive(showRoomsAtInstantiation);

            if (graph[i].pos.y == 0)
            {
            }

            for (int j = 0; j < graph[i].roomInstance.exits.Count; j++)
            {
                Exit      exit         = graph[i].roomPrefab.exits[j];
                int       x            = (int)(graph[i].pos.x + exit.pos.x);
                int       y            = (int)(graph[i].pos.y + exit.pos.y);
                GraphRoom adjacentRoom = GetRoomFromMapIndex(x, y);

                if (adjacentRoom == null || !adjacentRoom.roomPrefab.exits.Exists(adjExit => Exit.AreExitsConnected(exit, adjExit, graph[i], adjacentRoom)))
                {
                    float      angle   = exit.dir.x * 90 + (exit.dir.y == 1 ? 180 : 0);
                    Vector3    pos     = new Vector3(Mathf.Max(0, exit.pos.x) * gameData.roomBaseSize.x + 0.5f * gameData.roomBaseSize.x * Mathf.Abs(exit.dir.y), Mathf.Max(0, exit.pos.y) * gameData.roomBaseSize.y + 0.5f * gameData.roomBaseSize.y * Mathf.Abs(exit.dir.x), 0);
                    GameObject exitObj = Instantiate(exitBlock, roomWorldPos + pos, Quaternion.Euler(0, 0, angle), graph[i].roomInstance.transform) as GameObject;
                    exitObj.GetComponent <SpriteRenderer>().material = roomsMaterials[graph[i].roomPrefab.zoneIndex];
                }
            }

            if (secondsBetweenInstanciation > 0)
            {
                yield return(new WaitForSecondsRealtime(secondsBetweenInstanciation));
            }
        }

        yield return(null); // makes sure all the starts have been called;

        EventDispatcher.DispatchEvent(Events.GAME_LOADED, null);
    }
Ejemplo n.º 10
0
    private void OnPlayerEnterRoom(object roomObj)
    {
        GraphRoom room = (GraphRoom)roomObj;

        rooms[room].SetActive(true);
    }
Ejemplo n.º 11
0
 public static bool AreExitsConnected(Exit exit, Exit adjacent, GraphRoom room, GraphRoom adjRoom)
 {
     return((adjacent.dir.x != 0 && adjacent.dir.x == -exit.dir.x && adjRoom.pos.y + adjacent.pos.y == room.pos.y + exit.pos.y) ||
            (adjacent.dir.y != 0 && adjacent.dir.y == -exit.dir.y && adjRoom.pos.x + adjacent.pos.x == room.pos.x + exit.pos.x));
 }