Last active
December 29, 2023 11:29
-
-
Save Achie72/36c963754d779398c43d20d27f1204b0 to your computer and use it in GitHub Desktop.
Crumbling Crypt - PICO-8 Map Generation with a digger/walker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- General walker for dungeon template generation | |
-- Made for Crumbling Crypt: https://ko-fi.com/Post/Crumbling-Crypt-1--A-minimalist-Roguelike-B0B1SPL7E | |
function generate_dungeon() | |
-- random walker on an 8x8 grid on map | |
-- set rooms to 1 if there should be something | |
-- move randomly on if we are good | |
local roomNumber = 4+flr(player.level/2) | |
local xStart,yStart = flr(rnd(8)),flr(rnd(8)) | |
mset(xStart,yStart,1) | |
-- init the dungeon with a starer point | |
local diggerX, diggerY = xStart, yStart | |
-- select a direction to dig to | |
local dir = rnd({1,2,3,4}) | |
-- offset tables for the directions, left, right, up, down | |
local dirTable = {{-1,0}, {1,0}, {0,-1}, {0, 1}} | |
-- dig | |
while (number_of_rooms() < roomNumber) do | |
-- randomly turn into a new direction | |
turn_chance = 0.25 | |
if rnd() < turn_chance then | |
dir = rnd({1,2,3,4}) | |
end | |
-- calc new position that the digger would go to | |
local newX, newY = diggerX+dirTable[dir][1],diggerY+dirTable[dir][2] | |
-- check if it is inside the map | |
while ((newX < 0) or (newX > 7) or (newY < 0) or (newY > 7)) do | |
-- if not, find a new direction, check that | |
dir = rnd({1,2,3,4}) | |
newX, newY = diggerX+dirTable[dir][1],diggerY+dirTable[dir][2] | |
end | |
-- set the new room | |
mset(newX, newY, 1) | |
-- set the new digger pos | |
diggerX,diggerY = newX,newY | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made for Crumbling Crypt: https://ko-fi.com/Post/Crumbling-Crypt-1--A-minimalist-Roguelike-B0B1SPL7E