BBC BASIC 2.31 for the Tatung Einstein, showing DRIFT, the text adventure the course builds, in the middle of a game
← Back to Courses
module
28

Finishing Touches

Introduction

DRIFT works. This section makes it feel finished: a title screen to start it, a sound when the power comes on and a tune when you win, and now and then a noise from the ship to remind you that you are alone on it.

A Title

PROCTITLE clears the screen, prints the name in yellow and a subtitle in white, and waits for a key with GET$. Then it clears the screen again, and the game begins.

Sound

S16's RND made numbers; SOUND makes notes. On the Einstein it takes four numbers:

SOUND 1,-15,100,TRUE
  • the channel - which of the sound chip's voices plays it; DRIFT uses 1;
  • the loudness, from -15 (loudest) to 0 (silent);
  • the pitch - 100 is middle C, and every 4 more is a semitone higher: 116 is E, 128 is G, 148 the C above;
  • and TRUE to start the note, FALSE to stop it.

That last one is the thing to know. A note, once started, goes on sounding until you stop it - the fourth number is not how long it lasts. So PROCBEEP(P%) starts a note, waits 30 hundredths of a second by watching TIME, and stops it. PROCTUNE plays four beeps: C, E, G, C.

The Ship Talks

PROCNOISE runs after most turns. One time in six - RND(6) is 1 - it picks one of three messages from DATA at random and prints it: THE HULL CREAKS. It uses RESTORE 3400 and reads 1, 2 or 3 of them, printing the last.

The Code

LOAD "ADV8". Add these lines, replacing 4210:

30 PROCTITLE
105 IF OVER%=0 THEN PROCNOISE
2850 PROCBEEP(148)
3400 DATA THE HULL CREAKS.,SOMETHING TAPS ON THE HULL.,A LIGHT FLICKERS AND DIES.
4210 IF OVER%=1 THEN PROCWRAP("THE ENGINES ROAR INTO LIFE. THE SHIP TURNS FOR HOME. YOU HAVE MADE IT."):PRINT "AIR TO SPARE: ";AIR%:PROCTUNE
4400 DEF PROCTITLE
4410 CLS:COLOUR 11:PRINT TAB(15,6);"D R I F T"
4420 COLOUR 15:PRINT TAB(9,10);"A SHIP ADRIFT IN SPACE"
4430 PRINT TAB(11,16);"PRESS ANY KEY";
4440 K$=GET$:CLS
4450 ENDPROC
4500 DEF PROCBEEP(P%)
4510 LOCAL T%
4520 SOUND 1,-15,P%,TRUE:T%=TIME:REPEAT UNTIL TIME>T%+30:SOUND 1,0,P%,FALSE
4530 ENDPROC
4600 DEF PROCTUNE
4610 PROCBEEP(100):PROCBEEP(116):PROCBEEP(128):PROCBEEP(148)
4620 ENDPROC
4700 DEF PROCNOISE
4710 LOCAL I%,M$
4720 IF RND(6)>1 THEN ENDPROC
4730 RESTORE 3400:FOR I%=1 TO RND(3):READ M$:NEXT
4740 PRINT M$
4750 ENDPROC

Starting from

LOAD "ADV8" from S27. When it works, SAVE "ADV9". That is the finished game: the whole listing, 211 lines, is in Appendix III, and the course disc carries it as GAME - CHAIN "GAME" plays it.

What you should see

The title screen first. Press a key, and the game begins as before. Somewhere along the way the ship makes a noise. Fitting the cell beeps; winning plays four rising notes.

The title screen

Change One Thing

  • Change line 4720 to IF RND(2)>1 THEN ENDPROC. How chatty is the ship now?
  • Change line 4410's COLOUR 11 to COLOUR 9. What colour is the title?
  • Change the pitches in line 4610 - to 148, 128, 116, 100, say. What does the tune do now?

Exercises

28.1 Add a fourth noise of your own. (Two lines change: the DATA, and the RND in 4730.)

28.2 Make the tune longer, with a note at pitch 136 - the A between the G and the top C.

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
A note never stopsIts SOUND ... FALSE is missing. ESC stops the program and the note together.
SOUND 1,-15,100,20 just clicksThe fourth number is start or stop, not a length. Use TRUE, and stop it yourself.
No noise ever appearsIt only comes one turn in six. Play longer, or change 4720.

Summary

PROCTITLE shows a title and waits for a key. SOUND starts and stops notes: channel, loudness, pitch, TRUE or FALSE - and every 4 in the pitch is a semitone. RND picks when the ship speaks and what it says. Save it as ADV9: DRIFT is finished.

Next

S29, Reading A Real Program - a 1984 program from the disc.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.