Part Two !
Don’t miss next issue, subscribe on page 16!
Part Two !Don’t miss next issue, subscribe on page 16!
OUR EXPERT
Nate Drake is a tech journalist specialising in cybersecurity and retro gaming. His first experience of video games was the ‘cocktail cabinet’ version of Space Invaders in his father’s local.
In the first part of this series, we introduced Basic and discovered how it’s ideal for learning I programming by creating simple games like Mark Buckwell’sCosmic Invaders.
If you went through the code in the article and used the sample scripts available from https://github.com/azuregate/lxfcosmicinvaders/, you’ll now have a game with a colourful title screen that plays a brief tune, then invites players to press Space to start or Q to quit. This month, we’ll focus on loading the game variables, as well as the basic elements of the main screen, such as the scores, aliens and player base.
We’re using the mighty b2 BBC Micro emulator. There’s a Snap version in the Ubuntu Software Center, making it easy to install. The code in this series works in other emulators; if possible, set your program to emulate a BBC Micro B 1770 as we’ve done, or it may render graphics differently from what you see here.
Game setup
If you ran the most recent sample script, COSMIC4. BAS, you’ll have seen that when the player presses the space bar to start a game, all that happens is a message to this effect.
In the original game script, this indirectly launches the procedure PROCSetup_Game. You can read through lines 2230-2280 to find out what this does.
As you’ll see, line 2240 reads CLS . This is shorthand to clear the screen of any existing text.
The next two lines define variables like the number of bombs and missiles. At the end of line 2260, you’ll notice our old friend, the VDU command:
VDU 23,1,0;0;0;0;
This command is quite common in video games, because it hides the cursor. Players can do without the distraction, particularly if they accidentally hit the wrong key so that text appears.