STEP BY STEP PROGRAMMING GUIDE TO STOS BASIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hello there. This is MEGADAZ guiding you through the aspects of programming in STOS Basic. I have had approximately 5 years experience with this widely popular package, and have games, demos and utilities all around Public Domain which I have created using STOS. This tutorial is mainly structured around STOS, but a lot of the more basic commands will apply to many, many other basics on the computer range, on all computers. It is targeted at those beginners who have no clue whatsoever as to programming, but may build up to some complex stuff, if I get there. This tutorial does not specifically tell you how to use STOS itself, but just how to program in Basic. I chose STOS because of its flexibility, ease of use, and quickness of creating programs. I have also included exercises and questions in this tutorial so you can have a go at programming yourself. The answers are at the end. I will attempt to make everything as straight-forward and as easy-to- understand as possible. (And excuse me for any careless spelling mistakes or mis-types, I am only 14 years old at the time of writing this!) P.S. I hope you have got a printer, because this is quite a long document, and you will need to type in examples from this tutorial. Finally, good luck and HAPPY PROGRAMMING! ######################################################################## Session 1] What is BASIC? -------------- Well, this stands for Beginners All-purpose Symbolic Instruction Code. - - - - - It is the highest-level programming language you can get. That menas, the easiest to understand, and most English-like, as it was designed to make programming of games and suchlike to be quick and easy without bothering about system calls and addressing modes in assembler (of which I am very unfamiliar!) Everything you see from games to utilities, from demos to databases are made from a long list of instructions telling the computer to do certain tasks. These instructions (called COMMANDS) are executed at a VERY FAST speed (hundreds per second). In STOS Basic, line numbers are used before each instruction. This effectively numbers each instruction. As each line number is typed in and the command(s) after it, the computer sorts the LIST of commands out into numerical order depending on the line numbers. Before I go any further, I will tell you there are two methods of entering (or INPUTTING) data; Direct and Line-numbers. If a command is entered without a line number, as soon as RETURN is pressed, that command will be acted on by the ST immediately (DIRECT COMMAND) but if it has a line number before it, that command will be stored in memory along with the others ready to be played back (or RUN). First of all, let's get familiar with a few of the very basic commands so I have something to use as examples. PRINT You are likely to have heard of this command. It simply prints a line of text to the screen. If it is entered directly (remember, no line number) then the computer will print out the text or whatever straight away. If just PRINT is entered, it means skip a line, because no text has been entered after it to tell the computer exactly what to print. 10 PRINT This command is with a line-number. Press RETURN to enter the line into memory. When RUN (replayed), it tells the computer to miss a line. If you want to print some text out, include it in quotation marks (I call them quotes " ") after the command. eg. PRINT "Hello there, this is a test!" When RETURN is pressed, will do this: Hello there, this is a test! 10 PRINT "Hello there." 20 PRINT "This is MEGADAZ with" 30 PRINT "the PRINT command!" This is a short program telling the computer to print things to the screen. When RUN is entered (as a DIRECT command), the ST will show this: Hello there. This is MEGADAZ with the PRINT command! What the computer has done is gone through the program line-by-line and executed what you have told it to do. It started on line 10, printed the text, moved onto 20, printed the other text, and moved to 30 and printed the final text. There are no more lines, so control is restored to you. Here is another command, CLS. This stands for Clear Screen and does just that. 10 CLS 20 PRINT "I have just cleared the screen." 30 PRINT "Good, isn't it?" When run, the screen will clear and the text will be printed. If CLS is entered on its own (DIRECT) and RETURN pressed, the screen will clear. NB. To execute a direct command, or to store a line number in memory, RETURN must be pressed after the command(s) are entered. Now, when we have finished with this program and we do not want it in memory any longer, type in NEW (as a direct command). This clear all the line numbers ready for a new program. If you over-write an existing line number with a new one, for example: 10 PRINT "Hello" 20 PRINT "There" 10 PRINT "Greetings" When you type RUN, you will get Greetings There Because the 'Hello' has been over-written by 'Greetings'. ####################################################################### So, at the end of session 1, we have learned: * What BASIC is. * What a program is. * What the difference between DIRECT and LINE-NUMBER programming is. * Two simple commands with examples. * How to erase a program from memory ready for a new one. ####################################################################### Session 2] I have told you that commands are stored with line-numbers (a sort of pointer to the command) but more than one command can be stored on a line. Two or more commands are separated with a colon : For example, instead of typing... 10 PRINT 20 PRINT "HELLO" 30 PRINT 40 PRINT "THERE" 50 PRINT You can squeeze it into less lines, like this: 10 PRINT : PRINT "HELLO" : PRINT : PRINT "THERE" : PRINT Here, I have moved all commands onto line number 10. Using this method of programming allows the user to group certain parts of the program together to shorten the length of the program and simplify it. Another example: 10 PRINT : PRINT 20 PRINT "This is the second line." : PRINT 30 PRINT "Hello" 40 PRINT : PRINT : PRINT : PRINT : PRINT Less importantly, colons can be used on their own to separate the program out so each part is plainer to see. For example. 10 PRINT "This is the first part" 20 : 30 : 40 PRINT "In the listing, the gap between this command and the one" 50 PRINT "above is significant, helping you to search easier." 60 : 70 : 80 PRINT "The final part." Here is another command which can ONLY be used as a direct command: LIST This simply lists through your program that you typed in. Type in the above example, run it if you want, and then type LIST followed by RETURN and VOILA! You get the list of your progam in front of you ready for addition, edition or deletion. This can be entered in as many times as you like. Another command is WAITKEY. This freezes the program until the user presses a key. For example: 10 CLS 20 PRINT "Press any key to continue." 30 PRINT : WAITKEY 40 CLS 50 PRINT "Well done, you just pressed a key!" Lets examine each line in turn: 10 Clears the screen 20 Prints the text to the screen 30 Leaves a gap and waits for a keypress (note the dividing colon) 40 Clears the screen again 50 Prints text to the screen Now type, 12 PRINT : PRINT : PRINT 14 PRINT "My first WAITKEY example program" Now type LIST. These two lines are entered into your program in the correct order. Now RUN it again and you get a little title sequence. Other notes: * The limit your line numbers can go up to is 65535, so don't worry about that! * Line numbers can be entered in ANY order, for example: 20, 10, 120, 70, 50, 30, 80, 90, 100, 110, 40 is perfectly acceptable. REMEMBER the computer sorts each line number as soon as you press RETURN so don't get the commands in the wrong order! * The increment between line numbers is also unimportant. With the examples so far, I have started at 10 and gone up in 10's. You can increase in ANY order you like. For example: 1, 2, 5, 444, 534, 777, 1024, 1025, 1027, 1028, 1032, 2000, 40000 is perfectly acceptable. Line numbers are usually entered in 10's so extra commands can be inserted into lines between them, for example: 10 PRINT "A" 20 PRINT "B" 30 PRINT "D" 40 PRINT "Oh blast! I missed a letter!" RUN To correct, 25 PRINT "C" 40 The empty line 40 simply erases the cursing remark. ####################################################################### At the end of session 2, you have learned: * The use of colons, * Two new commands, * More about line numbers. ###################################################################### Session 3] Let's have a look at disk operations. Ensure you have a blank, formatted disk you can use. Label it something like 'MY STOS PROGRAMS' and insert it into the disk drive. Type in any of the above programs. Now, as a direct command, type SAVE "stosprog.bas" and press RETURN. This saves the current program to disk under the filename 'STOSPROG.BAS'. STOS programs MUST end in .BAS for the saving procedure to work correctly. When it has finished saving, type in NEW. Now type LIST and you should get one empty space meaning no list in memory. Now type LOAD "STOSPROG.BAS" and when it has finished loading, type LIST to see the recovered program. Ex.1) Here is a small exercise for you to do. Type NEW. Now I want you to create a program which says "HELLO LADS" on the screen, waits for a keypress, clears the screen, and finally says "THE END". It doesn't matter whether you use colons on one line or more than one line, or both. This applies to all examples unless stated. NB. It doesn't matter what case (Capitals or lower) you type the commands in, but it will revert to lower case when it is entered into memory. Spaces also don't matter in most cases. Another command for you: CENTRE. This is exactly the same as PRINT, except it centralises the text on the X axis of the screen, for example: 10 PRINT : CENTRE "This is centralised text":PRINT 20 CENTRE "So is this!":PRINT 30 PRINT "This isn't though!" Variables --------- This is a VERY VERY important part of ANY program, so ensure you FULLY understand ALL aspects of it! If you are familiar with algebra, you should not have any trouble with this aspect. The phrase, 'A=1' or 'X=5' should be familiar. This simply assignes the letter A with 1 and the letter X with 5. These letters can be changed in memory at will. They can be used in combination with EVERY SINGLE command that takes parameters, for example: 10 A=2 20 PRINT A When RUN, this should print the number 2 to the screen, why? We have assigned the letter 2 to A, and told the computer to print what is in A, which is 2. WARNING: DO NOT GET CONFUSED BETWEEN 10 PRINT "A" and 20 PRINT A There is a great difference. Line 10 prints A to the screen and line 20 prints the algebraic contents of A to the screen. All contents default to 0 when not used. ie if you were to type PRINT Q straight away, you would get 0, because it has not been assigned yet. Q=55:PRINT Q would give 55. The term XY in algebra means multiply X by Y. In BASIC, it is just another variable name. For example: 10 XY=80 : SC=6 : MEGADAZ=99999 20 PRINT XY : PRINT SC : PRINT MEGADAZ : PRINT "MEGADAZ" Notice the difference between the last two commands. ####################################################################### At the end of session 3, we have covered: * Disk access (saving and loading programs), * A new command, * Basic variable use. ####################################################################### Session 4] More about variables. Study this program carefully: 10 A=10 20 B=3 30 PRINT A-B Ex. 2) What does the above program do? It assigns 10 to A and 3 to B. It then prints the result of the simple sum A-B or effectively 10-3 which is 7. Here are more examples: 5 X=2 6 Y=1 7 PRINT X+Y 8 A=0 9 B=500 10 PRINT A+B 11 PRINT A+B+B 12 PRINT A+B-B 13 PRINT X-Y-Y 15 PRINT B-X-X+Y-A Make sure you know what each line does. Line 15 is quite complicated, here is a run-down: Print the result of the equation; B subtracted by X subtracted by X again, added by Y and subtracted by A. Effectively, this means; 500 minus 2 minus 2 plus 1 minus 0, which equals 497. There is not just + and -. Multiply = * Divide = / 10 A=10 15 B=2 20 PRINT A*B 25 PRINT A/B 30 PRINT B/A*A Here is another command, GOTO. This makes the program jump backward or forward to a certain line number, for example. 10 PRINT "Hello." 20 GOTO 10 Before you run this program, remember that CONTROL and C is used to break out of a program, you'll need it! Now RUN it. Silly, isn't it? Lots of Hello's running down the screen infinitely. What is happening? 10 Prints the word hello. 20 Goes to line 10 10 Prints the word hello. 20 Goes to line 10 10 Prints the word hello. And so on, forever! Here is a more interesting program: 10 A=0 20 PRINT A 30 A=A+1 40 GOTO 20 RUN BEFORE you run this program, Ex. 3) What do you predict will happen? Here is a breakdown of the program: 10 Sets A to 0 20 Prints the contents of A 30 Increases A by 1 40 Goes to line 20 which prints the new number, and so on. Line 30 logically meand 'A equals A's old contents plus 1.' Ex. 4) How would you modify the program to count up in two's? Ex. 5) How would you modify the program to count DOWN from 2000 in one's? I hope you got these exercises correct, and if you did not, I strongly advise you ensure you understand the workings of the program before continuing. Here is more about the PRINT function. If you follow the text to be printed by a semi-colon, for example: 10 PRINT "HELLO "; 20 PRINT "THERE!" then, the next thing to be printed will NOT start on the next line, but will print NEXT to the previously-printed text. RUN the above example to see what I mean. You would expect the program to output HELLO THERE But it outputs HELLO THERE because of the inclusion of the semi-colon. Notice the space I placed after the HELLO. If this were not there, you would get this, HELLOTHERE Semi-colons can be used with variables as well. 10 A=2 15 B=3 20 C=4 25 PRINT A 30 PRINT A;B 35 PRINT A;B;C You can get more complicated by mixing text and variables: 10 A=4 12 PRINT "The contents of A are ";A;" aren't they?" Line 12 does the following: Prints "The contents of A are", then 4 (in A), then " aren't they?" Try this little program: 10 A=0 20 PRINT A; 30 A=A+1 40 GOTO 20 RUN Interesting... Ex. 6) What will 'A=40 : PRINT A-10' print? Ex. 7) What will the following program print? 1 A=4 : B=6 2 PRINT A+40-B/2 This is just the simple mixing of variables and numbers. Ex. 8) Write a program which will print two numbers side-by-side. The numbers on the left increment from 100 onwards by one, and the numbers on the right decrement from 500 downward by five. There should be a gap of 5 spaces between the two numbers. Ex. 9) Modify the above program to miss a line after printing the two lines of numbers. ####################################################################### Now, you should be able to: * Understand the GOTO command, * Know what the semi-colon does, * Mix text and variables, * Change variables with + - * /. ####################################################################### Session 5] Now I will introduce you to more commands. Here are three very simple commands for sound effects: BELL SHOOT BOOM Type each one in individually as a direct command. 10 PRINT "Press a key" 12 WAITKEY 14 BELL 16 PRINT "Ding!" 15 CLS Ex.10) What will the above program do? Here is another command which is important: INPUT This does not work on its own, you need to use a target variable, eg: INPUT A This command gets a number from the user and places it in A. It is like A=1 or A=2 or whatever, except the number placed in A is inputted by the user during the program. Try this: 10 PRINT "Type in any number and press RETURN." 20 INPUT N 30 PRINT "The number you typed in was ";N 40 PRINT "That number doubled is ";N*2;" isn't it?" Breakdown: 10 Prints text 20 Gets a number from user and puts it in N 30 Prints text, with N on the end 40 Prints text, with N multiplied by 2, with more text. Another example: 10 INPUT X : INPUT Y : INPUT Z 20 PRINT "X:";X;" Y:";Y;" Z:";Z 30 PRINT X+Y+Z 40 PRINT X-Y-Z Instead of having to type 'INPUT X : INPUT Y : INPUT Z' to get three different numbers, you can do the following: INPUT X,Y,Z This simply asks the user for three numbers, which are stored in X, Y, and Z respectively. Another format of INPUT is this: INPUT "Type in a number ->";N This prints the text, and then asks for an input without printing a question mark. ######################################################################## Now, at the end of session 5, we have learned: * Three new sound effects commands, * The use of the INPUT command, ######################################################################## Session 6] Strings ------- These are exactly like variables, except they can hold alphanumerics, spaces, punctuation etc. Instead of 'A' or 'X', it is 'A$' or 'X$'. You simply add a dollar $ sign to the end of the string name. Unlike variables, strings need the data to be in quotes (like PRINT). Some examples of these: NAME$="MEGADAZ" A$="Anything" X$="098" Q$="i*/444 ><;" SC$="000983" Ex.11) How would you get the ST to ask the user for a name? So, with your knowledge so far, you can write a simple questionaire program... 10 CLS : BELL 20 CENTRE "MY 1ST QUESTIONAIRE PROGRAM":PRINT:PRINT 30 INPUT "WHAT IS YOUR NAME? ";NAME$ 32 INPUT "HOW OLD ARE YOU? ";AGE 34 INPUT "WHERE DO YOU LIVE? ";ADDRESS$ 36 INPUT "HOW MANY PETS DO YOU HAVE? ";PETS 38 INPUT "FOR HOW MANY YEARS HAVE YOU OWNED AN ST? ";YEARS 40 PRINT "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 42 WAITKEY:CLS:CENTRE "RESULTS":PRINT :CENTRE "-------" 44 PRINT:PRINT:PRINT 46 PRINT "HELLO ";N$;".":PRINT "YOU ARE ";AGE;" YEARS OLD." 48 PRINT "YOU LIVE AT ";ADDRESS$;".":PRINT"YOU HAVE ";PETS;" PETS." 50 PRINT "AND YOU HAVE OWNED YOUR WEEL-EARNED ST FOR ";YEARS;" YEARS!" 55 PRINT:PRINT "AMAZING, ISN'T IT?":WAITKEY:GOTO 10 Notes: Line 42, 7 dashes (-) Here is another little command. Well, it's not really a command, its a sort of note: REM It is short for REMINDER or REMARK. ANYTHING on the same line which is entered in AFTER this command is TOTALLY IGNORED, so the user can write little remarks after complex bits of code, for example: 10 rem THIS IS THE START OF THE PROGRAM 12 PRINT "Type in a number" 14 INPUT GN : rem GET AN INPUT 16 AA=GN*2-AA+GN/3-GN+AA*4 : rem A SILLY AND TOTALLY MEANINGLESS EQUATION Ex.12) What would happen if the following line was entered and run? 10 rem PRINT "HELLO THERE" : INPUT Y : A$="NOW" : PRINT A$ Now we have covered some of the basics, I will now put in some notes for you to remember: * PRINT can be shortened to just ? although STOS changes to PRINT after. * The case of commands does not matter, although anything in quotes does. * Remember to type NEW before each example. Two more commands for you which are inseperably linked, GOSUB and RETURN. GOSUB acts exactly like GOTO, except when a RETURN is encountered, the program jumps the the very command AFTER the GOSUB. For example: 10 rem Start of program 20 ? "Jumping NOW!" : waitkey 30 gosub 70 40 ? "I have just returned from the loop" 50 ? "And now I will GOTO the last line." : waitkey 60 goto 100 70 ? "I am now in what is called a SUB-ROUTINE." 80 ? "Press any key to RETURN to the line after jump." : waitkey 90 return 100 ? "Fare the morrow. (Goodbye)" The advantages of using these two commands become clear in games. You could store line 1000 to print out the scores, so, when you want to update the scores, instead of typing in all the code again and again, all you need to do is GOSUB 1000, where it will print and return you to the command after the GOSUB. For example: 10 rem This is an invisible shoot 'em up! Honest! 20 SC=60 30 input "Increase the score by what? ";SCIN 40 SC=SC+SCIN : gosub 1000 : rem UPDATE SCORES 50 goto 30 1000 rem This is the score updation subroutine. 1001 print "And the current score might be ";SC;", OK?" 1002 return ######################################################################## Now, after Session 6, you probably can: * Use strings correctly, * Use GOSUB and RETURN, and know the difference from GOTO, * Create a simple questionaire, ####################################################################### Session 7] I will include the most important aspects here. One of them is the IF...THEN statement. Here is a simple example: IF A=5 THEN PRINT "OY! 'A' is 5 you know!" IF NAME$="NUGENT" then ? "Excuse me, can you go away please.....thanks." Logically, it means: If variable/string is equal to argument (number or string) then do a certain action. The first example simply means: If the variable in A is 5 then print the message. Here is a small program to demonstrate this: 10 rem ** THE WELL-TRENDY CONDITION PROGRAM THINGY ** 11 : 12 : 13 ? "Type in a number, 1, 2,3 or 4 please...yes now. Go on!" 14 input NUMB 15 if NUMB=1 then print "You crafty devil, you typed in 1 didn't you!" 16 if NUMB=2 then print "I think you pressed the second one, maybe" 17 if NUMB=3 then print "You did press 3, didn't you?" 18 if NUMB=4 then print "-TERMINATING PROGRAM-":end 19 ? 20 goto 13 Note the 'END' at the end of line 18....this simply ends the program and returns control to the editor. Really, this program asks for a number from 1-4 and acts upon each number, printing out some text, and if number 4 was chosen, quits. Other methods of using IF...THEN are: IF A=5 THEN - If A is EQUAL TO 5 then IF A<5 THEN - If A is LOWER THAN 5 then IF A>5 THEN - If A is HIGHER THAN 5 then IF A<>5 THEN - If A is NOT EQUAL TO 5 then IF A<=5 THEN - If A is LOWER THAN OR EQUAL TO 5 then IF A>=5 THEN - If A is HIGHER THAN OR EQUAL TO 5 then Here is another little program: 9 rem Another little program 10 PRINT "Type in two numbers, and I will tell you if one is higher" 11 PRINT "or lower than the other." :? 12 INPUT N1,N2 13 IF N1N2 THEN ? "Numb1 IF BIGGER THAN Numb2" 15 IF N1=N2 THEN ? "Numb1 EQUALS Numb2" 16 IF N1<>N2 THEN ? "Numb1 AND Numb2 ARE DIFFERENT" 17 ? "By the way, the numbers are":? "Numb1:";N1;" and Numb2:";N2;", OK?" 18 ? 19 input "Do you want another exciting go?";G$ 20 IF G$="YES" THEN CLS:GOTO 10 21 print "Oh! You spoil-sport." NB. The computer will only accept CAPITAL YES for another go, any other inputs: Y, y, yes, YO, yo, Oh! Yes Please!, YES MAYBE will not be accepted as they are NOT EXACTLY EQUAL TO "YES". Here is another important command that is used together with IF and THEN. It is called ELSE. This is added to the end of the entire statement to make the program do something else if the result of the test was negative. Here is an example: 1 ? "Oy! Can you type in a number from the keyboard, yes, that" 2 ? "grey/white thing in front of you. Yes, now. That's it. Well Done!" 3 ?:input a 4 IF A=1 then ? "You typed 1" else ? "You didn't type 1" This is the english version of line 4: If variable in A is equal to 1, then print "You typed 1" or ELSE print "You didn't type 1". Simple, isn't it? More than 1 else can be used in one line, although be careful you do not get all of the conditions mixed up. if a=1 then ? "1" else if a=2 then ? "2" else if a=3 then ? "3" else end Two last commands which can be incorporated with IF and THEN, are OR and AND. They are really self-explanatory. if a=2 OR a=3 then ? "A is either 2 or 3" if x=5 and v=9 then ? "X is 5, and V is 9 at the same time" Parenthesees (plural) can be used around the OR and AND commands to include lots of different conditions in one check. IF (S=3 AND B=4) OR (E=3 OR F$=":::") AND (E=4 AND E$="OY! THAT'S A BIT COMPLICATED!") THEN BOOM ELSE SHOOT In English, this means: (Big breath!) If either s=3 and b=4, or e=3 and f$=":::", and, e=4 and e$="OY! THAT'S A BIT COMPLICATED!", then boom, but if the aforementioned condition is false, then shoot. The program will BOOM if: E=4 E$="OY! THAT'S A BIT COMPLICATED!" either both S=3 AND B=4, or E=3 or F$=":::" If ANY of the above conditions are missing, or untrue (false) then the program will SHOOT. To sum up the entire IF...OR...THEN...ELSE subject, here is a program which includes all of the aspects... Note, on line 30 and others, it goes on after one line, so do NOT press return yet. 10 rem IF...THEN...ELSE 15 ? "Oy! Type in three numbers, one after the other. (From 0 to 9)":?:? 20 input a,b,c 21 if A<0 or a>9 then gosub 200:goto 10 22 if B<0 or B>9 then gosub 200:goto 10 23 if C<0 or C>9 then gosub 200:goto 10 24 cls:? "1st = ";a:? "2nd = ";b:? "3rd = ";c 25 : 26 : 28 rem ** THIS IS IT! ** 29 : 30 if A=1 then ? "The first number was 1, wasn't it?" else ? "The first number wasn't was, was it? Nah, it couldn't have been!" 31 if A=B then ? "The first two numbers are the same" 32 if A=B=C then ? "They were all the same! What a coincidence!" 33 if A>C then ? "The first one was higher than the third one" 34 if Bb then ? "A and B are different" 38 if c=0 then ? "C is 0" 39 if c<5 then ? "C is lower than 5" 40 if c>=7 then ? "C is either higher or equal to 7" 41 if b-a=0 then ? "B subtracted by A is 0" 42 if A+B+C=9 then ? "If you add A, B and C together, you get 9!" 198 rem I HOPE I PUT IN ENOUGH EXAMPLES FOR YOU! 199 END 200 BOOM: ? "Oy! I SAID BETWEEN 0 AND 9, can't you read?":return Just a couple of excersises for you to round off this section: Ex.13) Study the program: 10 X=9 : B=7 20 IF X=9 AND B<10 THEN BOOM Will the program boom? Ex.14) Study the program: 10 rem T=9 : N=9 20 IF T=9 OR N=9 THEN BELL Will the program bell? Ex.15) Study the program: 10 J=0 : K=84 : NAME$="ARNOLD" 20 IF (J>-55 AND NAME$<>"SYDNEY") OR K=7 THEN PRINT "YES!" ELSE PRINT "NO!" What will the program print? ######################################################################## Now, you should have learned: * Simple IF...THEN commands and their different arguments, * Additional use of ELSE during IF...THEN commands. * Additional use of OR and AND during IF...THEN commands. ######################################################################## Session 8] Let's go on to some graphic manipulation...drawing. You should know that the low resolution screen has 320x200 pixels, or PIcture Elements, a medium resolution screen has 640x200 pixels, and a high resolution screen has 640x400 pixels. A single co-ordinate for the screen is simply "X co-ordinate, Y co-ordinate". 0,0 is the top-left, 319x199 (in low res) is the bottom-right. Here is our first manipulation command, PLOT. This PLOTs a single point on the screen at the position given. ie PLOT 50,50 plots a pixel at 50,50 on the screen. PLOT 0,0 : PLOT 319,0 : PLOT 0,199 : PLOT 319,199 Here is another one, DRAW. This one needs two sets of co-ordinates, X1,Y1 to X2,Y2. This draws a line from X1,Y1 to X2,Y2. DRAW 0,0 to 319,199 : rem Draws a diagonal line from top-left to bottom- right. BOX 0,0 to 319,199 : rem Draws a hollow box from X1,Y1 to X2,Y2 BAR 0,0 to 319,199 : rem Draws a filled box from X1,Y1 to X2,Y2 CLS : RBOX 10,10 to 309,189 : rem Draws a rounded box RBAR 20,20 to 299,179 : rem Draws a filled, rounded box Here is another one, CIRCLE. It simply draws a circle with a centre- point of X and Y, and with a radius of R. The format o f this command is CIRCLE X,Y,R. CIRCLE 159,99,100 : rem Draws a largeish circle in the centre ELLIPSE X,Y,R1,R2 draws an oval with a centre-point at X and Y, and with two radii of R1 and R2. An example, CLS : ELLIPSE 159,99,80,25 : CIRCLE 0,0,9 : CIRCLE 319,199,19 Two very important commands are PEN and INK. They change the colours of the writing pen and drawing ink respectively. The defaults are PEN=1 and INK=15. These can vary from 0 (background, invisible) to 15. Try this program: 10 CLS : PEN 1 : CENTRE "MY FIRST DRAWING PROGRAM THINGIE" 12 ? : PEN 15 : ? :? "Type in the colour of the ink (0-15)" 14 PEN 14 : input c : PEN 10 16 if c<0 or c>15 then ? "I said from 0 to 15, fool!": goto 10 17 if c=0 then ? "You DO realise that you won't see the object!" 18 if c=1 then ? "White" else if c=0 then ? "Black" else if c=15 then ? "Cyan" else if c=14 then ? "Purple" else if c=13 then ? "Blue" else ? "I can't remember what colour it is!" 20 pen 12:?:?:? "Press any key to draw the shape":waitkey 22 cls : ink C : circle 159,199,50 23 ellipse 159,10,80,10 : ellipse 159,189,90,10 24 waitkey : cls : ? "Another one? (Y for yes, N for Nay)" 25 input c$ : if C$="Y" then goto 10 else if C$="N" then end else ? "Look , it isn't funny, it isn't clever, now it's either Y or N!": goto 25 ######################################################################## So, at the end of this sesh, you should be able to, * Change PEN and INK, * Draw to screen using primitive shapes, ######################################################################## Session 9] Here is another command, LOCATE. This one locates the text cursor at location XX,YY. So if we wanted to place the cursor at the top-left, we would write LOCATE 0,0 To place the cursor at 7 across by 11 down, we would type LOCATE 7,11. 10 CLS 14 LOCATE 0,0:PRINT "THIS IS THE TOP LEFT" 18 LOCATE 27,18:PRINT "THIS ISN'T" 20 waitkey:end Another example: 10 CLS : PEN 15: CENTRE "STAR PLOTTER":PEN 1 12 LOCATE 0,15:PRINT "INPUT X AND Y CO-ORDS FOR STAR (0-37 AND 2-14)" 13 INPUT X,Y 14 IF X<2 OR X>37 OR Y<2 OR Y>14 THEN BOOM:GOTO 12 27 PEN 14:LOCATE X,Y:? "*":PEN 1:GOTO 12 Here is another rather important command, RND. This is short for RANDOMIZE, which will force the computer to give the user a random number from 0 to the stated number. This is the format: A=RND(100) would get any number from 0 to 100 and place it in A. PRINT RND(10) would print a number from 0 to 10. PRINT RND(20)+20 would print a number from 20 to 40 (0-20 plus 20). So, with the knowledge we have learned so far, we can put together our first small game, of which you may be familiar... 1 rem OH NO! PLEASE DON'T BE THAT NUMBER GUESSER PROGRAM! 2 rem 3 rem OH BOTHER, IT IS. OH WELL, IT IS QUITE IMPORTANT, SO I MIGHT 4 rem AS WELL TYPE IT ALL IN... 5 rem 10 cls : pen 1 : under on : locate 0,0 : centre "Number Guesser!" 11 under off : pen 14 : locate 0,3 12 print "Yes, it is that cheap and rather boring game" 13 print "where you have to guess the number that the" 14 print "computer has just thaught of. You might as well" 15 print "have a go, so just press any key to seal your doom!" 16 waitkey 20 guesses=0 : cls 22 pen 10 : ? "What skill level (1=easy, 3=hard).?" 23 input skl:if skl<1 or skl>3 then goto 22 24 if skl=1 then r=rnd(20) 25 if skl=2 then r=rnd(50) 26 if skl=3 then r=rnd(200) 27 cls 30 pen 14 : locate 0,0 : print "I have just been forced to guess a" 31 print "number between 0 and "; 32 if skl=1 then print "20"; 33 if skl=2 then print "50"; 34 if skl=3 then print "200"; 35 print "...":? 36 pen 15 : ? "And you have to guess it..." 38 ?:?:pen 6:? "Guess number ";guesses;".":input "Guess=";yg 39 if yg<0 then 38 40 if skl=1 and yg>20 then 38 41 if skl=2 and yg>50 then 38 42 if skl=3 and yg>200 then 38 43 guesses=guesses+1 44 if yg=r then print "WAHEY!";:bell:? "You got it in ";guesses;" goes." 45 if yg>r then ? "Too high, guess lower":goto 38 46 if yghigh then high=nums(chk) 46 if nums(chk) : Prints all results and exits. There, pretty complex stuff? I hope you get used to it, because the above program is NOTHING. ####################################################################### At the end of this tiring session, we have learned: * How to use FOR...[STEP]...NEXT loops, * How to use arrays. I advise that you read and re-read session 10 until you have COMPLETE understanding of it. It is completely useless going on without it. ####################################################################### Session 11] I know it's unfair, but here is an excersise: Ex.17) How would you dimension an array called SUM with 50 positions, fill each position APART from the first three (4-50) with any random number from 0 to 9, and then print the 50 numbers out ACROSS the screen, one after another? Now you are familiar with STOS commands, I will tell you this now... In the NUMBER STATISTICS program in session 10, did you wonder why I used TTL instead of TOTAL? When you press RETURN, STOS goes through the line you just entered and converts it into it's own language. Do you remember the command TO (for a=1 TO 20 step 7)? -- Well, when STOS gets to the word TOTAL, it would mis-interprit it as: to TAL=5 ; which would then create a Syntax Error. The only way to avoid this is to call the variable something else, such as TTL, T0TAL (with a zero), TTAL, etc. Here is a VERY important aspect...MEMORY BANKS There are 15 of these. This is where music, pictures, icons, sprites etc. are stored. You need to RESERVE some space for a memory bank before you can actually use one. This is quite simple. If you want to reserve some space for a picture, you would do this: RESERVE AS SCREEN 5 This reserves memory bank 5 ready to hold picture or screen data. To load a picture into STOS, you would do this: LOAD "PICCIE.PI1" (Substitute PICCIE.PI1 for the filename of your picture - Note. STOS can only read PI1, PI2, PI3 and NEO pictures.) This loads the picture and displays it IMMEDIATELY. If you want to keep it in a bank, just do this: LOAD "PICCIE.PI1",5 And to display it, type in SCREEN COPY 5 TO PHYSIC. The PHYSICal screen is the screen you can ALWAYS see. To interpret the above command into English: "Copy screen from bank 5 to physical, so we can see it." If you had two screen banks, 5 and 6. RESERVE AS SCREEN 5 RESERVE AS SCREEN 6 and loaded a picture into bank 6, LOAD "NASTY.NEO",6 you could do this: SCREEN COPY 6 TO 5 This copies the NASTY picture from 6 to 5 so they BOTH hold the same picture. If you get bored with the picture just appearing on the screen, try this: {Reserve a bank for screen 5, load a picture in} APPEAR 5,1 Nice, isn't it. The screen nicely dottes on. To break down the command: APPEAR {Memory bank},{Type of appear} There are a total of 79 different appears, 1-72 are for low res and 73-79 are for high res, and do not appear the picture proporly. Have a little experiment with the APPEAR function. Do you wonder why the picture has the wrong colours? The APPEAR function only appears the picture and not the palette. To correct the colours, use this commands: GET PALETTE(5) This GETS the pallette of screen 5, so to apear the picture on correctly: GET PALETTE(5) : APPEAR 5,67 Here is a very flexible command: FADE. Try this: FADE 10 [Press UNDO twice to reset the editor] This fades the colours to black at the speed of 10 50ths per second. FADE 50 fades each colour one shade per second, FADE 1 is very fast. FADE 3 usually gives a nice speed. It is so flexible because there are so many different additions you can add to it, try this: FADE 10 TO 5 (when you have got a picture loaded into bank 5) This fades nicely to the colours in bank 5 at speed 10. Try this: FADE 40 TO 5 : APPEAR 5,8 Nice, isn't it? Now you know how to create nice title pictures and sequences for games. ######################################################################## Now you know how to: * Determine the mis-interprited commands, * Reserve memory areas, * Load pictures to screen and banks, and display them, * APPEAR the pictures to the screen, * Get the picture palette, * Fade to black, and the picture palette at a certain speed ######################################################################## Session 12] Here, I will go into the use of memory banks a bit. Ensure you have your STOS accessories disk in the drive, where you should have some example music files. Type in the following: NEW LOAD "MUSIC.MBK" LIST You should see something like: 3 music S:$066500 E:$067300 L:$000E00 The S (start), E (end) and L (length) numbers (which are in hexadecimal) will be different. The above are an example. When this line appears in your listing at the end (where all of the memory banks are listed) that means that you have some music in memory. As you can see from the music editor accessory, you can have up to 31 tunes. To play some music, try this: MUSIC 1 Either some music starts playing, or you get a 'Music Not Defined' error. This means that the music number you just attempted to play has not been used. If you loaded in the 'MUSIC.MBK' file, you should get a tune playing. Now type MUSIC 2, it sounds a bit the same, but slower. This is just tune number 2. Now try to type in MUSIC 28. You should get the above error message. Now type, TEMPO 20 and the music should slow down. Now try TEMPO 100, and the music should speed up, considerably! TEMPO 50 should revert to somewhere near normal. Now try, TRANSPOSE 5. The tune gets lower. TRANSPOSE -5, it is higher than normal! TRANSPOSE 0 is normal, TRANSPOSE 70 and TRANSPOSE -70 sound a bit silly. Type in VOICE OFF 1. Something is missing from the tune. It is the first of the three voices. It has been turned off with the VOICE OFF 1 command. Try the following in direct mode: VOICE ON 1 VOICE OFF 2 VOICE OFF 3 VOICE ON 2 VOICE ON 3 These commands can be used to easily turn on/off individual voices. Ex.18) What do you think the MUSIC OFF commands does? During this entire tutorial, I will be interested in demo-making (you MUST have seen at least one demo!), so let's put together our first demo! Ensure the ACCESSORIES disk with the music is in the drive. LOAD "music.mbk" (enter this before your program WITHOUT line number) (MUSIC bank need not be RESERVEd first.) 5 rem MAKE SURE YOU NOW HAVE YOUR ORIGIONAL STOS DISK IN THE DRIVE 10 MODE 0 : KEY OFF : CURS OFF : HIDE ON : CLS PHYSIC : CLS BACK 12 CLICK OFF : CLEAR KEY 14 RESERVE AS SCREEN 5 : load "A:\stos\pic.pi1",5 16 music 1 : fade 30 to 5 : appear 5,rnd(71)+1 18 wait 200 20 fade 3 : wait 25 22 fade 3 to 5 : wait 25 24 goto 20 The demo should be straightforward to you, except some commands in the first line (line 10). MODE 0 - Switches to low resolution (MODE 1 to medium, MODE 2 to high) KEY OFF - Switches off the menu bar at the top of the screen. CURS OFF - Switches off the cursor. HIDE ON - Switches off the mouse pointer. CLS PHYSIC, CLS BACK - Clears the physical and background screen. CLICK OFF - Switches off the keyboard clicking when a key is pressed. CLEAR KEY - Removes the last keypress from the keyboard buffer. Note - KEY ON, CURS ON, SHOW ON, and CLICK ON are all used respectively to turn back on all of the above functions. (Note SHOW ON for HIDE ON). ######################################################################## Now, you should know: * How to use, play and modify music, * Some basic EDITOR commands (HIDE, KEY, CURS, CLICK, CLEAR KEY etc), * An idea of a simple demo. ######################################################################## Session 13] For this, and a following session, I will concentrate on the use, animation, and movement of SPRITES. Again, this is a very important section, so make sure that you are very familiar with it. First of all, what on Earth is a sprite? It is a smallish piece of graphics which you can move around the screen independantly of the rest of your program (on interrupt, like music.) (Interrupt means that once you set it off [sprites, music etc.] you do not have to keep updating it to keep it working, like with music, all you have to do is type MUSIC 1 and you don't have to worry about music again.) STOS can hold a maximum of 15 sprites at once. Sprites are created with the SPRITE DESIGNER on the accessories disk and loaded into your games, programs and demos. Insert the accessories disk now, and type LOAD "ANIMALS1.MBK" LIST You should see something like: 1 sprites S:$055000 E:$066500 L:$011500 (Again, the numbers S,E, and L will be different.) This means there is a sprite bank in memory, ready to be used. To display a sprite, enter the following command: SPRITE 1,160,100,1 There, you should see a glowing octopus in the centre of the screen. There is a lot of things to say about this one thing, so I will take them one by one. First of all, the format of the command. SPRITE sprnum,xpos,ypos,image SPRNUM is the number of the sprite (1-15) you want to display. 15 sprites can be displayed at any one time. XPOS and YPOS are simply the X and Y co-ordinates of the hotspot of the sprite (the hotspot is a pixel on the sprite where collisions are detected - more about this later.) IMAGE is the number of the sprite in memory. For example 1 is an octopus, and if my memory serves me correctly, 5 is a dog or robot, and 12 is a monkey with a machine gun! Ex.19) Assuming sprite 12 is the monkey, how would you display the money sprite at the top-left of the screen? Press UNDO twice to clear the screen, and type the following. 10 KEY OFF 12 sprite 1,0,0,1 : sprite 2,200,0,1 14 sprite 3,0,150,1 : sprite 4,200,150,1 RUN this program. You should get four octopii (I think that's it!) on the screen. The top-left is sprite 1, top-right is sprite 2, bottom-left is 3 and bottom-right is 4. Now type sprite 3,0,150,5. What has happened? We have changed the IMAGE number of the third sprite. There are a couple of questions which may arise from the more wary readers. Why are the sprites glowing? Why are the sprites not the right colours? You may notice that the glow of the sprites is the same colour as the glow of the cursor. If I was to tell you that the cursor was colour 2, would you know what to do? No. Right, try CURS OFF. There. It has stopped glowing. Why? Because the bits that were glowing were colour 2, the same as the cursor. The reason that the sprites are not the correct colours is because we have not told the computer we want the right colours. Unfortunately, there isn't a simply command like GET SPRITE PALETTE, or GET PALTTE(1). The only ways to do it are either by viewing the sprite palette from the sprite editor and changing the palette manually with the PALETTE command (more about this later) or by typing in the following bit of cryptic code: (Beginnnig of program) 10 AD=hunt(start(1) to start(1)+length(1),"PALT")+4 11 for A=0 to 15 : colour A,deek(AD+A*2) : next A ...and suddenly, the sprites are in the right colours. Please don't get annoyed because you can't figure out what in goodness' name the above code means, it is very advanced, and I might come onto it later. ####################################################################### Now, you should: * Know what a sprite is and how to display one, * Know how to get the correct palette, and why the sprite glows. ####################################################################### Session 14] Before we go any further, I want you to create a 'setup' file fo use with all of my examples. Type in and save the following program on your back-up of the STOS master disk: NEW 1 gosub 50000 49999 end 50000 mode 0 : key off : hide on : cursoff : clearkey : click off : cur soff : cls logic : cls physic : cls back 50001 ad=hunt(start(1) to start(1)+length(1),"PALT")+4 : for a=0 to 15: c olour a,deek(ad+a*2):next a 50009 return SAVE "SETUP.BAS" Load in the program "CONFIG.BAS" from the STOS disk and RUN it. Now click on NEXT PAGE at the bottom-right of the screen. Select any function key number that you KNOW you will not use (I use F8), click on it, and type in MERGE "SETUP.BAS"` and press RETURN (note the ` which is the key just before BACKSPACE, this tells the computer to execute the command immediately, and acts as a sort of automatic RETURN.) Now select SAVE, follow the instructions, and quit from the configuration program. Type NEW. Now, every time you are given a new example, type NEW, and press that function key. The screen clearance and sprite palette changer code is automatically loaded in. If the program you are about to enter does not use sprites, simply type in 50001 in direct mode to delete the line which changes the palette. Because there is no sprite palette in memory, the screen will go a greenish colour which we do not want. (To delete a line, simply type in the line-number on its own) Right, back onto sprites. Let's do a bit of movement. Press your set-up function key button (I will call it [SET-UP] from now-on) and type in the following: LOAD "ANIMALS1.MBK" (ensuring you have the accessories disk in the drive) 10 SPRITE 1,0,0,1 15 move x 1,"(1,1,300)" : move on Wahey! The sprite will begin to move across the screen to the other side. Let's explore the command more deeply: MOVE (tells STOS that we want to move a sprite) X (we want to move it along the X axis, or ACROSS the screen) 1 (we want to move sprite number 1 across the screen) 1 (Speed. 1 is quickest, 50 is slow, 300 is very very slow!) 1 (Step size. This is how many pixels the sprite jumps per move. If this were set to 5, the sprite would move 5*300 pixels, and in steps of 5 pixels.) 300 (Tells STOS we want to move the sprite 300 x step size pixels.) If you still do not understand the bit about STEP SIZE, type in this line instead of the one above: 15 move x 1,"(60,20,10)":move on There, the sprite jerks across the screen, in steps of 20, and 10 times (20x10=200 pixels)) and at a speed of 60, which is just over one second per movement. Ex.20) How would you move the sprite DOWN the screen? Type this in instead of line 15: 15 MOVE Y 1,"(1,1,200)":move on RUN The sprite now moves DOWN the screen. Type this in instead of line 15: 15 MOVE X 1,"(1,1,300)":move Y 1,"(1,1,200)":move on The sprite now moves DIAGONALLY down the screen. This is simply a combination of X movement AND Y movement. Now try this: 15 MOVE X 1,"(1,1,300)(1,-1,300)":move on The sprite moves right, then back left again to the beginning. This is because we have done the following: (1,1,300) Tells STOS to move right with speed 1, step 1, 300 moves. (1,-1,300) Tells STOS to move left with speed 1, step -1 (left), 300. Positive numbers mean RIGHT or DOWN, and negative numbers mean LEFT or UP. Try this: 15 move y 1,"(1,1,200)(1,-2,100)" : move on It moves normally down, then quickly bounces back. This is due to the -2 on the second movement definition. But why did I type in 100 instead of 200 in the second command? (1 x 200 = 200) and (-2 x 100 = 200). Alter line 15 so the last brackets read (1,-2,200). The sprite totally disappears off the top of the screen. (1,-200,200 = -2 x 200 = 400) ^^^ Here is another example: 15 move y 1,"(2,1,10)(1,1,10)(1,2,10)(1,3,10)(1,4,10)(1,3,10)(1,2,10)( (1,1,10)(2,1,10)(2,-1,10)(1,-1,10)(1,-2,10)(1,-3,10)(1,-4,10)(1,-3,10) (1,-2,10)(1,-1,10)(2,-1,10)L" This gives a nice 'wavey' sort of movement. Also note the L at the end of the movement definition. This stands for LOOP and tells the sprite to continue following the predefined path forever until you turn it off. Another thing you can add to the end of a movement definition is this: E50 This means, when either the X or Y co-ordinate of the sprite (depending on wether you used MOVE X or MOVE Y) reaches 50 across or down, it will stop moving. For example: move x 14,"(1,1,300)E250" will move sprite 14 across the screen and stop when it reaches 250. If you want a sprite to keep going in one direction forever, change the last number (how many times) to a 0. For example: move y 15,"(1,1,0)" would move sprite 15 down the screen and not stop. Using large step sizes, you can produce interesting effects, try this: NEW (load in sprite bank) [SET-UP] 10 sprite 1,0,0,1 12 move x 1,"(20,70,4)(1,-280,1)l" 13 move y 1,"(81,70,3)(81,-70,3)l" 14 move on 15 ? "WIERD????" 16 goto 16 A couple more handy commands for use with MOVE are MOVE OFF and MOVE FREEZE. MOVE OFF stops the movement of the sprite, and MOVE FREEZE pauses the animation until you use MOVE ON again (note you do not need to re-define the paths.) If you place a number after the MOVE OFF, MOVE ON or MOVE FREEZE commands then only that sprite number will be affected. ie. MOVE OFF 2 will only stop sprite 2 moving, while the others (if there are any) will continue as normal. If no number is added after the command, ALL the sprites will be affected. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Now, providing you paid attention, you should now be able to: * Move the sprite(s) around the screen in various paths, * Know what the 'L' and 'E' endings mean. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Session 15] We have looked at sprite movement, now let's look at sprite animation. Like movement, animation firstly needs to be defined, and the set in motion (MOVE to define, and MOVE ON to execute). In a simple animation set-up string, there are two different datas. FRAME and DELAY. Try the following program: NEW [SET-UP] (load animals1.mbk sprite bank) 10 sprite 1,150,90,1 12 anim 1,"(1,3)(2,3)(3,3)(4,3)(5,3)(6,3)(7,3)" 14 print "Press any key to play animation once." : clearkey:waitkey 15 anim on 1 18 boom : end When you press the key, the pink gorilla should go through the motions of walking a few steps. Let's have a look at the ANIM command. ANIM 1, - Define animation for sprite 1. (1,3) - Replace with frame 1 and hold for 3/50ths of a second. (2,3) - Replace with frame 2 and hold for 3/50ths of a second. (3,3) - Replace with frame 3 and hold. (4,3) - And so on. The first seven images are of the monkey walking in different animation frames. What the ANIM command does is to place each image at the X and Y co-ordinate of the pre-defined sprite and hold the image for DELAY 50ths of a second. Just before the closing parenthesees on line 12, place an L and RUN the program again. Can you guess what happens? Ex.21) What on Earth DOES happen? To stop the animation, simply use ANIM OFF, or to temporarily pause or freeze the animation, use ANIM FREEZE. ANIM ON is used to resume the animation without re-declaring or re-defining it. Again, inserting a number after the command menas only that sprite is affected, and if no number is added, ALL sprites are affected. Here follows the code for your second demo, the WALKING PINK GORILLA! (Note- it uses some commands with which you will be unfamiliar, but I will define them later on.) NEW [SET-UP] 10 erase 1 : erase 5 12 load "animals1.mbk" : load "backgrnd.mbk",5 14 limit sprite 20,0 to 299,199 16 pen 13 : locate 0,4:under on 18 centre "A lost guerilla gorilla (pathetic) in the dungeons of hell" 19 pen 12:locate 0,19:? "Or some other hopeless title.":bell:clearkey 20 waitkey:locate 0,19:? "By the way, do you get the joke?" 21 ? "GUERILLA (Gorilla. - no?)":bell:clearkey:waitkey:gosub 50000 22 unpack 5,back : unpack 5,physic 24 sprite 1,100,0,1 : anim 1,"(1,3)(2,3)(3,3)(4,3)(5,3)(6,3)(7,3)l" 25 move x 1,"(1,2,160)(1,-320,1)l" 26 anim on:move on 27 wait 100 28 repeat : until xsprite(1)<50 29 locate 0,4:pen 14:centre "Haven't I been":locate 0,5 30 centre "here before?!" 31 clearkey:waitkey:bell:gosub 50000:end ######################################################################### Unless you are unable to read, you should now know how to: * Animate sprites on the screen, * Have knowledge of a small demo involving quite an innocent pink gorilla! ######################################################################### Session 16] Let's have a look at quite an interesting command - DEF SCROLL. This takes parameters in the following format: DEF SCROLL num,xtop,ytop to xend,yend,xdir,ydir eg. DEF SCROLL 1,0,0 to 319,199,-1,4 DEF SCROLL, which is used in conjunction with SCROLL, is used to define and use a scroll area respectively. DEF SCROLL 1 - You can have up to 8 different scroll zones, 1-8. 0 - This means the left of the rectangular scroll box is set to 0. 0 - This means the top of the rectangualr scroll box is set to 0. 319 - The right-hand edge of the box is set to 319. 199 - The bottom of the box is set to 199. -1 - When the scroll is activated with SCROLL, in one step, it will scroll left one pixel. 4 - At the same time it will move down by four pixels. To sum up the above example, the zone contains the whole screen (low res) and when activated, moves sort of diagonally, (left 1 and down 4) To move right 9 and up 5, you would use 9 and -5. {Negative numbers mean up or left, positive numbers mean right or down. This refers to ALL movements etc. and is very important!} DEF SCROLL only defines the scroll box, but to actually scroll the box, type in the following simple command: SCROLL x ; where 'x' is the number of the zone you have defined (1-8) Type in the following example: NEW [SET-UP] 10 def scroll 1,0,0 to 319,199,0,8 12 print "Let's go DOWN!!!!" 13 ? "Hit any key (gently!)" 14 waitkey:scroll 1 15 wait 50:scroll 1:wait 50 16 for t=1 to 40:scroll 1:next t 17 gosub 50000 : rem CLEARS etc. 18 locate 0,20:? "Now let's go UP. Press a key" 19 waitkey:defscroll 1,0,0 to 319,199,0,-8 20 rem THE PREVIOUS DEFINITION TO MOVE DOWN IS OVER-WRITTEN WITH UP. 21 for t=1 to 30:scroll 1:next t 22 gosub 50000 25 def scroll 2,0,0 to 319,199,4,-2 26 locate 0,10:centre "Let's go MEGA-SILLY!" 27 for t=1 to 30:scroll 2:next t 28 fade 3:wait 40:gosub 50000:end RUN This program scrolls the screen is various directions. Try messing about with the parameters, especially the first four, which are the screen parameters. The smaller the screen size you have to scroll, the faster it will move. Now let's mess about with using more than one scroller at a time. NEW [SET-UP] 10 def scroll 1,0,0 to 159,84,-2,-2 12 def scroll 2,0,85 to 159,199,-2,2 14 def scroll 3,160,0 to 319,84,2,-2 16 def scroll 4,160,85 to 319,199,2,2 18 locate 0,10 : centre "Press any key to obliterate" 20 clearkey : waitkey 22 locate 5,5 : ? "1" 23 locate 5,18 : ? "2" 24 locate 34,5 : ? "3" 25 locate 34,18 : ? "4" 26 wait 100 27 for t=1 to 100 28 for v=1 to 4 : scroll v : next v 29 next t 30 end Let's break down the program... 10-16 Defines the scroll zones (1, 2, 3, and 4) 18 Print message at centre of screen 20 Wait for keypress 22-25 Show number of each scroll zone 26 Wait for 2 secs 27 Scroll each zone 100 time (Start of loop) 28 29 End of loop (after 100 scrolls) 30 End program Let's look at line 28 with greater detail. I could have easily written: scroll 1 : scroll 2 : scroll 3 : scroll 4 but I find it a bit long-winded, so I used a loop to do it for me. Eg: for v=1 to 4 (go through loop 4 times and store current run-through in variable V.) scroll v (scrolls the scrolling zone number V) next v (finish loop) Feel free to experiment with the parameters in the above program and try to add some more zones. ######################################################################### At the end of this sesh, you should be able to: * Define scrolling zones, * Scroll areas of the screen around, * Generally bodge the screen up! ######################################################################### Session 17] We talked about strings earlier on...eg NAME$="MEGADAZ" which stores the word MEGADAZ under the string name NAME$. Now let's have a look at string manipulation, which is very important. To add two strings together ie. Merge "MEGA" with "DAZ" to make "MEGADAZ" simply 'add' them together: A$="MEGA" B$="DAZ" C$=A$+B$ print C$ A$="HELLO " B$="THERE " RR$=" AND WE" GGH$="LCOME T" WWW$="O A SILLY DEMO" Q$="NSTRATION" YYT$="!" print A$+B$+RR$+GGH$+WWW$+Q$+YYT$ Ex.22) What the above example do? NEW [SET-UP] 10 print "Type in three names." 12 input a$,b$,c$ 13 print "Hello ";a$;", ";b$;" and ";c$;"." 14 rem MAKE SURE YOU TYPE IN LINE 13 CORRECTLY! RUN The - (minus) sign can be used to 'subtract' one string from another: Eg: A$=" " B$="THIS STRING HAS NOT GOT ANY SPACES" print B$-A$ which will print: THISSTRINGHASNOTGOTANYSPACES ...because we have taken the string with text and subtracted the spaces (in B$) from it to leave the silly-looking text. Ex.23) What will happen here: A$="STOS" B$="S" print A$-B$ Ex.24) What will happen here: CF$="BASIC IS EASY" D1$="B" D2$="AS" print CF$-D1$-D2$ Here is a command which seems complicated: A$="MY NAME IS MEGADAZ ON THE COMPUTER" print MID$(A$,12,7) ...which will print MEGADAZ. Why? The format of the MID$ command is as follows: Name of string: A$ Start position in string: 12 Length of string after start position: 7 It takes the string A$, finds the 12th character (the M) and prints the next seven letters including the M, to reveal "MEGADAZ". If you were to change the 7 for a 4, it would print "MEGA" and if you were to change the 4 for a 23, it would print "MEGADAZ ON THE COMPUTER". If you were to use A$,15,7 as parameters, you would get "ADAZ ON" Ex.25) What would the following example print: NAME$="JUSTICE LONGTHORPE" Ex.26) What would the following example print: NAME$="SILAS BANDAVENUE" print mid$(NAME$,1,1) If you have ever seen any demos (especially mine) you will have noticed things called SCROLLING TEXTS, SCROLLERS, SCROLLING MESSAGES or whatever you call them. With only the knowledge we have learned so far, we can do a simple one... NEW [SET-UP] 10 rem MY FIRST SCROLL TEXT 12 M$=space$(40) 13 M$=M$+"Hello there, this is my first scroll text...(well actually it's" 14 M$=M$+"YOUR first scroller, and MY 60th scroller!)...I can't really" 15 M$=M$+"think of anything else, so I want YOU to enter whatever text" 16 M$=M$+"you like in lines 18-29, using M$=M$+ --- here we go!! - " 17 M$=M$+"PS. I will explain what SPACE$(40) means later on.... " 30 M$=M$+space$(80) 31 for t=1 to len(m$)-40 : locate 0,0 32 print mid$(M$,t,35) : wait 10 : next t 33 end RUN Let's break the program down: 12-30 Places all of the scrolltext in M$ 31 Starts off the loop. It will go through T the length of the scroller minus 40 (explained later) and re-locate at 0,0 32 Print 35 letters out from position T, pause and end loop. 33 End program I have used two new commands, SPACE$() and LEN() print SPACE$(15) simply prints out 15 spaces, instead of typing " " print SPACE$(800) prints out 800 spaces. A=LEN(M$) returns the length of string M$ in A, for example: M$="MEGADAZ" A=len(M$) A would contain 7, because the string M$ (MEGADAZ) is 7 letters long. M$="MEGADAZ " would return 8 in A (plus the space) M$="M" would give 1 M$="12R3*4&5œ6!789()/*-+.0EWœ" would return 25 (count 'em!) Now, using the knowledge we have gained so far, we can write our first scrolling text demo. Type in the following: NEW [SET-UP] 10 M$=" Hello there and welcome to my first scrolltext demo. I can't think of anything else to type, so I want you to continue for me. Add anything you like to the string M$ using M$=M$+ when you have reached the end of a line. Put the rest of your message between lines 11 and 39. " 11 M$=M$+"Now it's your turn...... " 40 M$=M$+space$(20)+"Time to WRAP now, so byeeeeee! " 42 POS=1 : def scroll 1,0,0 to 320,8,-1,0 43 locate 39,0 : ? mid$(m$,POS,1) 44 for t=1 to 8 : scroll 1 : next t 45 inc POS : if POS=len(M$) then POS=1 46 goto 43 RUN There, not bad eh? Let's analyze the program. 10 = Puts the text to be scrolled into M$ 11-39 = You put in YOUR message using M$=M$+" whatever " 40 = Adds 20 spaces and a message at the end. 42 = Sets scrolling zone, and sets POS to 1 (POS is a counter of which letter we are at in M$) 43 = Puts the next letter at 39,0 44 = Scrolls back 8 times 45 = Goes to next letter and checks that if the letter we are on now is equal to the length of the message, go back to 1 46 = Jump back to routine What the program does, is to put a letter on the top-right of the screen, and using DEF SCROLL, it can scroll the top 8 lines of the screen back by the width of a letter. To make the gaps longer between letters, change line 43 to: 43 for t=1 to 9 : scroll 1 : next t This scrolls back 9 times instead of 8. Try it with 10, 11 and 16, (and 99999 if you want to be silly.) To make the letters seem squashed up, change it to: 43 for t=1 to 7 : scroll 1 : next t This scrolls back only 7 times instead of 8. Try it with 6 and 5, (and with 2 if you, again, want to be silly.) We COULD have the makings of a demo here! Save the current program as "DEMO.BAS", and then load in sprite bank "sprdemo.mbk", and music bank, "music.mbk". Now, add these lines to the program: 41 gosub 1000 1000 rem HERE WE WILL ADD ALL OF THE NEW BITS 1001 sprite 1,1,0,3 : sprite 2,280,0,3 : sprite 3,1,170,3 1002 sprite 4,280,170,3 : wait vbl : for t=1 to 4 : put sprite t 1003 next t : sprite off 1004 sprite 1,30,30,1 1005 move x 1,"(1,1,250)(1,0,140)(1,-1,250)(1,0,140)l" 1006 move y 1,"(1,0,250)(1,1,140)(1,0,250)(1,-1,140)l" 1007 move on 1 1008 music 1 1099 return BEFORE YOU RUN THE PROGRAM, you will probably need to re-merge the set-up file because you will need line 50001 for the sprite palette. Now, re-run the demo. Now thatz better! (Please note that the Z was deliberate.) Ex.27) How would you double the speed of the scroller? ################################################################## So, at the end of this demo-packed session, you should be able to: * Manipulate strings in various ways, * Know how to produce a scroll-text, * Improve a simple program by adding sprites, music etc. ################################################################## Session 18] I think that we now have enough basic knowledge to make a game (and NOT a number-guesser game either!) We will have a crack at making a Pac-Man game! This, in my opinion, is the simplest of all of the types of games to make. In games, variables are used on a much greater basis than we have seen here so far. The first thing to do is make a brief intro to what we intend to do: "Allow the user to control the letter O (representing a Pac-man) around the screen with the joystick and collect some dots." We will make improvements and amendments later on. Now we have to define the program structure: - INITIALISATION (set up variables, arrays, etc.) - TITLE SCREEN (displayed before game) - MAIN LOOP (where everything happens) - ROUTINES (soon you will see the importance of GOSUB!) Now follows the initialisation bit. 1 gosub 50000 (remember to load your SETUP program) 2 SC=0 3 dim POS(30,20) 4 X=2 : Y=2 5 LEVEL=1 This is where the game is set up. In REAL games, graphic location, decompression, music sorting, array loading, external data loading, etc. will take place here. Line 1 - Clears screen (remember to have your little set-up program loaded in first!) Line 2 - Sets score to 0 (we will call it SC) (SCORE = SC or E) Line 3 - Sets array called POS which holds information about where the pills are. Line 4 - Start Pac-man at position 2,2 Line 5 - Start on level 1 Next is the title sequence. I will leave this bit up to you, but here are some ideas to help: o Maybe just plain text ("PRESS ANY KEY TO START"). o Draw a picture of a Pac-man and display it. o Sprite of a Pac-man flying around screen. You can use lines 10 to 90 for your title sequence. 10 rem TITLE SEQUENCE 11 gosub 50000 90 rem END OF TITLE SEQUENCE Now comes the pre-level initialisation. This is where the level itself is set up. 100 rem PRE-LEVEL INITIALISATION 101 gosub 50000 : for xw=0 to 30 : for yw=0 to 20 : pos(xw,yw)=0 : next yw : next xw 102 for T=1 to LEVEL*3 103 XP=rnd(28)+1 : YP=rnd(18)+1 : if XP=2 and YP=2 then goto 103 104 if POS(XP,YP)<>0 then goto 103 105 POS(XP,YP)=1 : locate XP,YP : print "." : next T 106 NEED=LEVEL*3 107 : 108 X=2 : Y=2 109 locate 0,22 : ? "SCORE:" 110 locate 12,22 : ? "LEVEL:" 111 locate 22,22 : ? "NEED:" Line 100 : Simply indicate what this part is. Line 101 : This clears the screen, and also erases all elements of the POS array, ready for the next level. Line 102 : There will be 3 coins to collect on level 1, 6 on level 2 and so on (Copins=Level x 3) This small routine between lines 102 and 106 sets up the coins. Line 103 : Chooses any place on the game grid. Any X between 1 and 29, and any Y between 1 and 19. It also checks to see that no coin is placed directly under the Pacman (ie. at location 2,2) Line 104 : In any chosen place in the POS array, 0=empty and 1=coin. If a coin has already been placed, choose again. Line 105 : Therefore empty space. Put a . there (coin). Also, finish the FOR...NEXT loop. (ie. put rest of coins) Line 106 : We will call NEED the variable for storing how many coins the Pac-man still has to collect. Line 108 : Places Pac-man at position 2,2. Line 109 : Print out headings for information bar at bottom. Here is the main loop. (Ideally, this is just a collection of GOSUBs which refer to different aspects of the game ie. control, etc.) 150 rem ** MAIN LOOP ** 151 : 152 gosub 230 : rem READ JOYSTICK 153 gosub 210 : rem ANYTHING UNDERNEATH PAC-MAN? 154 gosub 200 : rem PLACE 'O' 155 if need=0 then 240 156 gosub 250 : rem UPDATE INFO-BAR 199 wait 3 : goto 152 And that's it! The main loop. Simply branching out to the sub-routines greatly simplifies the process of making a game, and you can add new features by putting in one GOSUB, and the routine later on. But that's not the game yet! We haven't actually written the routines that place the 'O' and read the joystick, etc. Here they come, though! 200 rem PLACE 'O' 201 locate X,Y : ? "O" 209 return 210 rem READ ARRAY 211 P=POS(X,Y) 212 if P=0 then return 213 if P=1 then SC=SC+2 : dec NEED : bell : POS(X,Y)=0 229 return 230 rem READ JOYSTICK 231 j=joy : if j=0 then return 232 locate X,Y : ? " " : rem One space in quotation marks. 233 if j=1 and y>0 then dec y 234 if j=2 and y<20 then inc y 235 if j=4 and x>0 then dec x 236 if j=8 and x<30 then inc x 239 return 240 rem COMPLETED LEVEL! 241 gosub 50000 : locate 0,9 242 centre "LEVEL COMPLETE!" 243 SC=SC+30 : wait 100 244 inc LEVEL 249 goto 100 250 rem INFO-BAR 251 locate 7,22 : ? SC 252 locate 17,22 : ? LEVEL 253 locate 27,22 : ? NEED;" " 259 return Here is a description of what each routine does. Routine 200 - Locates the cursor at X,Y (Pac-man's position) and prints a 'O' Routine 210 - This routine checks to see if the Pac-man has stood on a coin. To do this, it looks at the array POS (which holds information about the level) at the specific location of Pac-man (X,Y). If a 0 is found, then that space is empty, but if a 1 is found, then you have stood on a coin. If a coin is detected, then the SCore is increased by 2, a BELL sound is made, then NEED counter is decreased, and finally the collected coin is wiped from the array. Routine 230 - JOY returns the position of the joystick (1=up, 2=down, 4=left, 8=right, 0=centred). If it is 0, then the routine is left (no movement). If it is 1, AND the Pac-man is lower than the top line, then he moves up one square. If it is 2, AND the Pac-man is higher than the bottom line, then he moves down. If we do not make these checks, then you can move out of play, and cause an error. Also, if movement is detected, then the old 'O' is erased before the new one is drawn. Try erasing line 232 and see what happens! Routine 240 - This routine is called when all of the coins have been collected. It increases your score by 30, and goes to the next level. Routine 250 - This fills in the information in the info-bar. You may notice the ;" " after the NEED display. This is because when the number counts down from 10 to 9, then 0 will be left over, so it will look like: 12 11 10 90 80 70... The ;" " places a space after the last letter to be printed, therefore erasing any spare 0's. So there we have it! A very basic Pac-man game! Although, you must admit that after a while, it does get boring. This may be because you cannot get killed! Let's start adding things to this program. First of all, though, save the current program under 'PAC1.BAS' or something. ######################################################### At the end of this session, we have: * Learned how important GOSUB and RETURN are. * Created a very simple Pac-man game. ######################################################### Session 19] The first thing we can add to this program is a time limit. This forces Pac-man to hurry around the level, because if he runs out of time, then the game is over. So, first of all, we add a routine to deal with the time limit. 260 rem ** TIME LIMIT ** 261 dec TIME : if TIME=0 then 270 : rem GAME OVER 269 return We now have to make the main loop branch to this routine: 157 gosub 260 Now, we re-make the info-bar so we can fit the time limit on: 250 rem INFO-BAR 251 locate 3,22 : ? SC 252 locate 10,22 : ? LEVEL 253 locate 16,22 : ? NEED;" " 254 locate 23,22 : ? TIME;" " 259 return 109 locate 0,22 : ? "SC:" 110 locate 7,22 : ? "LV:" 111 locate 13,22 : ? "ND:" : locate 20,22 : ? "TM:" I have abbreviated the SCORE to SC, the LEVEL to LV, NEEDED to ND, and TIME to TM. Next, I have to put in a command which sets how much time you get to complete each level. This goes during the pre-level initialisation: 112 TIME=LEVEL*200 This means you get 200 units of time (NOT seconds) per three coins to complete each level. But what happens if you run out of time? If the program detects TIME to be 0, then it goes to line 270. This is where you can put in an OUT OF TIME message of your own, and make it return to the title page. (Make sure it does not go over line 280). Now save your latest version as 'PAC2.BAS' OK, so we have got a time limit, but what about a pursueing monster? This will really spice the game up a bit! Here follow the routines: 280 rem MOVE MONSTER 281 if MDELAY>0 then dec MDELAY : return 282 MDELAY=MSPEED : locate MX,MY : ? chr$(MUND) 283 if MX>X then dec MX 284 if MY>Y then dec MY 285 if MX0 then 119 120 locate XW,YW : ? "#" : POS(XW,YW)=2 : next T 121 for xw=0 to 30 : locate xw,0 : ? "#" : pos(xw,0)=2 : locate xw,20 : ? "#" : pos(xw,20)=2 : next xw : for yw=0 to 20 : locate 0,yw : ? "#" : pos(0,yw)=2 : locate 30,yw : ? "#" : pos(30,yw)=2 : next yw 124 return 125 rem Prevent 'LINE NOT FOUND' error (see line 114 below) 114 MX=26 : MY=10 : MUND=0 : goto 125 102 gosub 115 : for T=1 to LEVEL*3 233 if j=1 and y>0 and POS(X,Y-1)<>2 then dec y 234 if j=2 and y<20 and POS(X,Y+1)<>2 then inc y 235 if j=4 and x>0 and POS(X-1,Y)<>2 then dec x 236 if j=8 and x<30 and POS(X+1,Y)<>2 then inc x 283 if MX>X and POS(MX-1,MY)<>2 then inc MX 284 if MY>Y and POS(MX,MY-1)<>2 then inc MY 285 if MX2 then dec MX 286 if MY2 then dec MY There! Now there is some wall on each level to hinder both you and the monster. Increasing amount of wall are randomly scattered around each level. Unfortunately, if a coin is completely surrounded by wall, then tough luck! You will have to commit suicide! You may be lucky though, and the monster may be trapped in his corner - who knows? Let's go through each new line in turn... 115-117 Draws on a line of wall at the beginning. It gets longer as the level increases. 118-120 Same method used for scattering coins. Scatters walls instead. 121 This long line draws a large square of walls around the outside of the play area. The lines 124, 125, 114 and 102 outline the problem of numbering your programs in one's. If you draw out the wall after the coins, then some coins may get erased - making the level impossible. Therefore, it is best to draw the walls first, and then the coins. Unfortunately, I had not left any space to do this during the pre-level initialisation, and so I had to skip to the wall-drawing routine first (line 102 - GOSUB 105), do the wall-drawing between lines 115 and 123, skip back to the normal coin-drawing (line 124 - RETURN), and skip the wall-drawing bit when it is reached again (line 114 - GOTO 125). I had to put a REM at line 125, or else an error would have occured because there was no line 125 to go to! The code for a wall is 2 (coin=1, space=0). Lines 233 to 236 had to be re-written. They now contain a check. For example, on line 233 where the player has pushed the joystick up: IF joystick has been pushed up AND Pacman is not out of bounds AND there is no wall above him, THEN move up one square. To check for wall, we look in the POS array one square ABOVE the Pacman's current position. A similar rule applies for the other three directions. Lines 283 to 286 deal with the monster's movement in exactly the same way. Now add this: 248 if LEVEL=11 then 320 320 rem GAME COMPLETED! 321 gosub 50000 : locate 0,0 : inverse on 322 centre "WAHEY!" : inverse off : locate 0,7 323 centre "You have completed all 10 levels!" : SC=SC+100 324 if SC<=HI then 339 325 HI=SC : locate 0,12 : centre "YOU HAVE A HIGH SCORE!" 326 locate 0,14 : centre "INPUT YOUR NAME!" : locate 0,16 327 input NAME$ 339 goto 10 Now, somewhere in your title sequence, add this: locate 0,22 : ? "HISCORE";HI;" BY ";NAME$;"!" And this at the beginning: 6 HI=0 : NAME$="WILF" What I have done is limited the game to 10 levels, simply because if LEVEL got any higher than 10, then the walls would be too big, and the monster would have a negative speed! When drawing out the level, if the LEVEL is 11, then the program jumps to my little 'completed game' sequence at line 320. And just for an extra bonus, there is a hiscore as well, so you can get your name on the title screen if you beat the previous one! Try and make it ask you for your name if you beat the hiscore when you have lost your life. Just to make it more interesting, let's add this... 243 SC=SC+30+(TIME/3) : wait 100 The quicker you complete a level...the more score you get! Well, there is enough here to keep you going for a bit. Try adding loads of things to this program to make it a real blockbuster! To help you, here are some ideas: * Try and put in more than one monster at the same time. (you will probably need to use arrays) * Put in a special pill that freezes the monsters when you collect it. (have a delay variable where monsters only move when it is 0) * Make the play area bigger (38 x 21 for example) * Include some music, and make the levels more colourful. * Put in more objects, like pits to fall down, or hi-scoring coins, or timer resets, etc. There is a whole host of ideas that can go into a Pacman game. To see a *REAL* Pacman game in action, try buying my MONEYMANIA or MONEYMANIA 2 from GOODMAN INTERNATIONAL PD LIBRARY. ############################################################## Finally, we now know how to: * Greatly enhance a basic Pacman game ############################################################## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ANSWERS TO EXERCISES -------------------- No cheating! Ex. 1) 10 PRINT "HELLO LADS" : WAITKEY : CLS : PRINT "THE END" Ex. 2) The program prints the number 7. Ex. 3) Numbers will count down the screen from 1 onward. Ex. 4) Change line 30 to A=A+2 Ex. 5) Change line 10 to A=2000 and line 30 to A=A-1 Ex. 6) 30 Ex. 7) 19 Ex. 8) 10 A=100 : B=500 20 PRINT A;" ";B 30 A=A+1 : B=B-5 40 GOTO 20 Ex. 9) Insert the following: '25 PRINT' Ex.10) Print the text, wait for keypress, bell, clear screen, print text. Ex.11) INPUT "What is your name? ";NAME$ Ex.12) Absolutely nothing Ex.13) Yes Ex.14) No! This is a trick question. The REM at line 10 means the program ignores the commands, so therefore, T or N will remain 0. Ex.15) It will print "YES!" Ex.16) Dimension an array called NAME$ with 11 positions (including 0), make the fifth position "MEGADAZ" and the fourth one "KING". Ex.17) 10 dim SUM(50) 20 for t=4 to 50:sum(t)=rnd(9):next t 30 for t=0 to 50:? sum(t);:next t Ex.18) Stops the music. Ex.19) SPRITE 1,0,0,12 Ex.20) move Y 1,"(1,1,100)" - The numbers in the brackets don't matter. Ex.21) LOOPS the animation, like with MOVE. Ex.22) It will print "HELLO THERE AND WELCOME TO A SILLY DEMONSTRATION!" Ex.23) It will print "TO" because the S's have been erased. Ex.24) It will print "IC IS EY" because the B and the AS out of bASic and eASy have been erased. Ex.25) NOTHING! The PRINT has not been included! (Trick question, sorry!) Ex.26) S Ex.27) Change line 42 to POS=1 : DEF SCROLL 1,0,0 TO 320,8,-2,0 and line 44 to FOR T=1 TO 4 : SCROLL 1 : NEXT T You need to change line 44, or else the scroller would scroll 8 letters to many. (8x1=8, 4x2=8.) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~