--- title: "Zap" id: 57427 type: "computer_media" slug: "zap" url: "http://localhost/computer_media/zap/" markdown_url: "http://localhost/computer_media/zap.md" published_at: "2024-10-05T13:17:35+00:00" modified_at: "2026-03-30T21:18:01+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/228_Zap.png" excerpt: "Guide your ground cannon through 20 incoming missiles using live INKEY$ controls — can you intercept them all before they land?" 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/228_Zap.png" related_content: - id: 23926 title: "A Brief History of JRC Software" type: "post" url: "http://localhost/blog/a-brief-history-of-jrc-software/" media_type_tags: "Arcade, Game" --- ZAP is a short arcade-style missile interception game where the player must manoeuvre a ground-based launcher left and right to shoot down incoming projectiles. The player’s cannon is displayed at the bottom of the screen using block graphics, and each missile descends toward it over 18 animation frames. Movement is controlled via keys 5 and 8, read with INKEY$ on every frame, and a hit is registered when the missile’s horizontal position falls within two columns of the launcher. The game runs 20 rounds and reports how many missiles were landed (missed) versus stopped (intercepted) at the end. Variable P$ is constructed as a string expression (“P”, “P+1”, or “P-1”) and then evaluated with VAL each frame to drift the missile horizontally during its descent. *** ## Program Analysis ### Program Structure The program is compact at roughly 20 active lines. The outer `FOR I=1 TO 20` loop (lines 30–140) controls the 20 missile waves. The inner `FOR H=4 TO 21` loop (lines 70–130) animates a single missile descending row by row. Lines 10–20 initialise the score `S` and the player’s cannon column `M`. Line 150–170 display the final result and halt. ### Missile Initialisation At the start of each wave (lines 40–60), three variables are set: - `R = INT(RND*3)` — a random drift direction: 0 = left, 1 = straight, 2 = right. - `P` — starting column, calculated as `13 - (12 AND R=0) + (12 AND R=2) + INT(RND*5)`. When `R=0`, P starts around column 1; when `R=2`, around column 25; otherwise around column 13–17. The random offset adds up to 4 columns of variation. - `P$` — a string encoding the per-frame column update expression: `"P"` (straight), `"P+1"` (drift right), or `"P-1"` (drift left). ### String-as-Expression Technique Lines 60 and 80 demonstrate a notable BASIC idiom: `P$` is built by string concatenation using boolean masking (`AND R` yields the string “+1” only when `R` is non-zero; `AND R=2` appends “-1” only when drifting left). On each animation frame, `LET P=VAL P$` re-evaluates this expression to update the missile’s column position. This avoids an explicit IF/THEN branch and keeps the inner loop tight. ### Player Movement and Rendering Inside the inner loop, line 90 reads INKEY$ twice in the same statement to update `M`, moving right on key 8 (clamped to column 29) and left on key 5 (clamped to column 1). Line 100 clears the screen every frame, and line 110 draws three elements with a single `PRINT AT` statement: - The cannon at row 21 using block graphics `\.:\:.` (▄█▄ appearance). - The missile at row `H` using block graphics `\.'\'.\` (▖▘▖ appearance). - A bullet/exhaust marker `*` at row `24-H` (rising as the missile falls, creating a visual trail). ### Hit Detection Line 120 checks for a hit when the missile reaches row 12 (mid-screen): `H=12 AND M>P-2 AND M
1) 100 CLS 110 PRINT AT 21,M-1;"\.:\:.";AT H,P-1;"\.'\'.";AT 24-H,M;"*" 120 IF H=12 AND M>P-2 AND M