I have come to rely on Jumper for a lot of essential functions within “Segreta”, the roguelite I’ve been working on off and on for the last year or so. I don’t really mind leaning on the Jumper lib, mostly because it provides useful shortcuts to simple problems with regards to pathfinding, which are always bountiful when dealing with the roguelike genre.
For instance, Jumper is terrific for creating a path from spawnpoint to endpoint. The general concept is that, during level generation, every room has a door to every connected room. Before obstacle population, random rooms are chosen from within a function leveraging Jumper, checking to confirm that the rooms are accessible from the spawnpoint of the player:
function scene.buildStairStackDown() scene.directionComplete = 1 local function setDownStairInt() scene.randomStairDown = scene.randCall(2,#scene.pathMarkerY-1) if scene.randomStairDown == scene.randomStair then scene.buildStairStackDown() return true end end setDownStairInt() scene.callNewPath(scene.pathMarkerX[scene.randomStairDown],scene.pathMarkerY[scene.randomStairDown],scene.pathMarkerX[scene.randomStair],scene.pathMarkerY[scene.randomStair],scene.directionComplete) if scene.directionComplete == 2 then scene.buildStairStackDown() return true end scene.createDownStair() end
If the random room is not accessible, then the function gets called again until a valid room is found to place the endpoint.
I was finding that the most simple approach to this solution was allowing the spawnpoints and endpoints to potentiall be far too close to each other. To allow for more challange and complexity to gameplay, I made sure to include a threshold for the length of the path. That way, I will be able to keep the rooms far enough apart that it feels like an actual search to find them.
After the exit path is routed and set, the path “tiles” are locked and no impenetrable obstacles are placed on them, while destructible environments are fair game.
PS. I think I’m going to make development posts a regular thing.