mbkarle / mind-the-fog

Roguelike JavaScript game--mind the fog!
2 stars 1 forks source link

Rooms and Doors 2.0 #103

Open akarle opened 7 years ago

akarle commented 7 years ago

We need a major rehaul of the room system to provide a 2D map #76. Our game plan is the following:

Changes needed to be made:

  1. How to detect which door you are on (currently we use the avatarX position). Possible solution: door has a property position = 'left', 'right', etc...
  2. How to spawn on interacting with door. Currently this is an issue because we spawn on room_entry which is a room property, it should be a door property
  3. We need to work on randomizing the generation of the rooms. To do this, we settled on using an undirected graph of rooms:

Store the graph (of rooms) as an adjacency list (list of lists). ie: [[2],[1,3],[2]] means room 1 has a door to 2, room 2 has doors to 1 and 3, etc

In order to randomize this process, use a round robin type of simple algorithm:

rooms = list of all rooms on the floor
rooms_avail = rooms
while(!isempty(rooms_avail)
    for r in rooms:
        edges = rooms[r]
        pick room from rooms_avail
                add room to edges
                add r to room's edges
                if either has 4 edges, remove from rooms_avail
akarle commented 7 years ago

Update: after much consideration, this method does not work.

We decided upon a jigsaw like method where you:

  1. randomly start with a room size in a grid (grid size dependent on floor tier)
  2. maintain a possible list of doors that could be expanded
    • note here that the doors must from now on be hardcoded in each room size
  3. randomly pick a door to expand, pass it to a function getPossRooms4ExpBasedOnGrid or whatever, which will in turn return a list of room sizes that could be added and which doors should be connected so that the new room fits in the grid bounds and does not overlap current rooms
  4. Update the list of expandable doors (if removing any due to covering them w a new room, have a chance that a door appears between the rooms), add new exp doors.
  5. Update the current floor capacity (floors should have a certain number of grid spaces occupied)
  6. Repeat 3-5 until you run out of capacity

We also need some way to display this grid upon request, both for users and for us to debug!

Most work should be done in Floor.js I think