Lemmings explosion

So in the last post, we got up to the point where we were removing chunks from the background, and now I wanted to get the explosion code in. The first thing I needed was to get the explosion graphics. This was stored as a signed particle list which using a 16bit processor (x86 or 68000) it was fairly simple and cheap, but on the Z80 it’s a bit slower. Adding a signed 16bit number means either sign extending a byte or storing 16bits per-coordinate.

I wasn’t really wanting this, but actually, didn’t need it either. The Next added a new command where I can add A to HL, and this is incredibly useful. So I un-sign extend the table and have it offset from the top left of the particle sprite, and just add on the X,Y byte offset to the 16bit X, and 8bit Y.

This again works pretty well, but as it’s going to the screen and not the level, I need to clip it to the current view. This is always slightly painful…

Plotting lots of points in 256 colour Layer 2 is painful, clipping is painful, so logically…plotting loads of points, will be extra painful. When you plot a point, you need to work out the 16K bank (Layer 2 uses 3 banks) you’re in, then the offset into that bank, and then add on the X. These coordinates are offset by level X position, so requires some 16bit maths, which is also a little slow.
See where I’m going with this? Yep, basically what sounds like a really simple, fast thing to do…. is slow and horrible. You can have a look at explosion.asm to see what I ended up with…

Once this was running, and being clipped to the display, I needed to try and get a Lemming itself to explode. For this I added in the bomber skill, and drew the counter above the Lemming itself. These numbers are drawn using the same auto-generated code that Lemmings are – since I’ll need to be able to draw lots of them as well as the Lemmings themselves. I then simply set the Lemming to be a bomber when I spawned it, and this set the count down going as soon as it was spawned. Next, I attached the explosion to the Lemming so that it followed it along and I was ready to rock-and-roll!

Now, that this was done, that was mostly the hard bit done….mostly. Next I started using the panel and cursor so that I could click on a Lemming and assign the bomber skill. It’s a simple change, but actually took a bit of time to get working. Once I had the selection and assignment working, I finally got to blow a Lemming up…

While doing this, I also decided to colour the pixels. The original have specifically coloured pixels, but I couldn’t quite do that, so instead, I set up a coloured pixel, then each time I plot, I rotate this byte value by 1 bit, with bit 0 going back into bit 7. This gives me a few colours without having to spend too much time looking up a specific colour etc.

Now that I could assign a bomber skill, I added in the removal of the background on the explode frame, and I had fully working bomber skill. The next step – obviously, is to do the NUKE. This is the most iconic part of Lemmings, and I was itching to see it… After much faffing around to get the double click working – and you have no idea how overly complicated I was making it, I finally got a double click on the panel, and could trigger the nuke feature.

Nuke is very simple. Each frame, you assign the bomber skill, and move onto the next Lemming the next frame, and so on. When all Lemmings are gone, you wait a bit, and then quit the level. Once this was all in and working, we could finally see the slowest graphical effect in Lemmings – NUKE!

This was one of those times where I got nothing else done that week. I would continually just nuke everything and laugh at it. Very satisfying!

Once I had the removal code in, I could then look at some other skills, so I thought I’d tackle the simplest one – Digger. This is a pretty simple one where you basically remove a line on a specific frames of the animation. Again, I added the panel code for assignment, this time it was a proper skill assignment which also including some new code to stop you assigning a skill you already had. You don’t want to assign a digger if he was already digging after all….

This was pretty cool to see, and this is what I took down to the Play Expo in Blackpool where I was going to be on the big ZX Spectrum Next panel. While it wasn’t exactly playable, I guess it was nice for folk to see running on real hardware so that you could see it was real, and was running at the speed I’d been saying it was.

The talk was good fun, and my first Next panel.