Scripted vs Random Level Generation


For this simple game I want open ended levels, where each level had a different layout. The coin op arcade game this effort is inspired by has a  rigidly defined set of level layouts it uses (because 80's coin op hardware had 24kb of ROM and 2kb of RAM). The Play.Date platform is much more generous.

First Attempt - JSON Files

Initially I built a set of JSON files that broke the 2880 x 2880 pixel world map into smaller 'level parts' that defined the layout of asteroids and enemy bases in an area. The idea was very vaguely based on Spelunky's procedural level generation and was total overkill. It did allow me to do interesting things like hide words and patterns in the world map but that was about it.

Second Attempt - Random Generation with Collision

Lone Fury now generates the levels by scattering a number of enemy bases and obstacles in a circular area of the world, around the player start position. A solution that is simpler to code, and produces more playable maps with interesting results. The level definition also becomes as simple as this:



The beauty of Play.Date's Lua support is it's really easy to visualize things. The level generation uses a 180x180 pixel image to detect enemy base and obstacle overlapping (via playdate.graphics.image:sample(x, y) and playdate.graphics.checkAlphaCollision(image1, x1, y1, flip1, image2, x2, y2, flip2) ), so I just have a game state that shows that pixel image on screen:

The central circle is the player spawn area that must be kept clear of obstacles and enemy bases. I'm about to make this a larger, more interesting polygon - because the player ship starts flying up-screen after it's spawned.


The small dots are 16x16 obstacles (asteroids, enemy eggs, mines),  and the mid sized blobs are the enemy base positions.
I'm also about to add some simple trig check so that enemy bases don't start too close to each other. Having more than a couple of them on-screen at any time leads to some challenging game-play and slight visual oddities because of the way the sprites are moved in the visible window.


Each level also increases the enemy base aggression - they fire more bullets more frequently, the spawn rate of harassing single enemy ships, and the speed at which you're required to destroy enemy bases before an 'Alert' summons an enemy formation to chase you.

What Did I Learn?

Things I already knew from my commercial day job to be honest:

  • Don't Over-engineer: Build the simplest solution first to get some result, then you can iterate on it.
  • Kill Your Darlings: This is a term from writing but I think it also applies to coding: If something isn't working, just chuck it away and try something else. Don't cling to a poor solution just because you've already built it.

Oh Oops Bugs
The current version of Lone Fury you can download has a bug. I've forgotten to erase the level collision map! About to fix that, but it means after a few levels of play the 180x180 level collision map looks like this. Oops!


Get Lone Fury Arcade Shooter for PlayDate

Comments

Log in with itch.io to leave a comment.

This is awesome to read some of the process you've used to develop this Bosconian-type game for the Playdate.  One of the games I have in mind to develop for the Playdate had some inspiration from Bosconian (and my game title also includes the word "Fury" in it, coincidentally).  Downloading the demo to my Playdate now!  The Playdate truly is happiness.