Elena - The Second Demo

Time for another demo created with my new programming language for the ZX Spectrum Next. This one has quite a lot more going on than the first demo and if nothing else demonstrates that I'm not completely wasting my time with this project. Here is a video of it running on the CSpect emulator:

This demo uses a lot more features of the Next such as the Layer2 display mode for the background and custom palettes to get the correct greys for the rocks. Combine that with a drawing to the standard Spectrum screen for the stars and double or triple sized sprites for the rocks and there is quite a bit going on. I haven't done that much optimisation and yet it still manages to run at 50 frames per second. Not too bad if I do say so myself.

Whilst I haven't added that many more new language features since the first demo a lot of base code has been added for manipulating sprites, drawing to Layer2, loading resources via ESXDOS, etc. The compiler has been enhanced quite a lot with a project system to compile multiple code files and prepare Next compatible resources (images, palettes, etc) on the fly. It produces some useful error output too meaning I didn't tear quite as much of my hair out in writing this demo...

It could be better of course. There is too much repetition in the code at the moment. This is because I haven't yet added any polymorphism to the language. This means that, for example, the main loop has a call to update the ship, then the rocks, then the bullets, then the explosions, etc. With some polymorphism I could treat them all as one thing and just have a single loop over all the elements, irrespective of their type.

Can you have a copy of the compiler then? No, not just yet. There is one major annoyance with the compiler at the moment - you have to specify a suffix on all numbers to specify what type they are. This wouldn't be too bad if that produced proper errors. However the ANTLR parsing section of the code instead completely ignores the numbers if they do not have a suffix, which leads to a myriad of weird and wonderful error messages, none of which mention a number at all... I therefore intend to remove the need for these suffixes before I release the compiler.

In the meantime you can play the demo yourself; download it here. It works well on CSpect but I have yet to try with another emulator or an actual Next. Use Q, A, O and P to move the ship and Space to fire. Which as we all know are the best keys.

I'll blog about how the demo works in a future blog post. For the impatient you can download the source code and see if you can work out what is going on for yourself. The source code also includes the resultant C code that my compiler spits out, which is then compiled with Z88DK to produce the final program.

Aren't you impressed that I resisted the temptation to call the demo Project Next?

EDIT: The version I initially released didn't work properly on an actual Next, or the ZEsarUX emulator... Turns out that CSpect's timing is a bit different so I had to tweak the main game loop a little to get it to display correctly on ZEsarUX. It's working pretty well on version 6.1 despite the occasional dropped frame.

The palette had to be adjusted too - CSpect appears to have a bug whereby it treats E3 as the index of the transparent colour in the sprite palette, rather than the colour itself. It also doesn't shift the transparent colour with the rest of the colours when using palette offsets. I therefore changed the palette and the offset to accommodate both.

The links in this post have been updated with the new version. Hopefully it will work on a real Next now; mine hasn't arrived yet so I have no idea. 8o(

EDIT 2: After several tweaks and a few more retries I've given up getting the demo to work on a real Next until mine arrives. Thanks to everyone on the Facebook group who helped with my attempts to get it working.