Esempio n. 1
0
    // checks to see that the room added does not conflict with other rooms
    private static bool newConflicts(FinalRoom add, Vector2 lb, Vector2 rt)
    {
        Vector2 addPosition   = add.getPosition();
        Vector2 addDimensions = add.getRoom().getDimensions();

        if (addPosition.x > rt.x || addPosition.x < lb.x || addPosition.y > rt.y || addPosition.y < lb.y)
        {
            return(true);
        }

        foreach (FinalRoom b in finalArea)
        {
            Vector2 bPosition   = b.getPosition();
            Vector2 bDimensions = b.getRoom().getDimensions();
            if (addPosition.y + addDimensions.y / 2 > bPosition.y - bDimensions.y / 2 &&
                addPosition.y - addDimensions.y / 2 < bPosition.y + bDimensions.y / 2)
            {
                if (addPosition.x + addDimensions.x / 2 > bPosition.x - bDimensions.x / 2 &&
                    addPosition.x - addDimensions.x / 2 < bPosition.x + bDimensions.x / 2)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Esempio n. 2
0
    private FinalRoom createRandomFinalRoom(List<ConcreteRoom> createdRooms, List<Vector2> candidateNeighbors, List<Vector2> lastInsertedNeighbors , float linearFactor, Dungeon dungeon)
    {
        Vector2 pivot = getRandomNeighbor(candidateNeighbors, lastInsertedNeighbors, linearFactor);
        FinalRoom auxRoom = new FinalRoom((int)pivot.x, (int)pivot.y, dungeon.width, dungeon.height);

        //don't allow duplicate room creation
        while(createdRooms.IndexOf(auxRoom) >= 0)
        {
            pivot = getRandomNeighbor(candidateNeighbors, lastInsertedNeighbors, linearFactor);
            auxRoom = new FinalRoom((int)pivot.x, (int)pivot.y, dungeon.width, dungeon.height);
        }

        return auxRoom;
    }
Esempio n. 3
0
    private void Start()
    {
        // 10x5 "room"
        Dictionary <Room.Direction, List <Room> > test = new Dictionary <Room.Direction, List <Room> >();
        Room group = new Room(new Vector2(10, 5), test, GO);

        test.Add(Room.Direction.UP, new List <Room>());
        test.Add(Room.Direction.RIGHT, new List <Room>());

        // 5x10 "room"
        Dictionary <Room.Direction, List <Room> > test1 = new Dictionary <Room.Direction, List <Room> >();
        Room group11 = new Room(new Vector2(5, 10), test, GO1);

        test1.Add(Room.Direction.UP, new List <Room>());
        test1.Add(Room.Direction.RIGHT, new List <Room>());

        // 5x5 "room"
        Dictionary <Room.Direction, List <Room> > test2 = new Dictionary <Room.Direction, List <Room> >();
        Room group22 = new Room(new Vector2(5, 5), test, GO2);

        test2.Add(Room.Direction.UP, new List <Room>());
        test2.Add(Room.Direction.RIGHT, new List <Room>());

        // possible room connections declaration
        test[Room.Direction.UP].Add(group);
        test[Room.Direction.UP].Add(group22);
        test[Room.Direction.RIGHT].Add(group);
        test[Room.Direction.RIGHT].Add(group11);
        test[Room.Direction.UP].Add(group);

        test1[Room.Direction.UP].Add(group11);
        test1[Room.Direction.UP].Add(group);
        test1[Room.Direction.RIGHT].Add(group22);

        container = GameObject.Find("Container");
        FinalRoom        startingBlock = new FinalRoom(group, new Vector2(100, 2));
        List <FinalRoom> x             = Create.newCreateArea(startingBlock, new Vector2(100, 2), new Vector2(150, 20));

        NewInstantiate(x);

        // OLD CODE; this completely and randomly generates an area of platforms to climb through, not proceduraly generated
        //List<Block> x = Create.createArea(new Block(new Vector2(-270,-270),1), new Vector2(-270, 1), new Vector2(-240, 30));
        //Instantiate(x);
    }
Esempio n. 4
0
    /*
     * populates the area given by lb and rt, for room exploration
     */
    public static List <FinalRoom> newCreateArea(FinalRoom parent, Vector2 lb, Vector2 rt, List <FinalRoom> centralPieces = null, int size = 2)
    {
        finalArea.Add(parent);
        if (finalArea.Count > size)
        {
            return(finalArea);
        }
        if (centralPieces != null)
        {
            foreach (FinalRoom b in centralPieces)
            {
                finalArea.Add(b);
            }
        }

        Vector2     parentPosition     = parent.getPosition();
        Vector2     parentDimensions   = parent.getRoom().getDimensions();
        List <Room> rightPossibleRooms = parent.getRoom().getRooms(Room.Direction.RIGHT);
        int         randomIndex;

        if (rightPossibleRooms.Count > 0)
        {
            randomIndex = Random.Range(0, rightPossibleRooms.Count);
            print(randomIndex);
            Room    rightChild      = rightPossibleRooms[randomIndex];
            Vector2 childDimensions = rightChild.getDimensions();
            print(parentPosition);
            print(parentDimensions);
            print(childDimensions);
            print(parentPosition.x + parentDimensions.x / 2 + childDimensions.x / 2);
            FinalRoom rightRoom = new FinalRoom(rightChild,
                                                new Vector2(parentPosition.x + parentDimensions.x / 2 + childDimensions.x / 2,
                                                            parentPosition.y - parentDimensions.y / 2 + childDimensions.y / 2));
            if (!newConflicts(rightRoom, lb, rt))
            {
                newCreateArea(rightRoom, lb, rt);
            }
        }

        List <Room> upPossibleRooms = parent.getRoom().getRooms(Room.Direction.UP);

        if (upPossibleRooms.Count > 0)
        {
            randomIndex = Random.Range(0, upPossibleRooms.Count);
            print(randomIndex);
            Room    upChild         = upPossibleRooms[randomIndex];
            Vector2 childDimensions = upChild.getDimensions();
            print(parentPosition);
            print(parentDimensions);
            print(childDimensions);
            print(parentPosition.y + parentDimensions.y / 2 + childDimensions.y / 2);
            FinalRoom upRoom = new FinalRoom(upChild,
                                             new Vector2(parentPosition.x - parentDimensions.x / 2 + childDimensions.x / 2,
                                                         parentPosition.y + parentDimensions.y / 2 + childDimensions.y / 2));
            if (!newConflicts(upRoom, lb, rt))
            {
                newCreateArea(upRoom, lb, rt);
            }
        }

        return(finalArea);
    }
Esempio n. 5
0
        public WorldBuilder()
        {
            // Create Rooms
            var room1 = new StartRoom(
                "The Room",
                "I'm inside a small room with bad lighting, I can see a door, maybe I can open it?",
                "There's a key and a note on the ground!");

            var room2 = new Hallway(
                "Hallway",
                "A small hallway with cement covered walls, the air is damp. I think I'm in a cellar?\n" +
                "There is a path leading to the left, it looks dark. There's also a path leading to the right.",
                "");

            var room3Right = new JanitorsRoom(
                "Janitor's Room",
                "It's a small room, quite messy, it smells like gasoline. I see a painting of an old man with a handle bar mustasch.\n" +
                "I can't see any exits here besides the way I came from.",
                "");

            var room4Left = new FinalRoom(
                "Final Room",
                "It's a small room with walls covered in moist, I can see a door with a codelock next to it.",
                "There's nothing here except the door...");

            // Create Items
            var roomKey = new Item(
                "Room Key",
                "It looks like it could fit to this door.",
                1,
                "The key is old and rusty, it looks fragile.");

            var note = new Note(
                "Note",
                "A piece of paper with something written on it.",
                0,
                "A piece of paper with something written on it.");

            var bottle = new Bottle(
                "Bottle of Kerosene",
                "It's commonly used to power jet engines.",
                2,
                "A bottle of kerosene, it's very flammable.");

            var rags = new Rags(
                "Rags",
                "Some old clothes ripped apart.",
                2,
                "I think this used to be a shirt...");

            var broom = new Broom(
                "Broom",
                "A regular broom used to cleaning.",
                5, "It's a broom, what more do you need to know?");

            var painting = new Item(
                "Painting",
                "A painting of Mr.X?",
                0,
                "The painting is signed by Mr X." +
                " There seems to be missing a piece of the painting.",
                false);

            var rocks = new Rock(
                "Pile of Rocks",
                "It's a pile of rocks.",
                7,
                "A large pile of small rocks, almost as someone placed them there? Maybe I can move them.",
                false);


            // Create Exit Points
            var roomExit = new Door(
                room2,
                1,
                true,
                false,
                "Rooms Door",
                "You hear a crack... the door is unlocked! Oh... the key broke in half.",
                "The door is locked, maybe there's a key somewhere?",
                "A brown wooden door with a sturdy lock.");

            var room2RightExit = new RightOfHallway(
                room3Right,
                2,
                false,
                false,
                "Right",
                "",
                "",
                ""
                );

            var room2LeftExit = new LeftOfHallway(
                room4Left,
                10,
                true,
                false,
                "Left",
                "Finally some light! I can now see where I'm going.",
                "I can't go that way, it's too dark. I need some light...",
                "It's just a dark passage..."
                );

            var finalRoomExit = new FinalDoor(
                11,
                true,
                false,
                "Codelock Door",
                "Success! The door is unlocked, let's get out of here!",
                "The door is locked. There's a codelock to it. I need to find that code!",
                "A big iron door with a codelock next to it."
                );

            // Add exits to room sists
            room1.Exit.Add(roomExit);
            room2.Exit.Add(new Door(
                               room1,
                               1,
                               false,
                               false,
                               "Rooms Door",
                               "",
                               "",
                               "That's the door I came from. The key is still stuck inside the lock, whoops!"));
            room2.Exit.Add(room2RightExit);
            room2.Exit.Add(room2LeftExit);

            room3Right.Exit.Add(new Exit(
                                    room2,
                                    2,
                                    false,
                                    false,
                                    "Left",
                                    "",
                                    "",
                                    ""));

            room4Left.Exit.Add(new Exit
                                   (room2,
                                   2,
                                   false,
                                   false,
                                   "Right",
                                   "",
                                   "",
                                   ""));
            room4Left.Exit.Add(finalRoomExit);

            // Add items to room inventory
            room1.RoomInventory.Add(roomKey);
            room1.RoomInventory.Add(note);

            room2.RoomInventory.Add(rocks);

            room3Right.RoomInventory.Add(bottle);
            room3Right.RoomInventory.Add(rags);
            room3Right.RoomInventory.Add(broom);
            room3Right.RoomInventory.Add(painting);

            // Add all instances of rooms to property Rooms
            Rooms.Add(room1);
            Rooms.Add(room2);
            Rooms.Add(room3Right);
        }