Random Generation

     Designing the randomly generating rooms was quite simple to begin with. I had created the base starting room the player would begin in. This room would be placed in the game map, and be the starting point with which the randomly generated rooms would chain off of. A box collision was set in front of every door that would spawn in the next room at a specific vector relative to the vector of the current room.

      However, in order to pull off our original intention of difficulty adjustment and a final boss, we needed to make the room generation form a diamond shape.

     Here we have the starting room, this blueprint actor is the only thing placed in the actual game map. This actor generates all of the random rooms for the play session.

     At the start of the game, the starting room runs two functions- Level Math and Generation. In order to create the diamond shape, the "Midpoint" must be found. A midpoint can only exist if the number of spawned rows is odd (which is set by difficulty), and all this is checked in Level Math.

Capture3.PNG

     Over in the Generation function, we build our entire game. We start by setting the first spawn point for the first room, and create loops that generate rooms from row to row. We also increase difficulty per row, which I'll cover later.

Capture1.PNG

     For each loop, we spawn a new blueprint "BP Room Generator" in the X and Y location we choose for the next room. I will cover that blueprint later. After the blueprint is spawned, we add a float value to Y to spawn another room to the right if the loop continues, and add 1 to the rooms spawned.

Capture2.PNG

     When the loop is completed, we add 1 to spawned rows, reset the count of rooms spawned, and check if we have reached the midpoint. If we haven't, we keep increasing the number of rooms per row. If we have, we keep decreasing the number of rooms per row.

Capture3.PNG

     This method worked efficiently for us. As you can see in the image below, all the BP Room Generators spawned correctly in a diamond shape. The rooms do not actually generate until the player gets close enough to a door to activate it. A system was set up to activate rooms ahead and destroy rooms behind.

     Over in the Room Generator blueprint we spawned, we have a lot of different things going on. I will use the image below as I explain how it works.

     When the player overlaps either of the green trigger boxes (Trigger_BR, Trigger_BL) while in the previous room. it makes all the doors for this room visible (they are spawned immediately but hidden). A random room is chosen to be spawned at the origin point of the spawner (visually represented by a trigger box called "Marker"). There is a one second wait before spawning enemies, which we will cover next, and then the doors to enter the room open. Both sets of rear doors open because you would never see the other side opening anyway.

     To spawn enemies, first the amount of enemies to spawn must be determined. A random amount between 1 and 3 is added to the Room Level I mentioned earlier giving the total number of enemies. Then a loop begins that spawns random enemies in the yellow trigger box until the amount necessary for the room is met.

      When the player enters either of the black triggers, the doors behind them close. They are stuck in the room until all enemies are defeated.

      When an enemy is killed, it creates a sphere trace that messages "UpdateKillCount" to the overlapping room. 1 kill is added to the count, and a print string notifies the player of the total enemies spawned and total enemies killed. If enough enemies are killed, the room is completed.

      When the player overlaps the blue triggers, the doors open up as long as the room is completed and the player passes through to the next room. Once the player hits the red trigger boxes, the actor/room is destroyed to optimize game performance.

      This is a recording taken after a few little additions to the random generation. Leo's weapon system is demonstrated here as well.