10 Mar

How levels are generated in Spaceman 8

All levels in Spaceman 8 are procedurally generated and get larger and more complicated as the game progresses. PICO-8 has technical limitations so the map generator has to be relatively simple. The level generator works in two steps: first by generating the general structure of the level and then adding superficial details on the map that is eventually drawn on the screen. The map contains randomly placed objects that are often found in the ends of the map corridors.

The seed map

The seed map has two types of cells: “open” and “closed” cells. Map is initialized with closed cells.
All level objects (the collectables and the exits) are treated similarly.

  1. Start with single open cell in the center of the map
  2. Position all objects in the starting cell
  3. Pick a random cell on the map using these rules:
    • The cell has to be closed
    • Zero to one diagonal (NW, NE, SE, SW) neighbors have to be open
    • 1 or 2 cardinal (N, E, S, W) neighbors have to be open
  4. Change the cell type open and move an object from any of the neighboring cells or a randomly picked object in the new open cell
  5. Repeat from step 3 until map is large enough

Demo cart and code

You now have a branching, mazelike map that has all open cells connected at least from one direction. The objects should be positioned (mostly) in the ends of the corridors, further from the starting position (this of course depends on luck and you should fiddle with it if you want to make sure the object locations are always challenging).

Making it pretty

The map is upscaled so that each cell now takes twice the cells vertically and horizontally. There is a random change that a cell flips its state if the neighboring cell is of the opposite type. The resizing is done again and again so that the level corridors are suitably wide (at first they are only one tile wide, then two, four etc.). The randomness from the resizing steps carries over and adds first large and then (relatively) smaller random variation to the edges.

The visible map is built from the data using a tileset that has tiles for different edge/side combinations.

The seed map is scanned cell-by-cell and if the current tile is closed, a bitmask is built from the four neighboring seed tiles in the cardinal directions (see the linked cart for working code). The bitmask tells us the tile we want on the visible map. E.g. if all neighboring seed tiles are closed, the bitmask will be binary) 1111b = 15, we know we want to use tile 15 which is a fully filled tile. If one of the sides is open, let’s say to the east, the mask will be 1101b = 13 and we will use tile 13.

If the current seed tile is empty, the visible map will simply have an empty cell. All of this is very easy to implement when just following instructions (basically just make sure the tile order is the same and it will work) but here is a good article about the technique in case you want more details.

Demo cart and code

Finally, the visible map has some random variations added on it: empty cells have a random change to have a non-black background tile and the fully filled tiles have a random change to have a pebble tile and so on. This randomness doesn’t change the level geometry.

25 Mar

Some Cool Demoscene Stuff

Here are some of my favorite demoscene products with a short review of each.

Matt Current (The Shitfaced Clowns/Breakpoint 2007)

Gameboy Advance

You could say Matt Current features two demos in one. The first part features 3D stuff very familiar to anyone who has seen mid-1990s demos and the second half is a complete change in style with one of the best tracks I have heard in a demo (with lyrics), effects with more focus on the presentation than the technology and hip hop. I love the short flashes of video captured footage of skateboarders in synch with the music and the 2D parallax field of graffiti.

Atrium (TBC & Loonies/Breakpoint 2008)


There are a lot of very impressive 4K intros that have come out in the last few years but this one caught my attention. It is funny how the pacing — the single most important thing outside the content itself — is much better than of those in many multi-megabyte demos. The growing building effect also is pretty much equal to the 2006 Assembly demo by Fairlight shown below.

The Secret Life of Mr. Black (Orange/Assembly 1997)


Orange demos have a very distinct style. Even simple things like fade ins and fade outs are tweaked, mainstream effects are avoided (notice the complete lack of Phong shaded polys and other common stuff) and the demo generally has a weird atmosphere (just listen to the soundtrack).

Inside (CNCD/The Gathering 1996)


CNCD’s Inside has one of my favorite soundtracks, the fat track suits the demo well. While some of the 3D stuff in Inside is a bit out of place (how do you segue from rappers to spaceships is beyond me) and looks dated, the remainder of the effects still look absolutely fantastic.

And now for the best of the bunch…

9 Fingers (Spaceballs/The Party 1993)


Take a look at Spaceballs’ 9 Fingers and think about the fact it was done on the Amiga and that it features streaming video of sorts. The demo came on two 800 KB floppies and only lasts for less than three minutes, which was unheard of (well, Spaceballs already did the same with State of the Art but I bet you know what I mean). Ironically, the demo takes far more data when converted to an inferior quality Youtube video.

The captured video footage is converted into a polygon mesh which allows for good compression ratio (you need to store only the mesh points and the polygon color). Of course, the more important thing is that it allows sufficiently fast decoding the video and other effects such as the rotating cube with “texture mapping”. The Atari ST demo shown below employs a similar trick as it streams the precalculated polygon data (or rather the horizontal line data) from disk.

You might also want to take a look at the making of 9 Fingers.

22 Mar

Amazing 4KB Ray Tracer

2008-07-27T12:24:18+00:00: Updated with an even more impressive 4 KB raytracer from RGBA1


The above is the output of a 4KB intro by Rgba that uses purely generated data to render a nice creepy landscape scene. To give some perspective: the same image compressed into a JPEG of similar size would look crap. And it still needs code for displaying the compressed image. You can try and run the program yourself, it can be downloaded from the Rgba site (32-bit Windows binary)2. It takes about 10 seconds for the image to appear on my Athlon XP 3000+. Let’s hope they will make a screen saver of it, with random parameters for the scene.

Things like this make me think of how much things have gone forward since I first looked into ray tracing. It used to take many hours for a similar image to render in POV-Ray (not including the time used for modelling!). Nowadays, you can optimize for size (as opposed to optimizing for speed) and still have a reasonably fast ray tracer. It’s not too far fetched that the above landscape could be rendered real-time on a fast processor and probably with some speed optimizations.

18 Mar

More generated game content

Shmup Pixel Craft Generator

Shmup Pixel Craft Generator is another random sprite generator that is quite similar to Richard’s Evolving Sprite Tool from the last installment. SPCG too gives a sheet of sprites that you can pick from. The sprites make me think of Xevious, they have the feel of ancient space ships.

The author mentions Dave Bollinger’s Pixel Space Ships as his inspiration. Bollinger’s Pixel Robots was featured in the last installment as well.

Explosion generators

There are very many products for generating various effects by using a particle system. However, many of those products are very expensive as they are aimed at film and game industry instead of a hobbyist. Here are some alternatives.

ExGen is a commercial product but with a much nicer price (less than your average game). It is very feature rich, has a nice GUI and even exports as AVI.

The Explosion Graphics Generator or EGG is a very customizable particle system that uses a scripting language. It is free.

Explogen is similar to ExGen only that it is not as feature rich. It’s still worth checking out as it is free.

Positech Games has a free, unnamed generator as well. The page includes sheets of sprites so you don’t even have to download the software.

This blog writes about lhfire, a tool for generating particle effects for a Quake mod. I haven’t tested this myself but it should be good and also free.

22 Feb

Generating game content

Part 2 of this series »

If you can’t draw graphics or create sounds for your games, here are a few interesting tools I came across recently that can help you.


sfxr generates random sound effects such as explosions, sounds for jumping and so on. The sounds are nice and crisp and you can easily tweak a randomly generated sound to suit your needs better. A nice feature is that you can click on sound types to generate a sound for common actions in games.

Pixel Robots & Invader Fractal

Pixel Robots generates random sprites that resemble robots (well, duh). It’s a Java applet (made with Processing) so you can (or, have to) run it in your web browser. Hence, it is not too convenient to use for pure sprite generation purposes – but it is quite nice eye candy.

The author mentions the Invader Fractal as his inspiration. It is a quite similar thing, in that it generates a sheet of tiny sprites and runs in browser (it’s a Flash applet).

Both generators are quite nice in that their authors give good insight how the programs generate the sprites.

Richard’s Evolving Sprite Tool

I saved the best for last. Richard’s Evolving Sprite Tool, as the name implies, evolves sprites. The main idea is that the program generates a grid of mutated sprites and you can choose the one that looks good. The selected sprite then spawns mutated offspring. This continues until you decide the sprite is good enough. On the left, there’s an example of an evolved and hand-colored sprite (grabbed from the Retro Remakes forum thread).

It is also much more of a tool than the two previous generators, the user can edit the sprites inside the program. After the user has edited a sprite, it can be evolved further. Very nice if you’re short on inspiration.

Next thing Richard needs to do is to add a way to colorize and animate the lovely sprites.

kometbombNote: Since this tool has gone AWOL, here’s something similar: Retro Avatar generator. For example, the avatar created from my name looks like what you see on the left (cute!).