The COSMIC9.bas sample script crashes when a missile collides with an alien because PROC_Hit hasn’t yet been defined.
Part Three!
Don’t miss next issue, subscribe on page 16!
Part Three!
Don’t miss next issue, subscribe on page 16!
OUR EXPERT
Nate Drake
first experienced video games when he encountered the cocktail cabinet version of
Space Invaders
in his father’s local.
So far in this series, we have covered how the classic programming language Basic
S
(Beginners’ All-Purpose Symbolic Instruction Code) can still be used today to code games like Mark Buckwell’s
Cosmic Invaders.
In the first instalment of the series, we created code to establish a basic title screen. The following month’s tutorial covered loading the basic game elements, such as the player ship and bases, as well as the invaders themselves. If you followed the steps in last month’s Managing Movements boxout, the player ship also now can be moved left and right using the Z and X keys respectively.
The aliens now also move from side to side and downwards towards the player. As the current sample script COSMIC8.bas stands, they will continue to do so until they reach the bottom row of the screen, erasing the bases as they go, until the game crashes. If the player tries to return fire by pressing Shift as per the instructions in the title screen, the game throws up a ‘NO SUCH FN/PROC’ error.
In this tutorial, we’ll cover how the player fires weapons. We’ll also touch on the procedures for when the aliens are hit. If you haven’t read the preceding tutorials in this series, we recommend viewing the sample scripts at https://github.com/azuregate/lxfcosmicinvaders. This will give you a better idea of how to put the game together in a methodical way. As always, we have chosen the b2 BBC Micro emulator to run Basic code, as it’s readily available in the Ubuntu Snap store. Once this is installed, you can run any of the sample scripts in this series. Just copy the text to the clipboard, then in b2 choose Edit > OSRDCH Paste (+Return). Once the code is copied into b2, just enter RUN to execute it.
Opening fire
As we’ve established, if you run the current sample script COSMIC8.bas and press Shift, it results in the following error: ‘No such FN/PROC at line 1350.’
If you review the sample script, you’ll see it makes a reference to Proc_Fire. This isn’t defined in COSMIC8. bas but you can see this in the original game script (available from http://bit.ly/cosmicinvaders): 1530 DEF PROC_Fire 1540 SOUND &0012,2,0,10 : Missile%=TRUE :
MissileX%=B%+2 : MissileY%=22 : PROC_Move_ Missile(L%) 1550 ENDPROC
As you’ll see, in the interest of efficiency, the game’s coder, Mark, has used the colon (:) to group multiple commands on line 1540.
Firstly, this plays a sound effect to indicate that the player missile is to be fired. If you examine the main game code, you’ll also see that the variable Missile% has already been defined in line 2260 of PROC_Setup_ game. This value is set to false – that is, invisible – by default but line 1540 of PROC_Fire sets this to true.
You’ll also note that the line sets two more variables: MISSILEX% and MISSILEY%. As you have probably guessed, these determine the horizontal and vertical starting positions of the missile respectively.
The missile keeps moving up the screen at fixed intervals. The player can only fire one at a time.