Skip to content
Game 3

Give every column a ground height

Give each column a height, while deliberately keeping all those heights equal at first.

Continue with Steer and thrust together. The ground is still a constant row. Give each column a height, while deliberately keeping all those heights equal at first.

Add lines 20, 30. Replace lines 310, 610, 620.

20 DIM h(32)
30 FOR c=1 TO 32: LET h(c)=20: NEXT c
310 LET ny=y+v: LET contact=0: LET limit=100*(h(nx+1)-1)
610 FOR j=h(c+1) TO 21: PRINT PAPER 4;INK 0;AT j,c;" ";: NEXT j
620 PRINT PAPER 4;INK 0;AT h(c+1),c;"#"

One value for each column

DIM h(32) creates a numeric array with 32 elements. An array lets one name refer to several values by index. h(1) and h(2) are different stored values, not multiplication or a call to a drawing routine.

Line 30 assigns 20 to every element. Sinclair array indices here run from 1 to 32, while screen columns run from 0 to 31. The expression h(c+1) connects them: column 0 uses element 1; column 31 uses element 32.

The array is created once when RUN starts the program. Retry redraws the site using those same heights and resets the flight values. The unchanging landscape and the changing attempt have different lifetimes.

Make drawing and contact agree

The drawing routine replaces its fixed first ground row with h(c+1). Its inner FOR loop fills that column from the surface through row 21, and the skyline PRINT places a # at the surface. With every value set to 20, the result should look like the previous flat site.

The contact calculation uses 100*(h(nx+1)-1). It selects the candidate column’s surface, subtracts one row for the craft’s one-cell footprint, then converts rows to our position units. Drawing and downward contact now consult the same value.

If we change the drawing to use h but leave the landing limit fixed at 1900, what can go wrong?

Show the explanation

A raised column would look solid above row 20 while the craft still fell towards the old limit. The visible ground and the contact rule would describe different sites. Both must use the height array.

Test the representation before the landscape

First repeat an ordinary flat-pad approach. Its rules and starting values have not changed. A different result should prompt an indexing or replacement check, rather than an immediate change to gravity.

For a focused experiment, add 35 LET h(19)=18. That raises screen column 18, just outside the pad. Leave steering alone and descend vertically above that column. Its skyline should move to row 18, and the craft should stop above it at position 1700. Row numbers grow downwards, so a smaller height value creates taller ground.

This experiment checks downward contact. Sideways entry into a raised column needs a further rule: a craft can already be below that column’s surface when it moves into it. Do not treat this checkpoint as the finished uneven-terrain game. Remove line 35 and restore the flat site before the next lesson.

Complete program for this step
10 BORDER 0: PAPER 0: INK 7: BRIGHT 1: CLS
20 DIM h(32)
30 FOR c=1 TO 32: LET h(c)=20: NEXT c
50 PRINT AT 3,9;"TOUCHDOWN"
60 PRINT AT 6,2;"O / P: steer left / right"
70 PRINT AT 8,2;"SPACE: thrust (with steering)"
80 PRINT AT 10,2;"Pad: ========  Safe: 0 to 12"
90 PRINT AT 12,2;"Empty tank? You still coast."
100 PRINT AT 15,2;"S launches. Q quits."
110 GO SUB 800: IF k$="q" THEN GO TO 850
120 CLS: GO SUB 600
130 LET x=18: LET y=400: LET v=0: LET fuel=45: LET r=4: LET burn=0
140 PRINT AT r,x;"A"
150 PRINT AT 0,1;"FUEL       SPEED       MAX 12"
160 PRINT AT 1,1;"O/P STEER  SPACE THRUST  Q QUIT"
200 LET k$=INKEY$: IF k$="q" THEN GO TO 850
210 LET keys=IN 57342: LET nx=x
220 IF INT (keys/2)-2*INT (keys/4)=0 THEN LET nx=nx-1
230 IF keys-2*INT (keys/2)=0 THEN LET nx=nx+1
240 IF nx<1 THEN LET nx=1
250 IF nx>30 THEN LET nx=30
260 LET burn=0: LET keys=IN 32766
270 IF keys-2*INT (keys/2)=0 AND fuel>0 THEN LET burn=1: LET fuel=fuel-1
280 LET v=v+2-6*burn
290 IF v>60 THEN LET v=60
300 IF v<-30 THEN LET v=-30
310 LET ny=y+v: LET contact=0: LET limit=100*(h(nx+1)-1)
330 IF ny>=limit THEN LET contact=1
340 IF contact=1 THEN LET ny=limit
350 IF ny<300 THEN LET ny=300: LET v=0
360 LET nr=INT (ny/100)
370 PRINT AT 0,6;fuel;"  ";AT 0,19;v;"   "
375 LET a$="A": IF burn=1 THEN LET a$="*"
380 PRINT AT r,x;" ";AT nr,nx;a$
390 LET x=nx: LET y=ny: LET r=nr
400 IF contact=1 THEN GO TO 700
410 PAUSE 2: GO TO 200
600 FOR c=0 TO 31
610 FOR j=h(c+1) TO 21: PRINT PAPER 4;INK 0;AT j,c;" ";: NEXT j
620 PRINT PAPER 4;INK 0;AT h(c+1),c;"#"
630 NEXT c
640 FOR c=20 TO 27: PRINT PAPER 6;INK 0;AT 20,c;"=": NEXT c
650 RETURN
700 PRINT AT r,x;"A"
710 LET m$="Off the pad."
720 IF x>=20 AND x<=27 THEN LET m$="Too fast for the pad."
730 IF x>=20 AND x<=27 AND v<=12 AND v>=0 THEN LET m$="Safe landing!"
740 PRINT AT 2,1;m$;"    "
770 PRINT AT 1,1;"R retries. Q quits.            "
780 IF INKEY$<>"" THEN GO TO 780
790 LET k$=INKEY$: IF k$<>"r" AND k$<>"q" THEN GO TO 790
795 IF INKEY$<>"" THEN GO TO 795
796 IF k$="q" THEN GO TO 850
797 GO TO 120
800 IF INKEY$<>"" THEN GO TO 800
810 LET k$=INKEY$: IF k$<>"s" AND k$<>"q" THEN GO TO 810
820 IF INKEY$<>"" THEN GO TO 820
830 RETURN
850 IF INKEY$<>"" THEN GO TO 850
860 PAPER 0: INK 7: CLS: PRINT "Finished.": STOP

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 12 (numeric arrays), and chapters 15–16 (screen placement and colour).