Mini-Invaders is a simple Space Invaders-style shooting game that scrolls a row of alien characters (“V”) across the screen while the player moves a ship (“$”) along the bottom and fires upward. The alien row is animated by rotating the string A$ one character left each frame using the slice A$(2 TO 31)+A$(1), a classic Sinclair BASIC string-rotation idiom. Player movement is handled with keys 5 and 8, firing with key 0, which triggers a subroutine setting a bullet flag and start position. The score display alternates between S and ABS(S-1) on every loop iteration, producing a flickering effect at line 106–107 that appears to be an unintended artifact rather than deliberate design.
Program Analysis
Program Structure
The program is structured as a single outer FOR L=1 TO 4 loop (lines 25–280) representing four waves or levels of play. Within each iteration, an inner animation loop (lines 50–110) runs continuously via GOTO 50, handling display, input, bullet movement, and alien scrolling. A subroutine at line 230 initialises the bullet. The program ends at line 290 with STOP; lines 300–310 are a save/run block outside the game logic.
Key Variables
| Variable | Role |
|---|---|
S | Score |
P | Player horizontal position (column) |
L | Current level/wave (loop counter) |
A$ | Alien row string, 32 characters |
F | Bullet-in-flight flag (0 or 1) |
Y | Bullet row position |
X | Bullet column position (set to P at fire) |
Animation and Scrolling
The alien row is animated by the string rotation at line 100: LET A$=A$(2 TO 31)+A$(1). This shifts the 32-character string one position left each frame and appends the displaced character to the right, producing a continuous leftward scroll of the “V” alien pattern across the screen row. The row is printed at AT L,0, so the alien row’s screen row deepens with each level.
Player Movement and Firing
Line 90 updates the player position using a Boolean arithmetic idiom: LET P=P+2*(INKEY$="8")-2*(INKEY$="5"). In Sinclair BASIC, a true condition evaluates to 1, so this moves P by ±2 columns per frame depending on which key is held. There is no boundary clamping, so P can go off-screen. Pressing “0” calls the subroutine at line 230, which sets the flag F=1, bullet row Y=6, and bullet column X=P.
Bullet Movement Logic
When the bullet is active (F is non-zero), line 60 jumps to line 120, which decrements Y. Line 140 checks whether the bullet has reached the alien row (Y=L); if so, control passes to line 170 — which is absent from the listing. This is a known technique of branching to a non-existent line; the interpreter will fall through to the next available line, which is 180. Line 180 blanks the alien at position X in A$, and line 190 adds 10 to the score. Line 210 uses RND>.7 to give a 30% chance of a bonus 50 points and advancing to the next level via line 270; otherwise the wave restarts at line 40.
Score Display Anomaly
Lines 106–107 print the score and then immediately set S=ABS(S-1) on every animation frame. This means the displayed score alternates between S and S-1 on successive frames, producing a persistent one-point flicker in the score readout. This appears to be a bug: the intent was likely to use the score as a frame-toggle indicator for some other purpose, or the lines were intended to be conditional. As written, the score is corrupted every other frame.
Notable Techniques and Idioms
- String slicing for cyclic rotation:
A$(2 TO 31)+A$(1) - Boolean arithmetic for multi-direction movement in one statement
- Subroutine used solely to set state variables and return (lines 230–260)
- Branch to non-existent line 170 as a fall-through to line 180
RND>.7for a probabilistic level-completion check
Bugs and Anomalies
- No boundary check on
P: player can move off the left or right edge of the screen. - Score corruption:
S=ABS(S-1)runs every frame, making the displayed score oscillate. - Line 170 is missing; the fall-through to 180 works but is fragile if lines are reordered.
- The bullet erase at line 150 (
PRINT AT Y,X;" ") happens before the alien-row check, but the alien row itself is not re-drawn at the erased position until the nextGOTO 50cycle, which may produce a one-frame blank in the alien row. - After
Fis set, there is no mechanism to clear it if the bullet reaches row 0 without hitting an alien at rowL, potentially locking the game in bullet-active state indefinitely for certain level values.
Content
Source Code
5 REM "MINI-INVADERS"
10 LET S=0
20 LET P=16
25 FOR L=1 TO 4
30 LET A$="V V V V V V V V V V V V V V V V "
40 LET F=0
50 PRINT AT L,0;A$;AT 7,P;"$"
60 IF F THEN GOTO 120
70 PAUSE 20
80 IF INKEY$="0" THEN GOSUB 230
90 LET P=P+2*(INKEY$="8")-2*(INKEY$="5")
100 LET A$=A$(2 TO 31)+A$(1)
105 CLS
106 PRINT S
107 LET S=ABS (S-1)
110 GOTO 50
120 LET Y=Y-1
140 IF Y=L THEN GOTO 170
150 PRINT AT Y,X;" "
160 GOTO 70
180 LET A$(X)=" "
190 LET S=S+10
210 IF RND>.7 THEN GOTO 270
220 GOTO 40
230 LET F=1
240 LET Y=6
250 LET X=P
260 RETURN
270 LET S=S+50
280 NEXT L
290 STOP
300 SAVE "1023%4"
310 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
