Skip to content
Game 7 Unit 7 of 16 1 hr learning time

Levels

Add level progression — more coins and hazards each time.

44% of Treasure Hunt

Collecting five coins and seeing “GAME OVER” isn’t much of a game. Real games get harder. Clear the coins, advance to the next level, face more of everything.

The Program

10 CLS
20 LET r = 10
30 LET c = 15
40 LET n = 0
50 LET v = 3
60 LET l = 1
70 LET f = 5
80 LET h = 2
90 GO SUB 500
100 GO SUB 600
110 GO SUB 700
120 REM game loop
130 GO SUB 800
140 LET k$ = INKEY$
150 IF k$ = "" THEN GO TO 140
160 PRINT AT r, c; " "
170 IF k$ = "q" AND r > 1 THEN LET r = r - 1
180 IF k$ = "a" AND r < 20 THEN LET r = r + 1
190 IF k$ = "o" AND c > 0 THEN LET c = c - 1
200 IF k$ = "p" AND c < 31 THEN LET c = c + 1
210 LET a = ATTR (r, c)
220 IF a = 49 THEN LET n = n + 1: BEEP 0.05, 20: LET f = f - 1: GO SUB 700
230 IF a = 58 THEN GO SUB 900
240 GO SUB 800
250 IF v = 0 THEN GO TO 400
260 IF f = 0 THEN GO SUB 1000
270 GO TO 140
400 REM game over
410 CLS
420 PRINT AT 8, 10; "GAME OVER"
430 PRINT AT 10, 8; "Level: "; l
440 PRINT AT 11, 8; "Coins: "; n
450 BEEP 0.5, -10
460 STOP
500 REM === place coins ===
510 LET g = 5 + l
520 LET f = g
530 FOR i = 1 TO g
540 LET y = INT (RND * 19) + 2
550 LET x = INT (RND * 32)
560 INK 6: PRINT AT y, x; "*": INK 0
570 NEXT i
580 RETURN
600 REM === place hazards ===
610 FOR i = 1 TO h
620 LET y = INT (RND * 19) + 2
630 LET x = INT (RND * 32)
640 INK 2: PRINT AT y, x; "#": INK 0
650 NEXT i
660 RETURN
700 REM === draw HUD ===
710 PRINT AT 0, 0; "L:"; l; " Coins:"; f; "  Lives:"; v; "  "
720 RETURN
800 REM === draw player ===
810 INK 4: PRINT AT r, c; "O": INK 0
820 RETURN
900 REM === lose life ===
910 LET v = v - 1
920 BEEP 0.2, -5
930 GO SUB 700
940 LET r = 10: LET c = 15
950 RETURN
1000 REM === next level ===
1010 LET l = l + 1
1020 LET h = h + 1
1030 BEEP 0.2, 12: BEEP 0.2, 16: BEEP 0.3, 19
1040 CLS
1050 PRINT AT 10, 8; "Level "; l; "!"
1060 PAUSE 50
1070 CLS
1080 LET r = 10: LET c = 15
1090 GO SUB 500
1100 GO SUB 600
1110 GO SUB 700
1120 RETURN

Level 1 with coins and lives display

What’s New

Variable l tracks the current level, starting at 1.

Dynamic difficulty (line 510). LET g = 5 + l means level 1 has 6 coins, level 2 has 7, and so on. The variable h increases hazards each level too.

Level complete (line 260). When f (coins remaining) reaches 0, the game calls the “next level” subroutine.

Next level (lines 1000-1120). Increases the level counter and hazard count. Clears the screen. Shows “Level 2!” for a moment. Then redraws everything — new coins, new hazards, new HUD.

The HUD

The HUD now shows three pieces of information:

710 PRINT AT 0, 0; "L:"; l; " Coins:"; f; "  Lives:"; v; "  "

The trailing spaces overwrite any leftover characters from previous values. Without them, switching from “Coins:10” to “Coins:9” would leave a stray “0”.

Level as Multiplier

Using the level number in formulas is a clean way to scale difficulty:

LevelCoins (5+l)Hazards (h)
162
273
384

Each level feels noticeably harder without any special logic.

Try This

Victory at level 5. Add a check: IF l > 5 THEN CLS: PRINT AT 10, 8; "YOU WIN!": STOP. Five levels is enough for a complete game.

Level display. Make the “Level 2!” screen more dramatic — add colour, a sound effect, or a short pause.

What You’ve Learnt

  • Level progression — clear all objectives to advance
  • Dynamic difficulty — use the level number in formulas
  • Screen reset — CLS and redraw for a new level
  • The next-level subroutine — a clean transition between levels