--- title: "Invasion" id: 57431 type: "computer_media" slug: "invasion" url: "http://localhost/computer_media/invasion/" markdown_url: "http://localhost/computer_media/invasion.md" published_at: "2024-10-05T13:24:03+00:00" modified_at: "2026-03-30T21:17:58+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/232_Inv.png" excerpt: "Guide your block-graphic gun base to intercept falling aliens before five slip through — each alien type scores differently, and one key teleports you across the screen." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Arcade" slug: "arcade" taxonomy: "genre" url: "http://localhost/type/arcade/" - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_contents: - id: 56736 title: "Timex Sinclair Public Domain Library Tape 1005" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1005/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/232_Inv.png" media_type_tags: "Arcade, Game" --- # Invasion “Invasion” is a Space Invaders–style alien-dropping game in which the player manoeuvres a gun base along row 20 to intercept falling invaders. Aliens drop from the top of the screen one at a time, each rendered as a single character chosen from the string R$ which contains five different block-graphic sprites; the alien drifts diagonally when K is set to 0.5, or falls straight down when K=0. The player scores points equal to the alien’s type multiplied by 100, and loses a life for each miss; five misses ends the game with an inverse-video “GAME OVER” message. The gun base is drawn using Spectrum block graphics (\:.\.​:), and teleport is available via the “H” key, which repositions the base to a random column. *** ## Program Analysis ### Program Structure The program is organised into a small number of functional blocks: 1. **Initialisation (lines 40–90):** Sets score `W`, alien sprite string `R$`, miss counter `M`, gun position `J`, and draws the initial gun base. 2. **Main loop (lines 100–340):** Randomly picks a column `X` and alien type `T`, then branches to either the left-side handler (line 200) or right-side handler (line 300) based on whether `X` is less than 12 or greater than 20. Both handlers set a drift factor `K` and call the drop subroutine at line 400. 3. **Drop subroutine (lines 400–495):** Animates the alien falling from row 0 to row 20, polls for a keypress during each frame, checks for a hit or miss, updates lives and score, and returns. 4. **Player movement subroutine (lines 500–600):** Reads keys 5 (left), 8 (right), and H (teleport), moves the gun one column at a time or jumps to a random column. 5. **Game over (lines 900–920):** Prints inverse-video “GAME OVER” and the final score, then stops. ### Sprite and Graphics Techniques The alien sprites are stored as individual characters within the string `R$` at line 60. The string `"\##% \'.\''\,,"` contains a mixture of printable ASCII and Spectrum block graphics. The alien to display is selected by `R$(T)` where `T` is an integer 1–5, giving five distinct alien appearances from a single string. The gun base is drawn using the block-graphic sequence `\:.\.:` which produces the pattern ▙▖▙, giving a recognisable two-cell gun shape at row 20. Erasing is done by printing two spaces at the previous alien position (line 410) before drawing at the new position (line 430), and similarly at line 450 for the final erase after the loop. ### Movement and Drift Mechanic When an alien spawns, its horizontal drift `K` is set to either 0 (straight drop) or 0.5 (diagonal drift) based on a random value `Y` in the range 1–3. Because `K=0.5` and the loop runs 20 iterations, a drifting alien moves 10 columns horizontally across its descent, adding unpredictability. Note that `X=X+K` uses a floating-point column value; the `PRINT AT` statement truncates this to an integer implicitly, which is standard Spectrum BASIC behaviour. ### Input Handling Input is polled inside the drop loop at line 435: if `INKEY$<>""`, the movement subroutine at line 500 is called. This means the player can only move once per alien row-step, making the game progressively harder for fast-falling aliens. The subroutine reads `INKEY$` a second time at line 500 to capture the actual key, which introduces a minor race condition — the key held at line 435 may differ from the one read at line 500 if the player changes keys in the intervening time. The boundary check at line 530 prevents the gun from moving off-screen: if `J+P>30 OR J+P<1`, the subroutine returns without moving. The screen is 32 columns wide, so the gun (two characters wide) is effectively constrained to columns 1–30. ### Scoring and Lives A hit is detected at line 460 by checking whether the gun’s left cell (`J`) or right cell (`J+1`) matches the alien’s final column `X`. The score increment is `T*100`, so higher-type aliens (up to type 5) are worth up to 500 points. A miss increments `M`; five misses triggers the game-over branch at line 900. ### Notable Anomalies and Observations - Lines 200–280 and 300–340 are structurally identical — both set `K` from the same `Y` random variable and call the same subroutine. The branch on column ranges (`X<12` vs `X>20`) appears to be intended to give left-spawning and right-spawning aliens different drift directions, but since `K` is always non-negative, all drifting aliens drift to the right regardless of spawn side. - When `X` is in the range 12–20, neither branch at lines 110–120 is taken and execution falls through to line 200 anyway, so there is no effective dead zone. - After the `FOR` loop at line 400, the variable `I` holds the value 21 (one past the final iteration), so line 450 erases at row 20 (`I-1 = 20`), which is correct. - The teleport key “H” (line 525) can move the gun to a random column in 1–30 without consuming a move step, offering a significant gameplay advantage if used skillfully. - Lines 930–940 (`SAVE` and `RUN`) are never reached during normal play because line 920 executes `STOP`; these lines serve only as a program-save footer. ### Variable Summary | Variable | Purpose | | --- | --- | | `W` | Player score | | `M` | Miss counter (lives lost) | | `J` | Gun base column position | | `X` | Alien column (floating-point during drift) | | `T` | Alien type index (1–5), used for sprite and score | | `K` | Horizontal drift per row (0 or 0.5) | | `Y` | Temporary random value for drift decision | | `R$` | Five-character sprite string | | `P` | Gun movement direction (−1 or +1) | | `Y$` | Key pressed by player | | `I` | Loop counter for alien drop animation | ## Source Code ``` 40 REM "INVASION" 50 LET W=0 60 LET R$="\##% \'.\''\,," 70 LET M=0 80 LET J=15 90 PRINT AT 20,J;"\:.\.:" 100 LET X=INT (RND*28)+2 105 LET T=INT (RND*5)+1 110 IF X<12 THEN GOTO 200 120 IF X>20 THEN GOTO 300 200 LET Y=INT (RND*3)+1 210 IF Y=1 THEN LET K=0 220 IF Y>1 THEN LET K=.5 230 GOSUB 400 280 GOTO 100 300 LET Y=INT (RND*3)+1 310 IF Y=1 THEN LET K=0 320 IF Y>1 THEN LET K=.5 330 GOSUB 400 340 GOTO 100 400 FOR I=1 TO 20 410 PRINT AT I-1,X;" " 420 LET X=X+K 430 PRINT AT I,X;R$(T) 435 IF INKEY$<>"" THEN GOSUB 500 440 NEXT I 450 PRINT AT I-1,X;" " 460 IF J=X OR J+1=X THEN LET W=W+T*100 470 IF J<>X AND J+1<>X THEN LET M=M+1 480 IF M>=5 THEN GOTO 900 490 PRINT AT 21,7;"PTS= ";W;" LIVES= "; 5-M 495 RETURN 500 LET Y$=INKEY$ 510 IF Y$="5" THEN LET P=-1 520 IF Y$="8" THEN LET P=1 525 IF Y$="H" THEN GOTO 580 530 IF J+P>30 OR J+P<1 THEN RETURN 540 PRINT AT 20,J;" " 550 LET J=J+P 560 PRINT AT 20,J;"\:.\.:" 570 RETURN 580 PRINT AT 20,J;" " 590 LET J=INT (RND*30)+1 600 GOTO 560 900 PRINT AT 19,12;"%G%A%M%E% %O%V%E%R" 910 PRINT AT 21,7;"PTS= ";W;" LIVES= "; 5-M 920 STOP 930 SAVE "1023%2" 940 RUN ```