Aliens

This file is part of SINCUS Exchange Tape 101 - Entertainment, and Timex Sinclair Public Domain Library Tape 2004. Download the collection to get this file.
Developer(s): Bob Redman
Date: May 12, 1985
Type: Program
Platform(s): TS 2068
Tags: Arcade, Game

This is a Space Invaders-style shoot-em-up game in which the player defends against randomly appearing aliens using a joystick-controlled rocket launcher. The program defines four User Defined Graphics (UDGs) for the alien sprite (\a), the launcher base (\l), the missile (\d), and an explosion (\e) via POKEd bitmap data in the subroutine starting at line 1000. Joystick input is handled using the STICK keyword, reading both axes of the left joystick for movement and fire detection. Alien appearance speed is governed by the system timer peeked at address 23672, with spawn rate increasing according to a skill level variable `a` entered by the player (1–5). The SOUND keyword drives multi-channel audio for missile launch and hit effects, while hit detection relies on ATTR to check the color attributes of the cell above the missile’s current position.


Program Analysis

Program Structure

The program is organized into a main game loop and several subroutines:

  1. Lines 5–9: Header remarks and startup beep.
  2. Lines 10–20: Two initialization subroutines — UDG definition (line 1000) and instructions/skill selection (line 1200).
  3. Lines 30–90: Screen setup; draws the ground strip using PAPER 4, scatters stars with OVER 1, and initializes key variables.
  4. Lines 100–370: Main game loop — alien spawning, launcher movement, missile firing and travel, hit detection, and scoring.
  5. Lines 400–440: Game-over screen with replay prompt.
  6. Lines 1000–1160: UDG definition subroutine, loading four characters.
  7. Lines 1200–1320: Instructions display and skill level input.
  8. Line 9999: SAVE with autostart.

UDG Definitions

Four UDGs are defined at lines 1000–1160 by POKEing bitmap data into USR "x" addresses:

UDGVariableRoleBitmap data
\aaAlien sprite129,126,219,126,60,60,90,129
\llLauncher base24,24,24,24,60,126,255,90
\ddMissile16,16,16,16,16,16,58,40
\eeExplosion137,74,52,204,51,44,82,145

Note that the loop variable names (a, l, d, e) collide with other game variables used later. In particular, l is reused as the launcher column position starting at line 80, and a is reused as the skill level at line 1310. This is safe because the UDG subroutine completes before these variables take on their game roles, but it is a potential maintenance hazard.

Joystick Input (STICK Keyword)

The TS2068-specific STICK keyword (represented as | in the source) reads joystick state. The program uses two forms:

  • stick(1,1) at lines 205 and 231 reads the left joystick’s directional axis and fire button to control horizontal launcher movement and firing.
  • Direction 8 = right, direction 4 = left (standard Kempston-style encoding). The launcher position l is updated by adding and subtracting boolean results of these comparisons.
  • Fire detection at line 231 checks stick(2,1)=1; if not firing, line 241 checks |(2,1)=0 to loop back without firing.

Alien Spawning and Timing

The system frame counter at address 23672 is used as a software timer. Line 110 resets it with POKE 23672,0, and line 120 reads it back with PEEK 23672. When the counter reaches the threshold 80-(a*6), a new alien is printed at a random screen position using PAPER 8; INK 2 (transparent paper). Skill level a ranges from approximately 0.67 to 4.67 (after the VAL a$-(.33) calculation at line 1310), making the threshold vary between roughly 52 and 76 frames. Higher skill levels cause more frequent alien appearances. The alien counter f1 increments each spawn; when it exceeds 10, the game ends.

Missile Mechanics and Hit Detection

When fire is detected (line 231), a FOR loop from line 250 walks the missile UDG \d upward from row 18 to row 0. At each step the missile is printed in INK 0 (black), then erased. Hit detection at line 276 uses ATTR (c-1,l) to check the color attribute of the cell directly ahead of the missile. The value 106 corresponds to BRIGHT 1 + PAPER 8 + INK 2 (i.e., the alien’s attribute), which triggers the hit routine at line 300. On a hit, f1 is decremented and a FLASH 1 explosion UDG \e is displayed briefly.

SOUND Usage

The TS2068 SOUND keyword is used for multi-register AY-3-8910 sound effects:

  • Line 265: Missile travel sound — registers 6, 7, 8, 9, 10, 13 configured for noise-based propulsion sound.
  • Line 285: Missile miss — resets registers 8 and 7.
  • Lines 331–333: Hit explosion — registers 6, 7, 8, 9, 10, 12, 13, then silenced.
  • Line 351: Post-hit silence — resets registers 8 and 7.

Starfield Background

Lines 50–75 draw 20 random stars using PLOT with OVER 1 (XOR plotting mode). The Y coordinate is constrained to RND*120+40, keeping stars above the ground strip (which occupies the lower portion of the screen). Using OVER 1 means re-plotting a star position would erase it, a side effect not guarded against but statistically unlikely with only 20 points.

Skill Level Calculation

At line 1310, the skill level is computed as LET a=VAL a$-(.33). Subtracting 0.33 means skill 1 yields a≈0.67 and skill 5 yields a≈4.67. This fractional offset slightly softens the lowest difficulty while keeping the spawn threshold formula 80-(a*6) continuous and non-integer, producing slightly irregular timer thresholds — likely an intentional tuning choice.

Notable Bugs and Anomalies

  • Line 1280 vs 1290: Line 1280 collects INKEY$ into a$, but line 1290 immediately overwrites it with an INPUT statement, making the INKEY$ at 1280 redundant. The validation GO TO 1280 at line 1300 will loop back to re-execute the INKEY$ before re-prompting, which is slightly awkward but functional.
  • Launcher position guard: Line 220 prevents l exceeding 31, but uses l=l-1 rather than LET l=31, which could theoretically allow values of exactly 32 briefly if the joystick increments by more than 1 per iteration.
  • Line 350: PRINT AT 21,29; INK 4;"\::" prints a block graphic over the alien count display, apparently intended as a visual flash effect, but the count is restored two lines later at line 360.
  • Commented-out line 400: The original game-over message "You're Dead" is preserved as a REM comment and replaced by "They got you!" at line 401.

Content

Appears On

One of a series of library tapes compiled from multiple user groups.

Related Products

Related Content

Image Gallery

Aliens

Source Code

    5 REM written for the 2068        by Bob Redman May 12 '85
    7 CLS 
    8 REM "aliens.bas"
    9 BEEP .1,11
   10 GO SUB 1000
   20 GO SUB 1200
   30 REM screen set up
   34 CLS : PAPER 5: CLS : PAPER 5: BORDER 0
   40 CLS : PRINT AT 20,0; PAPER 4;"                                "
   45 PRINT AT 21,0; PAPER 4;"                                "
   50 FOR s=1 TO 20
   55 OVER 1
   60 PLOT RND*254,RND*120+40
   70 NEXT s
   75 OVER 0
   80 LET f1=0: LET l=15
   85 LET b=-22
   90 LET hits=0
  100 REM aliens
  110 POKE 23672,0
  120 LET t=PEEK 23672
  125 BRIGHT 1
  129 BRIGHT 1: IF t>=80-(a*6) THEN PRINT AT RND*17,RND*28+2; PAPER 8; INK 2;"\a": BEEP .05,b: LET f1=f1+1: BRIGHT 0: PRINT AT 21,28; INK 4;"\::\::"
  131 BRIGHT 0: LET b=b+.1
  135 PRINT AT 21,21;"aliens ": PRINT AT 21,28;f1
  140 IF f1>10 THEN GO TO 400
  160 IF t>=80-(a*6) THEN POKE 23672,0
  200 REM launcher base
  205 LET l=l+(|(1,1)=8)-(|(1,1)=4)
  210 LET l=l+(t=0)-(t=30)
  215 IF l<=0 THEN LET l=0
  220 IF l>31 THEN LET l=l-1
  222 BRIGHT 1: PRINT AT 19,l; INK 1;"\l": BEEP .001,69: BRIGHT 0
  225 PRINT AT 19,l;" "
  231 IF |(2,1)=1 THEN GO TO 250
  240 PRINT AT 19,l;" "
  241 IF |(2,1)=0 THEN GO TO 120
  250 FOR c=18 TO 0 STEP -1
  261 PRINT AT c,l; INK 0;"\d"
  265 SOUND 6,15;7,7;8,16;9,16;10,12;13,4
  271 PRINT AT c,l;" "
  276 IF ATTR (c-1,l)=106 THEN GO TO 300
  280 NEXT c
  285 SOUND 8,0;7,63
  290 GO TO 129
  300 REM missile hit
  310 BEEP .01,69
  330 PRINT AT c-1,l; FLASH 1;"\e"
  331 SOUND 6,6;7,7;8,16;9,16;10,16;12,56;13,8
  332 PAUSE 55
  333 SOUND 8,0;9,0;10,0
  335 PRINT AT 19,l;" "
  340 PRINT AT c-1,l;" "
  350 LET hits=hits+1: LET f1=f1-1: PRINT AT 21,29; INK 4;"\::"
  351 SOUND 8,0;7,63
  360 PRINT AT 21,3;"hits=";hits: PRINT AT 21,28;f1
  369 PAUSE 25
  370 GO TO 129
  400 REM PRINT AT 11,10; INK 0; FLASH 1;"You're Dead"
  401 PRINT AT 11,10; INK 0; FLASH 1;"They got you!"
  405 BEEP .1,1: BEEP .1,1: BEEP .1,1: BEEP .1,1
  406 BEEP .1,1: BEEP .1,1: BEEP .1,1: BEEP .1,1
  407 BEEP .1,1: BEEP .1,1: BEEP .1,1: BEEP .75,13
  408 CLS 
  410 PRINT AT 12,1;"  Do you want another game?                                                                            press  y or n "
  420 IF INKEY$="y" THEN GO TO 30
  430 IF INKEY$="n" THEN PAPER 6: INK 0: CLS : STOP 
  440 GO TO 420
 1000 FOR n=0 TO 7
 1010 READ a: POKE USR "a"+n,a
 1020 NEXT n
 1030 DATA 129,126,219,126,60,60,90,129
 1040 FOR n=0 TO 7
 1050 READ l: POKE USR "l"+n,l
 1060 NEXT n
 1070 DATA 24,24,24,24,60,126,255,90
 1080 FOR n=0 TO 7
 1090 READ d: POKE USR "d"+n,d
 1100 NEXT n
 1110 DATA 16,16,16,16,16,16,58,40
 1120 FOR n=0 TO 7
 1130 READ e: POKE USR "e"+n,e
 1140 NEXT n
 1150 DATA 137,74,52,204,51,44,82,145
 1160 RETURN 
 1200 REM instructions
 1203 PAPER 4: CLS : PAPER 4: BORDER 6
 1205 CLS : BRIGHT 1
 1207 PAPER 4: CLS : PAPER 4: BORDER 6
 1210 PRINT AT 3,3;"You have to defend yourself    against the attacking aliens    who will re-energise out of     hyperspace above the ground      It is your job to shoot the    aliens down using your rocket    base (\l)"
 1220 PRINT AT 16,3;"PRESS ANY KEY TO CONTINUE"
 1230 REM IF INKEY$=" " THEN GO TO 1250
 1240 PAUSE 0
 1242 BRIGHT 0
 1245 CLS 
 1247 PAPER 1: INK 7: BORDER 5: CLS 
 1250 PRINT AT 09,2;"Your launcher is controlled by the left joystick. If you      allow 10 aliens to be present at the same time you will be....   "                                     
 1252 PAUSE 300: BRIGHT 1: PRINT AT 15,09; INK 2; FLASH 1;"  ELIMINATED!!": BEEP .30,1: PAUSE 480                                     
 1253 PAPER 5: CLS : PAPER 5: BORDER 1
 1254 PAPER 5: INK 0
 1255 BRIGHT 0: CLS : BEEP .1,11
 1260 PRINT AT 13,1;" ENTER SKILL LEVEL FROM 1 TO 5"
 1270 PRINT AT 15,5;"1=EASIEST   5=HARDEST"
 1280 LET a$=INKEY$
 1290 INPUT "SKILL LEVEL = ";a$
 1300 IF a$<"1" OR a$>"5" THEN GO TO 1280
 1310 LET a=VAL a$-(.33)
 1314 PAPER 7: CLS : PAPER 7
 1320 RETURN 
 9999 SAVE "aliens" LINE 1

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top