The Complete Game
Combine everything into the finished Treasure Hunt game with levels, timer, and game over.
Every piece is ready. Title screen, arena, coins, hazards, collision detection, lives, levels, timer, sound, colour. Now combine them into a complete game.
The Complete Program
10 REM Treasure Hunt
20 BORDER 0
30 PAPER 0
40 INK 7
50 CLS
60 INK 6
70 PRINT AT 3, 8; "TREASURE HUNT"
80 INK 7
90 PRINT AT 7, 4; "Collect all the coins to"
100 PRINT AT 8, 4; "clear each level."
110 PRINT AT 11, 4; "Avoid the hazards! They"
120 PRINT AT 12, 4; "cost you a life."
130 PRINT AT 15, 4; "Controls:"
140 PRINT AT 16, 6; INK 5; "Q"; INK 7; " Up "; INK 5; "A"; INK 7; " Down"
150 PRINT AT 17, 6; INK 5; "O"; INK 7; " Left "; INK 5; "P"; INK 7; " Right"
160 INK 3: PRINT AT 20, 5; "Press any key to play": INK 7
170 IF INKEY$ = "" THEN GO TO 170
180 LET r = 10: LET c = 15
190 LET n = 0: LET v = 3: LET l = 1
200 GO SUB 1000
210 LET m = 500
220 LET t = PEEK 23672 + 256 * PEEK 23673
230 REM === game loop ===
240 INK 4: BRIGHT 1: PRINT AT r, c; "O": BRIGHT 0: INK 7
250 LET e = PEEK 23672 + 256 * PEEK 23673
260 LET d = INT ((e - t) / 50)
270 LET w = m - d
280 IF w < 0 THEN LET w = 0
290 PRINT AT 0, 0; "L:"; l; " C:"; f; " V:"; v; " T:"; w; " "
300 IF w = 0 THEN GO TO 600
310 LET k$ = INKEY$
320 IF k$ = "" THEN GO TO 240
330 PRINT AT r, c; " "
340 LET u = r: LET z = c
350 IF k$ = "q" THEN LET u = r - 1
360 IF k$ = "a" THEN LET u = r + 1
370 IF k$ = "o" THEN LET z = c - 1
380 IF k$ = "p" THEN LET z = c + 1
390 IF u < 2 OR u > 20 THEN LET u = r
400 IF z < 1 OR z > 30 THEN LET z = c
410 LET a = ATTR (u, z)
420 IF a = 5 THEN GO TO 240
430 LET r = u: LET c = z
440 IF a = 6 THEN LET n = n + 1: LET f = f - 1: BEEP 0.05, 20
450 IF a = 2 THEN GO SUB 1500
460 INK 4: BRIGHT 1: PRINT AT r, c; "O": BRIGHT 0: INK 7
470 IF v = 0 THEN GO TO 600
480 IF f = 0 THEN GO SUB 1600
490 GO TO 240
600 REM === game over ===
610 CLS
620 INK 2: PRINT AT 5, 10; "GAME OVER": INK 7
630 PRINT AT 8, 8; "Level: "; l
640 PRINT AT 9, 8; "Coins: "; n
650 IF n >= 30 THEN PRINT AT 12, 6; "Amazing treasure hunter!"
660 IF n >= 15 AND n < 30 THEN PRINT AT 12, 8; "Well done!"
670 IF n < 15 THEN PRINT AT 12, 6; "Better luck next time!"
680 BEEP 0.2, 7: BEEP 0.2, 5: BEEP 0.2, 2: BEEP 0.4, 0
690 INK 3: PRINT AT 20, 5; "Press any key to exit": INK 7
700 IF INKEY$ <> "" THEN GO TO 700
710 IF INKEY$ = "" THEN GO TO 710
720 BORDER 7: PAPER 7: INK 0: CLS
730 STOP
1000 REM === draw arena ===
1010 CLS
1020 INK 3
1030 FOR i = 0 TO 31
1040 PRINT AT 1, i; "="
1050 PRINT AT 21, i; "="
1060 NEXT i
1070 FOR i = 1 TO 21
1080 PRINT AT i, 0; "|"
1090 PRINT AT i, 31; "|"
1100 NEXT i
1110 INK 7
1120 GO SUB 1200
1130 GO SUB 1300
1140 RETURN
1200 REM === place coins ===
1210 LET g = 5 + l * 2
1220 LET f = g
1230 FOR i = 1 TO g
1240 LET y = INT (RND * 18) + 2
1250 LET x = INT (RND * 29) + 1
1260 IF ATTR (y, x) <> 7 THEN GO TO 1240
1270 INK 6: PRINT AT y, x; "*": INK 7
1280 NEXT i
1290 RETURN
1300 REM === place hazards ===
1310 FOR i = 1 TO l + 1
1320 LET y = INT (RND * 18) + 2
1330 LET x = INT (RND * 29) + 1
1340 IF ATTR (y, x) <> 7 THEN GO TO 1320
1350 INK 2: PRINT AT y, x; "#": INK 7
1360 NEXT i
1370 RETURN
1500 REM === lose life ===
1510 LET v = v - 1
1520 BEEP 0.1, 0: BEEP 0.1, -3: BEEP 0.2, -7
1530 LET r = 10: LET c = 15
1540 RETURN
1600 REM === next level ===
1610 LET l = l + 1
1620 LET m = 500 - l * 20
1630 BEEP 0.15, 12: BEEP 0.15, 16: BEEP 0.3, 19
1640 CLS
1650 INK 6: PRINT AT 10, 10; "Level "; l; "!": INK 7
1660 PAUSE 75
1670 GO SUB 1000
1680 LET r = 10: LET c = 15
1690 LET t = PEEK 23672 + 256 * PEEK 23673
1700 RETURN

The Structure
The program has a clear architecture:
| Lines | Section |
|---|---|
| 10-170 | Title screen |
| 180-190 | Initialise variables |
| 200 | Draw arena |
| 210-290 | HUD with timer |
| 300-310 | Game loop — input |
| 330-450 | Movement and collision |
| 460-490 | Win/lose checks |
| 600-730 | Game over screen |
| 1000-1140 | Draw arena subroutine |
| 1200-1290 | Place coins subroutine |
| 1300-1370 | Place hazards subroutine |
| 1500-1540 | Lose life subroutine |
| 1600-1700 | Next level subroutine |
Collision Detection
With PAPER 0, the ATTR values are simple — just the INK number:
420 IF a = 5 THEN GO TO 240
430 LET r = u: LET c = z
440 IF a = 6 THEN LET n = n + 1: LET f = f - 1: BEEP 0.05, 20
450 IF a = 2 THEN GO SUB 1500
| ATTR | Colour | Action |
|---|---|---|
| 5 | Cyan | Wall — block movement |
| 6 | Yellow | Coin — collect it |
| 2 | Red | Hazard — lose a life |
| 7 | White | Empty — move freely |
The wall check (line 420) jumps back to the game loop without updating r and c. The player stays in place.

Coin Placement Validation
1260 IF ATTR (y, x) <> 7 THEN GO TO 1240
Coins only appear on empty cells (ATTR 7 = white ink on black paper). If the random position lands on a wall or hazard, it tries again. The same check protects hazard placement.
Level Progression
Each level increases the challenge:
1210 LET g = 5 + l * 2
1620 LET m = 500 - l * 20
| Level | Coins | Time limit | Hazards |
|---|---|---|---|
| 1 | 7 | 480 | 2 |
| 2 | 9 | 460 | 3 |
| 3 | 11 | 440 | 4 |
More to collect, less time to do it, more to avoid.
Game Over

Three tiers of feedback based on total coins collected:
| Coins | Message |
|---|---|
| 30+ | “Amazing treasure hunter!“ |
| 15-29 | ”Well done!“ |
| 0-14 | ”Better luck next time!” |
The game-over melody (four descending notes) and the level-up fanfare (three ascending notes) bookend the experience.
Try This
High score. After game over, store n in a variable and offer to play again. Show the high score on the title screen: PRINT AT 19, 8; "High: "; h.
Power-ups. Add a green + that gives an extra life when collected. Place it with INK 4 and check for ATTR 4.
Maze levels. Create different wall layouts for each level. Use IF l = 2 THEN GO SUB 1800 to call different arena-drawing subroutines.
What You’ve Learnt
- Program architecture — title, game loop, subroutines, game over
- Combining systems — timer, collision, levels, sound, colour
- Difficulty scaling — formulas that use the level number
- Check-before-move — propose position, test it, commit or reject
- Screen as data — ATTR reads the game world directly
What’s Next
You’ve built your first real-time game — with a proper game loop, subroutines, collision detection, and level progression. In Game 8, you’ll use 2D arrays to build a logic game where the data lives in memory, not on screen. The grid becomes data first, display second.