B2
Coding a BBC Basic Space Invader clone
Nate Drake invites you to stave off the alien menace by coding your very own Space Invaders clone in Basic, because it’s 2025!
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.
Line 2270 then invokes a number of other procedures, such as PROC_Info_line, which is used to display the player’s current score, high score and remaining lives.
If you want to get the game working, modify the lines in the existing sample script to invoke the Setup_Game procedure, by changing: 390 UNTIL A$ = “ “ 400 PRINT “Game starting...” to the following: 520 UNTIL A$ = “ “ 530 Start% = 0 540 Score% = 0 550 Base% = 3 560 PROC_Setup_Game In the above example, you’ll notice that the line numbers are different. This is because our sample script didn’t contain all the graphical and special characters in the original game (which are listed on lines 110-220).