CA
  
You are currently viewing the Canada version of the site.
Would you like to switch to your local site?
14 MIN READ TIME

Coding Cosmic Invaders in BBC Basic

Nate Drake invites you to stave off the alien menace by coding your very own Space Invaders clone in Basic, because it’s 2025!
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.
Unlock this article and much more with
You can enjoy:
Enjoy this edition in full
Instant access to 600+ titles
Thousands of back issues
No contract or commitment
Try for $1.39
SUBSCRIBE NOW
30 day trial, then just $13.99 / month. Cancel anytime. New subscribers only.


Learn more
Pocketmags Plus
Pocketmags Plus

This article is from...


View Issues
Linux Format
April 2025
VIEW IN STORE

Other Articles in this Issue


LINUX FORMAT
LINUX FORMAT
The #1 open source mag Future Publishing Limited,
WELCOME
MEET THE TEAM
This month, we’re putting our readers through our Hacking Academy, so which old-school type of hack are you most proud of?
Hacking an education
It’s that time of the year when we
REGULARS AT A GLANCE
Pebble OS returns from the dead as open source
OPERATING SYSTEM
Distrowatch blocked, then allowed by Facebook
Facebook’s Linux ban sparks outrage.
GTK winter 2025 update
Upcoming changes include X11 deprecation.
20 YEARS OF ODF
OPINION
DATA POINTS
OPINION
AI censorship broken with hex
Chinese AI firm DeepSeek’s censorship has been bypassed by a researcher.
Gnome adds HDR configuration
HDR support answers long-standing requests.
Flathub adds new sections
New We Games and On The Go categories make for easier Flatpak browsing.
Distro watch
What’s behind the free software sofa?
MAKING TRACKS
OPINION
BURNT OFFERINGS
OPINION
Kernel Watch
Jon Masters summarises the latest happenings in the Linux kernel, so that you don’t have to.
ONGOING DEVELOPMENT
Updated Kexec HandOver (KHO) patches were posted that
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
A QUICK REFERENCE TO… SHELL WILDCARDS
Wildcards are used to match multiple files in
Mailserver
WRITE TO US Do you have a burning
Helpdex
shane_collinge@yahoo.com
YOUR DIGITAL ISSUE ACCESS
Linux Format print subscribers can now access digital back issues two ways! * Who’s a lucky bunch of readers?!
SysD Manager
Version: 1.6 Web: https://github.com/plrigaux/sysd-manager
AdGuard Home
Version: 0.107.55 Web: https://adguard.com/en/adguard-home/overview.html
ExifTool
Version: 13.11 Web: https://exiftool.org
Tuptime
Version: 5.2.4 Web: https://github.com/rfmoz/tuptime
Xournal++
Version: 1.2.5 Web: https://xournalpp.github.io
Hidamari
Version: 3.6 Web: https://github.com/jeffshee/hidamari
PeaZip
Version: 10.2.0 Web: https://peazip.github.io
HeXon
Version: 20241021 Web: https://luckey.games
FeudalTactics
Version: 1.3.1 Web: https://github.com/Sesu8642/FeudalTactics
Lock
Version: 1.3.8 Web: https://konstantintutsch.com/Lock/
Double Commander
Version: 1.1.21 Web: https://doublecmd.sourceforge.io
REVIEWS
Asus ZenWiFi BT8
Brandon Hill finally thinks this is a worthy Wi-Fi 7 router.
Pop!_OS 24.04 Alpha 5
Nate Drake picks apart System76’s pet distro, based on Ubuntu. Does Pop!_OS hit with a bang or a whimper?
Siduction 2024.1.0
Nate Drake has been hobnobbing with Siduction’s developers to inform you about all this Debian-based distro has to offer.
MakuluLinux 2025.1
Nate Drake heads to Vietnam to explore this feature-rich distro with its own Electra AI assistant. What more could you want?
Ditana 0.9.0
Nate Drake delves into the beta version of this Arch-based distro. Is it ready to roll or just played out?
Halls of Torment
Management loves the idea of a vast army hammering away at keys all day – Joshua Wolens thinks that’s his current day job.
ROUNDUP
Power-user distributions
Michael Reed tries some Linux distros that throw ease of installation out of the window in favour of customisation and a learning experience.
Installation procedure
It tends to be a learning experience with distributions like these.
Alternative distro builds
Pre-built and configured options with easy-to-use derivatives.
Following the installation guide
An important aspect of these distros.
Educational value
These distributions offer an opportunity to pick up some useful skills.
As a daily driver distro
Using it as a standard desktop distribution for average users.
Community and support
Getting started and troubleshooting problems.
Scope for customisation
Make your vision for a Linux system a reality rather than using defaults.
The verdict
Power-user distributions
HACKING ACADEMY
Hacking Academy
Erstwhile academic Jonni Bidwell transmuted his ivory tower book smarts into l33t hacker knowledge. And he’s here to pass it on.
Hacking origins
Some musings on the hacker archetype and today’s common misconceptions about the practice. Plus an intro to BackBox.
Port scanning
Get started with port scanning and probe your systems with Nmap – the bread and butter of pentesting.
Network recon
Explore the Zenmap GUI, look at network traffic with EtherApe, and sniff packets with Wireshark.
Metasploit playground
Test your system for known vulnerabilities, try to backdoor it, and almost discover a vulnerability in BackBox. Fun!
Hacker-friendly Wi-Fi
Nate Drake guides you through choosing the right wireless device so you can hack with the best of them.
Pi USER
Raspberry Pi turns green
Now the Foundation is publicly listed, it’s reporting on how it’s reducing its environmental impact.
Pi 5 PCIe 3.0
Double the M.2 fun!
LoRa laughs
Meshtastic BBS.
THANK S FOR THE MEMORY ?
Les Pounder works with groups such as the
MX Linux 23.5
Les Pounder takes his annual spin with MX Linux on the Raspberry Pi 5. Has it improved since 2024? Spoiler: yes!
OrangePi 4A
The ingredients are all there, but this Pi just doesn’t taste sweet enough for Les Pounder.
RASPBERRY PI 5 Get the most from your Raspberry Pi 5
Faster CPU, storage and RAM for your Raspberry Pi 5 has Les Pounder shouting with a raspberry yell, “More! More! More!”
Long-range wireless without pesky bills
Exchanging data over long ranges without paying carriers a fortune sounds like a dream, but Tam Hanna and LoRa technology let you do it!
IN DEPTH
WIRE SHARK to the cloud!
Linux Format talks to Gerald Combs and Loris Degioanni , about creating Wireshark, the origins of network packet analysis, and how they want their shark to fly...
TUTORIALS
Back up data with ease
Neither music nor love will solve your computing problems, but timely backups just might, feels Shashank Sharma.
Run Android apps on your Linux PC
Nick Peers discovers a fast and relatively easy way to run standard Android apps on your Linux desktop installation.
Self-host remote access with Rust Desk
Remote-control software is useful, but Tam Hanna suggests self-hosted remote control software based on open source technology is even better.
The hardware that made Linux great
To kick off our new series, Mike Bedford delves into the now largely forgotten 80386, which is where Linux first saw the light of day.
Run OnlyOffice from your Synology NAS
Enhance your private Synology cloud with OnlyOffice Docs, as Kseniya Fedoruk walks you through the installation process.
ADMINISTERIA
Managing your Vagrant virtual machines
Laziness is the mother of invention and Stuart Burns is a past master at getting his machines to do all his work for him…
NVME AND RASPBERRY PI: A YUMMY SANDWICH
Raspberry Pis are great but, let’s be honest,
ENEMY WITHIN!
Stuart Burns is a sysadmin for a Fortune
AI security threats
The rise of AI presents cybersecurity challenges for all. Davey Winder explores the dangers – and how to defend against them!
CODING ACADEMY
How fast can your Rust code run?
David Bolton demonstrates running two Rust programs used to time card shuffling and generate a file full of poker cards.
ADVERTISEMENT
THE BRAIN TUMOUR CHARITY
thebraintumourcharity.org
LINUX FORMAT
www.linuxformat.com
Techradar
www.techradar.com
LINUX FORMAT
www.magazinesdirect.com
LINUX FORMAT
www.magazinesdirect.com/linux-format
LINUX FORMAT
MAGAZINES DIRECT
magazinesdirect.com
CODECLUB
www.codeclub.org.uk
LINUX FORMAT
LINUX FORMAT
LINUX FORMAT
Chat
X
Pocketmags Support