Log In  


Hi

I am making a roguelike and i would like to add in procedural generation of rooms. I would have prebuilt rooms in the map editor and when the character goes below, above, left or right of the current room, it would take them to a new room with which that entry was possible. I can do this ok apart from one thing:

How do i store the layout of the rooms once you go into a new room? If it was just left and right i would make a list of the coordinates of the rooms and when the player goes to the right, a new random room would be appended at the end, if it is to the left then at the beginning. Though this doesn't work when i have up and down too. How do i store the coordinates of the rooms that the player has already been in is my question.

I would appreciate some help

Thanks



store ‘generated’ rooms in a pseudo 2d array:
generated_maps[cellx + celly*16]={mx,my}

where cellx/y are coordinates of the map in the world.
in my example, the world can be 16x16 map ‘cells’


@freds72 Sounds right, but could you perhaps elaborate on it a little as im new to this so i don't really understand how that works. Thanks


Sample cart:

  • world is up to 16x16 cells (e.g. 'map's)
  • each time player goes into a cell that has not been allocated, a random map (from a set of 4 is picked up)
  • the correct map is displayed according to player's position (e.g. the cell he is in)
  • the minimap displays what cells have already been allocated (white) and where the player is (red)

Enjoy!

Cart #jototeneyu-0 | 2020-06-02 | Code ▽ | Embed ▽ | No License


@freds72 Thank you for the cart. I am slightly confused on the

local cell=(_x\16)+16*(_y\16)

as surely 16*(_y/16) is always just equal to _y. Am i missing something?


@freds72 Your cart works, but i am very confused as im not using the tile based coordinates and also i cant seem to make how you have moved the player to work with my game. Is it possible if you could perhaps rewrite the cart but much more simple for beginners like me. Sorry, and its fine if not but i just cant get it to work.
Thanks


x\y is the integer division (same as flr(x/y))
so:
18\16 = 1
16*(18\16) = 16

Hu... I tried to have as little obscure code as possible.
Not sure what I can simplify - suggest to start with a 1 room game and come back to this world idea later!



[Please log in to post a comment]