top of page
Writer's pictureBruce

The Super Efficient HUD

So, my current project, The Swarm is Coming..., has a nicely designed (at least I think so, HUD (Head Up Display) - this displays the current weapon, health, messages and so on.




When I first created it, I designed it using blocks. Then in my Game Initialisation script I turned it into code, using PUTBLOCK.


This was a stupid idea.


For a number of reasons.


First, it meant a whole stream of code to achieve, lots of REPEAT loops, lots of PUTBLOCKS and so on.


Not terribly efficient.


Second, I am developing the game using Adventure Mode, in adventure mode MPAGD will store data relating to any PUTBLOCKS that take place during the game, so that a screen that changes (perhaps if you remove a wallblock and replace it with an emptyblock for, say a door that has been unlocked) will retain the new blocks if the screen is redrawn or re-entered.


Now, my HUD is interactive, so when the player selects a different weapon, the bullet icon in the HUD changes.


Try doing that in adventure mode using PUTBLOCKs! - the game will soon bomb out of memory!.


The solution was staring me in the face all the time. One of MPAGDs most powerful tools, DATA & READ.


And of course, the ability to redefine the Font.


So, I set about redefining the font, replacing the characters in the font that the game wont be using, with the graphics for my HUD.


Each font character (in this case our HUD graphics) can be called using the CHR command, provided we know its number.


So, my Font now looks like this:



CHR starts at 32 (32 is a blank space....you''ll probably need that, so best not to redefine it!)


You'll note that I had to make a trade-off here, I only have one font case set, all uppercase, but that wasn't a big sacrifice for me.


So the first CHR in the Font is 32, then 33, 34 and so on. So we'll need to keep track of the CHR number of each HUD graphic.


OK, so, once you have done this you'll probably have noticed a problem...Fonts don't have colours like the BLOCK editor, the most efficient way is to use the COLOUR command, like CHR it needs an 8bit number to define the paper, ink, bright and flash attributes.


Here's a handy cut out and keep reference chart I made...




So colour 1 is dark blue ink on black paper, colour 93 is bright cyan ink on bright magenta paper. Note that colours 123 and up have the Flash attribute....which obviously doesnt work well in a static image!


For each horizontal line of my HUD I should now have a list of CHRs and COLOURS.


So, let's put them into a DATA statement(s)


You should entire your DATA in the paired format:


DATA (COLOUR#) (CHR#) (COLOUR#) (CHR#) (COLOUR#) (CHR#) .... and so on


Each DATA statement can have 16 of these numbers (8 pairs)


So your first DATA statement will define the first 8 characters (horizontally) of your HUD


If your game is using the full screen width you will therefore need 4 DATA statements to fully define each line of your HUD (Mine uses 6 full width lines)


Once you have fully defined your DATA, we just need a small script that READs the CHR and COLOUR values for each cell in the HUD and then displays it on the screen... something like this:




Unless you use RESTORE, using READ in this way means MPAGD will automatically know to carry on form where it left off last time it READ, which is why we can create some simple REPEAT loops to build the entire HUD


And that's it. I chose to put this in my GAME initialisation script, so it only gets called once, when the game starts, I then use CLW (which only clears the play area, not the HUD, in my RESTART SCREEN script.


I also use CHR and COLOUR within my game code to ensure the HUD displays the correct icons for weapons and items that the player has currently selected.


The net effect of this?, it saved me the best part of 350 bytes, which can be used elsewhere for more important stuff.


Huzzah!

639 views2 comments

Recent Posts

See All

2 Comments


Frozen Well
Frozen Well
Nov 19, 2021

Just working on my first game and I had used Blocks for the HUD, going to redo it using this method now, Thanks for your brilliant tutorials

Like

sloanysoft
Jun 26, 2021

This is so helpful! Thank you very much for sharing.

Like

Want to support my work?....Buy my games!

aboutME

Hello, I'm Bruce and I write games for old 8bit computers using Jonathan Cauldwell's excellent Multi-Platform Arcade Games Designer (MPAGD)

I've written a few successful* games for the Sinclair ZX Spectrum and MSX platforms that have been (largely) well received including Twenty Four Hour Parsley People scoring a 10 out of 10 on Planeta Sinclair.

In my blog I am sharing lots of the code that I wrote for my games, in a way that you can use in your own games.   I've commented it so that you'll learn some of the techniques I use to create interesting new mechanics and help your games stand out from the pack.

MPAGD includes lots of standard scripts, they're great to get you started, but if you're new (or just rusty) when it comes to writing code, hopefully my tutorials will help you get started and  turn your imagination into awesome 8 bit games!

All my code is free to use and do with as you please, but if you find them useful please feel free to buy me a coffee ...or better still - buy or download my games :)

*successful is a very relative term in 8bit computer games

bottom of page