Procedural world generation experiment

developing/porting a new game or gaming framework? post in here!
Post Reply
gfoot
Posts: 987
Joined: Tue Apr 14, 2020 9:05 pm
Contact:

Procedural world generation experiment

Post by gfoot »

After playing Exile a bit, I got interested in making some form of procedural world generator. This is where I got to so far:

Demo video: https://youtu.be/AuF9cMaVBsg

Disc image: (Shift-Break to load, Z X * ? to scroll around)
pgg.zip
(4.16 KiB) Downloaded 20 times
Screenshots:
pgg2.PNG
pgg4.PNG
I heard that Exile does it mostly based on just the X,Y coordinate of the target square - I didn't want to study its algorithm as I wanted to just try my own way, and learn more that way, but I wanted to do something vaguely similar, i.e. not requiring a large amount of memory to block out the whole world up front or anything like that.

I started prototyping a bit in BASIC with algorithms that randomly chose which cells were solid or not, subject to certain constraints, trying to get something that produced interesting patterns with enough connectivity but not too much. That was pretty effective, but a bit slow so I switched to Shadertoy to prototype more efficiently. This let me quickly render at different scales, scroll around in real time, and I added a second pass to the algorithm to round off some edges for a more organic look, and to allow passage between diagonally-adjacent cells.
pgg3.PNG
Shadertoy was great for this, if somewhat overkill. I took some care to stick to operations that are efficient in 6502 assembler, so that it would translate well.

As that was working pretty well, I started coding for the Beeb - cross-assembling using xa. My general plan was to make something that works a bit like the Repton games - with a square playfield, hardware scrolling, MODE 5, 4x4 character tiles. As it scrolls it draws rows/columns of characters at the edge, this isn't currently quite fast enough to happen within the vertical blanking interval. It also regenerates the world in the vicinity of the screen, covering about twice as much as the visible area - this is very redundant, just a proof of concept, and ultimately it should only regenerate the bits that are about to scroll on.

The procedural generation actually occurs in two passes, and it does use a couple of arrays. The screen is filled by an 8x8 grid of "fine" tiles. The first pass of procedural generation happens a couple of levels coarser - it considers each coarse region of 4x4 fine tiles, deciding whether each quarter of the region (a "medium" tile, 2x2 fine tiles) is generally solid or not. Then the second pass decides, for each fine tile, which graphic should be used, based on solidness of its neighbours. It picks edged tiles where the neighbours are empty, and also replaces some solid tiles with triangular ones to open passages, and some empty tiles with triangles to make a more interesting look overall.

I haven't optimized it much, just trying to get a ballpark feel for how fast or slow it would be, but I was quite happy with the result so far - it runs at 50Hz, mostly. For gameplay purposes this is probably way too fast, it'll probably play better at 25Hz, but I'm not sure what the gameplay will be yet.

The sprites were rendered by a BASIC program that's also on the SSD disc image attached. It was interesting writing code to create them programmatically. It let me refine them progressively - from solid colours to a brick-like pattern, and straight line edges to more interesting ones that wrap around the bricks a bit.

At the moment it only uses a 256x256 world, wrapping at the edges. The algorithm can easily support larger worlds, if necessary - it would just require things like the current screen X/Y coordinates to be stored with more bytes, and the hashing routine that calculates random cell contents to use the extra bits as well.

Probably the next thing to add is background objects, artifacts, and other decorations. The Shadertoy prototype has a quick hack to use green to indicate where I could place foliage, and blue and purple for maybe different kinds of artifact. As the real thing on the Beeb actually has a bit more local knowledge, it may be possible to automatically place things like doors in areas where a passage is only one tile high, and other things like that.

Another thing I played with in Shadertoy was varying the density of the caverns, so that some regions are more connected than others, and that could be interesting too.
Attachments
pgg1.png
User avatar
fizgog
Posts: 618
Joined: Thu Jun 17, 2021 3:18 pm
Location: Nottinghamshire
Contact:

Re: Procedural world generation experiment

Post by fizgog »

Very impressive =D>
Pitfall, Gridrunner, Matrix: Gridrunner 2, LaserZone, AcornViewer, AcornPad
User avatar
archie456
Posts: 180
Joined: Sat Sep 07, 2019 4:22 pm
Location: Chelmsford
Contact:

Re: Procedural world generation experiment

Post by archie456 »

Thats great! I'm early on in my road of trying to learn writing games for the BBC, and am trying to do a Citadel type game, but a procedural map world would be the end goal for me!

Looking forward to see what you do with the routine.
User avatar
Symo
Posts: 16
Joined: Thu Dec 06, 2018 1:47 pm
Contact:

Re: Procedural world generation experiment

Post by Symo »

Looks good so far, getting that Exile vibe already :).
Post Reply

Return to “new projects in development: games”