Home > Books > Amstrad CPC > Play BAS Invaders

Play BAS Invaders, a Space Invaders clone for the Amstrad CPC computer

BAS Invaders is a type-in listing I wrote for Amstrad Addict magazine, which was published in October 2023. Below you can play the game, read how it works, and copy the game listing to paste into your emulator. There's also a .dsk file to download.

How to play BAS Invaders

Click the game window to activate it (including sound), and then use the Z, X, and Space keys to play. For best results, I recommend downloading the .dsk file to use in your emulator. The in-browser emulator runs a little bit slowly.

About BAS Invaders

In the 80s and 90s, when I wrote type-ins such as Alien Intervention and Gribbet, magazines were the cheapest way to get games. The opportunity to write a new type-in for Amstrad Addict magazine prompted me to question the role of a type-in today, when we can download any software we want instantly.

While some have said they're looking forward to typing in this new listing like in the old days (thank you!), my priority was to create something that was interesting to read, and read about, whether or not you see the code running. I didn't think there was much point in doing a listing that was largely made up of unintelligible machine code and sprite data, as was common in magazines like Amstrad Computer User. I also wanted to do something using user-defined graphics and the built-in character set, and create a program that was short and readable.

To that end, I embarked on an experiment to see whether I could use colour swapping to get a fast version of Space Invaders working in pure, uncompiled BASIC. I've often used colour swapping for presentation elements and special effects, but hadn't used it as the main animation engine in a game before. I had seen it done: On early compilation Cassette 50, the arcade game Fantasy Land used colour swapping to move the enemies in a platform game. For some reason, I'd never tried something similar until now.

The experiment worked, and the game is called BAS Invaders (which rhymes with Space Invaders). I'm pleased with the result: there are up to 18 objects moving at a good speed, there's a nice title screen, and the listing is a comfortable length to read or type in. The game plays pretty well too. It seems like good value for typing time if you're entering it, and a reasonable length to read if not.

The magazine includes an article explaining the code, but here's a short summary:

  • There are four rows of four aliens. Each alien moves left and right, across five screen positions.
  • The aliens are all drawn at the start, in invisible inks.
  • For all the aliens, position 1 uses pen 1, position 2 uses pen 2 and so on.
  • To make the aliens appear in a particular position, its pen is switched to a visible ink and the pen at the old position is changed to the background colour.
  • When an alien is hit, its five positions are overwritten with spaces.

You can play the game above, but the online emulator runs a bit slow. To see it in real time, download the BAS INVADERS .dsk file to use in your emulator. At the same time, why not download my disc of Amstrad games and utilities, including programs from Amstrad Action, Amstrad Computer User and my book The Basic Idea?

If you don't have your copy of the magazine yet, order Amstrad Addict here

See the code listing

Here's the code listing. It's much more readable than many of my listings from the 80s! You can use the Auto Type feature in Winape to paste this program into your emulator.

10 REM --- BAS INVADERS
20 REM --- (C)2022 Sean McManus - www.sean.co.uk
30 REM
40 ON BREAK GOSUB 380:SYMBOL 250,126,219,219,255,165,60,66,129:SYMBOL 251,126,219,219,255,165,60,36,36:SYMBOL 252,126,193,128,128,129:GOSUB 400:'Two On Breaks are needed because the program loops by RUNning from the next line
50 ON BREAK GOSUB 380:MODE 0:PAPER 0:INK 7,20:DEFINT a-z:LOCATE 10,25:PEN 7:PRINT CHR$(239);:PRINT CHR$(22)CHR$(1)CHR$(23)CHR$(1):' XOR and transparency on
60 DIM aliens(25):alienrow=1:winner=0:position=-5:posink=5:ship=10:counter=1:missiley=0
70 FOR row=1 TO 10 STEP 3:aliens(row)=4:LOCATE 1,row:FOR col=1 TO 4:FOR cell=1 TO 5:INK cell,0:INK cell+8,0:PEN cell:PRINT CHR$(250+(cell MOD 2));:PEN cell+8:PRINT CHR$(8);CHR$(252);:NEXT cell,col,row
80 PRINT CHR$(22)CHR$(0):' Transparency off
90 WHILE winner=0:LOCATE ship-1,25:PEN 7:PRINT " ";CHR$(239);" ";:' 239 is the rocket
100 IF INKEY(63)=0 AND ship<19 THEN ship=ship+1
110 IF INKEY(71)=0 AND ship>2 THEN ship=ship-1
120 IF INKEY(47)=0 AND missiley=0 THEN missilex=ship:missiley=25
130 counter=counter+1:IF counter MOD 5=0 THEN GOSUB 190
140 IF missiley>0 THEN GOSUB 330 ELSE GOSUB 320
150 WEND
160 REM --- Game Over
170 INK 14,0:PAPER 14:PEN 0:LOCATE 7,7:PRINT SPACE$(8):LOCATE 7,8:PRINT " ";CHR$(winner);" WINS ":LOCATE 7,9:PRINT SPACE$(8):PAPER 0:INK 14,20,21
180 gap=250:FOR note=1 TO 7:SOUND 4,956-(g*50),5,15:SOUND 1,239+(g*50),5,15:SOUND 2,478,10,15:FOR delay=1 TO gap:NEXT:gap=gap*1.25:NEXT:SOUND 1,239,120,15:SOUND 2,478,120,15:SOUND 4,956,120,15:FOR delay=1 TO 4500:NEXT:RUN 50
190 REM --- Move aliens left-right
200 position=position+1:IF position=6 THEN position=-5:IF counter>250 THEN GOSUB 250
210 IF position<>0 THEN INK posink,0:INK posink+8,0:posink=ABS(position):INK posink,6:INK posink+8,15 ELSE IF counter>250 THEN GOSUB 250
220 IF position=0 THEN GOTO 190
230 RETURN
240 REM --- Aliens move down
250 IF missiley>0 THEN GOSUB 320
260 LOCATE 1,1:PRINT CHR$(11):LOCATE ship-1,25:PRINT" ";CHR$(239);" ";
270 IF missiley>0 THEN GOSUB 320
280 alienrow=alienrow+1:IF aliens(26-alienrow)>0 THEN winner=250:' 250 is alien
290 SOUND 4,956,5,13:SOUND 1,239,5,13:SOUND 2,239,5,13
300 RETURN
310 REM --- Show/hide missile
320 PLOT (missilex*32)-18,400-(missiley*16)+4,14:RETURN
330 REM --- Missile movement
340 GOSUB 320:missiley=missiley-1:IF TEST((missilex*32)-18,400-(missiley*16)+4)<>ABS(position) THEN GOSUB 320:RETURN
350 INK ABS(position),24:LOCATE (INT((missilex-1)/5)*5)+1,missiley:PRINT SPACE$(5):score=score+1:SOUND 2,956,20,15,0,0,7:IF score=16 THEN winner=239
360 aliens(missiley-alienrow+1)=aliens(missiley-alienrow+1)-1:missiley=0:INK ABS(position),6:RETURN
370 REM --- On Break
380 CALL &BC02:CALL &BB06:PEN 1:PAPER 0:MODE 2:LIST
390 REM --- Title Screen
400 MODE 1:CALL &BC02:INK 0,0:BORDER 0:INK 2,0:INK 3,0:INK 1,24,0:PAPER 0:PEN 1:LOCATE 1,25:PRINT CHR$(250)
410 FOR x=0 TO 16:FOR y=0 TO 16:IF TEST(x,y) THEN PEN 2:LOCATE x+13,16-y:PRINT CHR$(143):PEN 3:LOCATE x+14,17-y:PRINT CHR$(207)
420 NEXT y,x:INK 1,0:LOCATE 1,25:PRINT" ":PEN 1:LOCATE 14,20:PRINT CHR$(250);" BAS INVADERS ";CHR$(250):LOCATE 4,22:PRINT"A 100% BASIC demo of Space Invaders":LOCATE 5,23:PEN 2:PRINT"By Sean McManus - www.sean.co.uk"
430 PEN 1:LOCATE 4,25:PRINT"Keys: Z, X, Space. Any key to start":INK 2,15:INK 3,6:INK 1,24:CALL &BB06:RETURN

Load another game into the emulator

Where next?

Credits

© Sean McManus. All rights reserved.

Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!

Discover my latest books

Coding Compendium

Coding Compendium

A free 100-page ebook collecting my projects and tutorials for Raspberry Pi, micro:bit, Scratch and Python. Simply join my newsletter to download it.

Web Design in Easy Steps

Web Design IES

Web Design in Easy Steps, now in its 7th Edition, shows you how to make effective websites that work on any device.

100 Top Tips: Microsoft Excel

100 Top Tips: Microsoft Excel

Power up your Microsoft Excel skills with this powerful pocket-sized book of tips that will save you time and help you learn more from your spreadsheets.

Scratch Programming in Easy Steps

Scratch Programming IES

This book, now fully updated for Scratch 3, will take you from the basics of the Scratch language into the depths of its more advanced features. A great way to start programming.

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Newsletter | Blog | Copywriting Services | Books | Free book chapters | Articles | Music | Photos | Games | Shop | About