--- title: "Bounce" id: 56282 type: "computer_media" slug: "bounce" url: "http://localhost/computer_media/bounce/" markdown_url: "http://localhost/computer_media/bounce.md" published_at: "2024-08-04T10:49:46+00:00" modified_at: "2026-03-30T21:29:16+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/08/SCR-20240802-sxwc.png" excerpt: "Enter a bounce count and watch a pixel ricochet across the full screen, with distinct beeps at each wall — stopping exactly when you say." 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 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_contents: - id: 56277 title: "Timex Sinclair Public Domain Library Tape 2001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-2001/" - id: 60550 title: "Fort Worth TS2068 Club Library Tape" type: "computer_media" url: "http://localhost/computer_media/fort-worth-ts2068-club-library-tape/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Bounce%20%28198x%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/08/SCR-20240802-sxwc.png" media_type_tags: "Demo" --- # Bounce This program simulates a bouncing ball across the screen, plotting its path using PLOT coordinates up to 255×175 pixels. The user specifies a number of bounces before the animation halts; each wall collision triggers a short BEEP at a different pitch (semitones 1, 2, 4, or 5) to distinguish horizontal from vertical bounces. Direction reversals are handled by two subroutines at lines 200 and 230, which negate the respective delta variables and increment the bounce counter. Initial position and direction deltas are randomised at startup, giving a different trajectory each run. *** ## Program Analysis ### Program Structure The program is organised into three logical sections: 1. **Initialisation (lines 20–85):** Sets random starting coordinates, direction deltas, bounce counter, and prompts for the target bounce count. 2. **Main animation loop (lines 90–160):** Checks boundary collisions, updates position, plots the pixel, and loops until the bounce count is reached. 3. **Collision subroutines (lines 200–250):** Two short subroutines reverse the horizontal (`d`) or vertical (`c`) delta and increment the counter `t`. ### Variables | Variable | Role | | --- | --- | | `x` | Current X pixel coordinate | | `y` | Current Y pixel coordinate | | `d` | Horizontal delta (direction/speed), initially 1 | | `c` | Vertical delta (direction/speed), initially 1 | | `t` | Bounce counter (incremented on each wall hit) | | `b` | User-supplied maximum bounce count | ### Collision Detection and Boundary Values Boundary checks at lines 90–120 test whether the *next* position (`x+d` or `y+c`) would exceed the screen limits. The horizontal limits are 0 and 255, and the vertical limits are 0 and 175, matching the Spectrum’s full pixel resolution of 256×176. Beep pitches differ per wall: semitone 1 for the right edge, 2 for the left, 4 for the bottom, and 5 for the top, giving audible feedback distinguishing axis and direction of bounce. ### Key BASIC Idioms - Direction reversal via negation (`LET d=-d`, `LET c=-c`) is a standard reflection technique requiring no conditional logic beyond the boundary check. - Random initialisation using `INT(RND*50)+1` constrains the start point well within the screen, avoiding an immediate boundary hit on the first step. - The loop condition at line 160 (`IF t 255` rather than `>= 255`, a pixel landing exactly on coordinate 255 will not trigger a bounce on that step; the next step will move to 256 (off-screen) before the check catches it on the following iteration, potentially causing a brief out-of-bounds PLOT — though on hardware this typically wraps or clips silently. - The `BORDER 2` at line 10 sets a red border but there is no corresponding INK or PAPER setting, so the plot colour defaults to whatever the current attribute state is. ## Source Code ``` 5 REM bounce 10 BORDER 2: CLS 20 LET x=INT (RND*50)+1 30 LET y=INT (RND*50)+1 40 LET c=1 50 LET d=1 60 LET t=0 70 PRINT "How many bounces"; 80 INPUT b 85 CLS 90 IF x+d>255 THEN BEEP .1,1: GO SUB 200 100 IF x+d<0 THEN BEEP .1,2: GO SUB 200 110 IF y+c>175 THEN BEEP .1,4: GO SUB 230 120 IF y+c<0 THEN BEEP .1,5: GO SUB 230 130 LET x=x+d 140 LET y=y+c 150 PLOT x,y 160 IF t