Procedural map generation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
BrotSagtMist
Party member
Posts: 655
Joined: Fri Aug 06, 2021 10:30 pm

Re: Procedural map generation

Post by BrotSagtMist »

Uhhh? Of what?
obey
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

BrotSagtMist wrote: Tue Dec 13, 2022 4:59 pm Uhhh? Of what?
The lines mentioned before
User avatar
BrotSagtMist
Party member
Posts: 655
Joined: Fri Aug 06, 2021 10:30 pm

Re: Procedural map generation

Post by BrotSagtMist »

You can just open the file and look at it...
Its a zip.
obey
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

BrotSagtMist wrote: Tue Dec 13, 2022 4:34 pm At this point i am really sorry this code is so hard to read (i wrote that in a day).
But the concept i explained above are basically just lines 258-299 in that main.lua file.
There is nothing more to it.
Just found the functions, I dont understand them but can i just say damn its impressive you did this in one day

Code: Select all

function Makelab(s)
 local x = math.random(Tilesx-5)+5
 local y = math.random(Tilesy-5)+5
 if not (Lab[x][y-1] or Lab[x+1][y] or Lab[x][y+1] or Lab[x-1][y]) then
  Lab[x][y]=s
  local r
  for z = 1, 500 do
   local d = math.random(STRAIGHT)
   if d == 1 then
    if not (Lab[x-1][y-1] or Lab[x+1][y-1]) then y=y-1 r=d end
   elseif d == 2 then
    if not (Lab[x+1][y-1] or Lab[x+1][y+1]) then x=x+1 r=d end
   elseif d == 3 then
    if not (Lab[x-1][y+1] or Lab[x+1][y+1]) then y=y+1 r=d end
   elseif d == 4 then 
    if not (Lab[x-1][y-1] or Lab[x-1][y+1]) then x=x-1 r=d end
   else 
    if r == 1 then
     if not (Lab[x-1][y-1] or Lab[x+1][y-1]) then y=y-1 end
    elseif r == 2 then
     if not (Lab[x+1][y-1] or Lab[x+1][y+1]) then x=x+1 end
    elseif r == 3 then
     if not (Lab[x-1][y+1] or Lab[x+1][y+1]) then y=y+1 end
    elseif r == 4 then
     if not (Lab[x-1][y-1] or Lab[x-1][y+1]) then x=x-1 end
    end 
   end
   Lab[x][y]=s 
  end
 else
  return
 end
end
function fork(x,y)
 Lenght=Lenght+1
 Street[x][y]=Lenght
 Valids[Lenght]={x=x,y=y}
 if Lab[x][y-1] and not Street[x][y-1] then fork(x,y-1) end
 if Lab[x+1][y] and not Street[x+1][y] then fork(x+1,y) end
 if Lab[x][y+1] and not Street[x][y+1] then fork(x,y+1) end
 if Lab[x-1][y] and not Street[x-1][y] then fork(x-1,y) end
end
User avatar
BrotSagtMist
Party member
Posts: 655
Joined: Fri Aug 06, 2021 10:30 pm

Re: Procedural map generation

Post by BrotSagtMist »

Yea, jam code is not really meant to be reused, its jammed together.
But to pinpoint the process here:
Have a function walk through the map from one point to wherever its ruleset allows it to walk and save that not only in the map but a second table.
That table _is Street_ in my example.
The ruleset being: step is valid if new step is not surrounded by floor except in the direction we came from.
And we go for example 60% forward, 20% left/right to get a good walkable street.
And then the trick behind it is that Street does not only contain valid points to place your items on but also shows where to place them, with the first and latest entry being furthest away from each other, how big the map is playwise and it contains a valid path so that you can place enemies without the need of pathfinding.
And to make it a labyrinth you start forking from Street using a _contain walls left and right_ ruleset.
obey
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

BrotSagtMist wrote: Wed Dec 14, 2022 3:46 pm Yea, jam code is not really meant to be reused, its jammed together.
But to pinpoint the process here:
Have a function walk through the map from one point to wherever its ruleset allows it to walk and save that not only in the map but a second table.
That table _is Street_ in my example.
The ruleset being: step is valid if new step is not surrounded by floor except in the direction we came from.
And we go for example 60% forward, 20% left/right to get a good walkable street.
And then the trick behind it is that Street does not only contain valid points to place your items on but also shows where to place them, with the first and latest entry being furthest away from each other, how big the map is playwise and it contains a valid path so that you can place enemies without the need of pathfinding.
And to make it a labyrinth you start forking from Street using a _contain walls left and right_ ruleset.
Hi brot, so after messing around with flood fill and pathfinding what I found out was that the chance of a working map being generated was so low that that the system would get stack overflow bugged long before it could get a good map, so what Im trying to do now is make better map generation, Ive tried some maze generation algorithms but theyre pretty hard to understand lol, you got any advice?
User avatar
BrotSagtMist
Party member
Posts: 655
Joined: Fri Aug 06, 2021 10:30 pm

Re: Procedural map generation

Post by BrotSagtMist »

Stop doing the opposite of what i tell you to do.
obey
User avatar
darkfrei
Party member
Posts: 1195
Joined: Sat Feb 08, 2020 11:09 pm

Re: Procedural map generation

Post by darkfrei »

If you want to get result trough mazes, try to understand my old mod for Factorio:
(control.lua only)
https://mods.factorio.com/mod/Mazing
a58646e25aa00b54fff890d17a4d64392614e79e.png
a58646e25aa00b54fff890d17a4d64392614e79e.png (24.08 KiB) Viewed 1833 times
Attachments
Mazing_1.1.4.zip
(5.45 KiB) Downloaded 96 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

BrotSagtMist wrote: Wed Dec 14, 2022 5:15 pm Stop doing the opposite of what i tell you to do.
Im not sure what you mean
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

darkfrei wrote: Wed Dec 14, 2022 8:47 pm If you want to get result trough mazes, try to understand my old mod for Factorio:
(control.lua only)
https://mods.factorio.com/mod/Mazing

a58646e25aa00b54fff890d17a4d64392614e79e.png
Ill check it out thank you!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests