home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / STOSSER / STOSSE06.MSA / ISSUE_6 / 25.PNE < prev    next >
Text File  |  1987-04-22  |  29KB  |  934 lines

  1.                        STOS BASIC 6
  2.  
  3. I assume little/no prior knowledge of Stos.  Each lesson will also 
  4. have a Stos BASic or ASCii file to go with it.
  5.  
  6. Listed here for your convenience.  i.e. to make it easier to write 
  7. them down or to look at the structure of the command. Are the new
  8. commands to be dealt with.
  9.  
  10. Do not worry if you find things hard at first, practice makes 
  11. perfect.  Actual progs are used to explain things, called
  12. 'name.asc' and included in this folder.
  13.  
  14. The Main Commands:
  15.  
  16. SET ZONE:   RESET ZONE:     BOX:     
  17. IF THEN: FOR...NEXT:    REPEAT...UNTIL:
  18. RESERVE SCREEN:   SCREEN COPY:   GET PALETTE:
  19.  
  20. If you have any problems, then look for the command on pages 
  21. 271/73 of the manual.  This is not intended to replace the manual,
  22. but to add to it where needed.
  23.  
  24.  
  25. This programme does not work properly because line 80 needs to be 
  26. changed.  I am sort of hoping that by now you will have an idea as
  27. to what is wrong with it.  To give you a clue F is too high or 
  28. else the programme needs changed.
  29.  
  30. The next lesson will show you how to put it right in case you get 
  31. lost, so do not panic.
  32.  
  33.  
  34. LESSON 1
  35.  
  36.  
  37. 10 rem draw boxes
  38. 20 rem
  39. 30 if mode<>0 then mode 0
  40. 40 cls : key off
  41. 50 X=0 : Y=Y
  42. 60 X1=X : X2=X1+60
  43. 70 Y1=Y : Y2=Y1+60
  44. 80 for F=1 to 8
  45. 90 box X1,Y1 to X2,Y2
  46. 100 X1=X2+10 : X2=X1+60
  47. 110 next F
  48.  
  49. lines:
  50. 10 rem draw boxes         
  51. 20 rem
  52.  
  53. Tells you what to expect from the programme.  In this case it is 
  54. just drawing boxes onto the screen.  In the later lessons I shall
  55. show you how to create zones and use them to activate parts of 
  56. your programmes - which is just the same as drawing boxes really.
  57.  
  58. lines:
  59. 30 if mode<>0 then mode 0          
  60. 40 cls : key off
  61.  
  62. Set up the screen.  As you merge these small programmes together,
  63. you will delete the screen setup from each small programme and 
  64. write a larger one to cover them all.
  65.  
  66. lines:
  67. 50 X=0 : Y=0          
  68. 60 X1=X : X2=X1+60 
  69. 70 Y1=Y : Y2=Y1+60
  70.  
  71. Set up the values for the size of the boxes to be drawn.  In this 
  72. case the boxes will be 60 by 60 in size and start at point (0,0).
  73. i.e. top left hand of the screen.
  74.  
  75. I set up (X) and (X) as the starting points, and then tie the size 
  76. of the box to this.  If I change the value of x or y the boxes 
  77. will change in size, but they might not fit onto the screen.
  78.  
  79.  
  80. That, by the way is why this programme does not work.
  81.  
  82. line:
  83. 80 for F=1 to 8
  84.  
  85. Sets up the number of the boxes to be created, in this case 8.
  86.  
  87. line:
  88. 90 box X1,Y1 to X2,Y2
  89.  
  90. Draws the box at point (x1,y1) and (x2,y2).  By using a set of 
  91. variables here I can get away with only one line of code, which
  92. will be executed 8 times instead of 8 lines of code being executed 
  93. once.  This is quicker to write, and quicker to alter.
  94.  
  95. In this example there is not that much of a difference, as I also 
  96. have to include the other lines of the (For..Next) loop, so in the
  97. end I only save a little bit of time.
  98.  
  99. However if I want to move the boxes or resize them, then I only 
  100. have to change lines 50 to 70 and the programme will draw them to
  101. the new place for me.
  102.  
  103. line:
  104. 100 X1=X2+10 : X2=X1+60
  105.  
  106. Sets up the position of the next box to be drawn to screen.
  107.  
  108. line:
  109. 110 next F
  110.  
  111. Completes the loop and jumps back to line 80 until all 8 boxes 
  112. have been drawn.  Or it would do but for the fault.  Have you
  113. worked it out yet?
  114.  
  115. Well, Stos will not draw graphics off of the screen.  That is to 
  116. say at screen locations larger than the screen size.
  117.  
  118. If you remember, I did mention this in an earlier tutorial. So 
  119. whilst Stos will happily draw sprites off of the screen and
  120. then move them onto the screen.  Just remember that it will not do 
  121. the same for graphics!!
  122.  
  123.  
  124. Anyway The answer was to either make the boxes smaller so that all 
  125. 8 would fit onto the screen, or to change the number of boxes to
  126. be drawn to screen, or to make stos draw the other 4 boxes under 
  127. the first four.
  128.  
  129. Now as I wanted eight boxes of that size, I obviously intended to 
  130. add some more code to make it work.
  131.  
  132.  
  133. LESSON 2
  134.  
  135.  
  136. 10 rem draw boxes
  137. 20 rem
  138. 30 if mode<>0 then mode 0
  139. 40 cls : key off
  140. 50 X=0 : Y=0
  141. 60 X1=X : X2=X1+60
  142. 70 Y1=Y : Y2=Y1+60
  143. 80 for F=1 to 8
  144. 90 box X1,Y1 to X2,Y2
  145. 100 X1=X2+10 : X2=X1+60
  146. 110 if X1>=260 then X1=X :X2=X1+60 : Y1=Y2+10 :Y2=Y1+60
  147. 120 next F
  148.  
  149. I have added a line at 110.  Other than that it is the same 
  150. programme that I have already discussed with you.
  151.  
  152. lines:
  153. 10 rem draw boxes          
  154. 20 rem
  155.  
  156. Tell you what the programme does.
  157.  
  158. lines:
  159. 30 if mode<>0 then mode 0          
  160. 40 cls : key off 
  161.  
  162. Set up the screen.  In this case it checks the screen resolution
  163. then turns off the key menu and clears the screen.
  164.  
  165. lines:
  166. 50 X=0 : Y=0         
  167. 60 X1=X : X2=X1+60 
  168. 70 Y1=Y : Y2=Y1+60
  169.  
  170. Set up the values for the sizes of the boxes.
  171.  
  172. lines:
  173. 80 for F=1 to 8     
  174. 90 box X1,Y1 to X2,Y2       
  175. 100 X1=X2+10 : X2=X1+60
  176.  
  177. Set up the number of boxes and where each one is drawn in relation 
  178. to the previous one.
  179.  
  180. line:
  181. 110 if X1>=260 then X1=X : X2=X1+60 : Y1=Y2+10 : Y2=Y1+60
  182.  
  183. The new line.  This checks to see what the value of (x1) is.  If, 
  184. and only if, it is 260 or above, the programme reads the rest of
  185. the line.  Otherwise it is ignored.
  186.  
  187. Why 260?  Well if you remember the boxes are 60 by 60 in size and 
  188. the screen is 320 across by 199 down in size.  So we need to take
  189. the size of the box away from the screen size, in order to know 
  190. where we can draw the boxes.
  191.  
  192. When and if (x1) reaches 260 or above the rest of the line gets 
  193. read.  The first part (X1=X) resets (X1) to zero because we did
  194. not change the value of (X).  The second part (X2=x1+60) just 
  195. resets the value of (X2) to 60 larger than the value of (X1).
  196.  
  197. Before this command (X2) still held the value of (X1), before (X1) 
  198. had its value changed to zero, so (X2) would have held a value
  199. above 300 in this case.
  200.  
  201. Remember this line was read only because (X1) had a value too high 
  202. to draw a box on the screen.  It therefore follows that as (X2)
  203. was 60 greater than the value of (x1), that (X2) must also be 
  204. changed.  In this case (X1) was 280 and (X2) was 340.  What you
  205. have done is to reset the value of (X2).
  206.  
  207. line:
  208. 110 if X1>=260 then X1=X : X2=X1+60 : Y1=Y2+10 : Y2=Y1+60
  209.  
  210.  
  211. This determines the maximum value that (X1) can have, and still 
  212. draw a box on screen.  As the  size of the box is set at (60) and
  213. the screen is (320) across, and 320-60 = 260 then this is the 
  214. largest value that we can allow (x1) to take.
  215.  
  216. If you change the size of the box, then you will need to change 
  217. the value of line 110 to match.
  218.  
  219. line:
  220. 120 next F
  221.  
  222.  
  223. This loops the programme back to the (FOR F = ...) bit of the 
  224. programme.  In this case back to line 80 and increments the value
  225. of (F) each time until (F) reaches the set value for it, which in 
  226. this case is 8.
  227.  
  228.  
  229. LESSON 3
  230.  
  231.  
  232. Well, here we are.  This is all of the previous lessons rolled 
  233. into one, and tacked in there is also the previous tutorial as
  234. well.  The object is quite simple.  To display a picture to 
  235. screen, and to draw boxes in the screen.
  236.  
  237. Next I will show you how to create zones to detect the mouse, to 
  238. manipulate your programmes.
  239.  
  240. 10 rem set up boxes/zones
  241. 20 rem
  242. 30 if mode<>0 then mode 0
  243. 40 cls back : cls physic
  244. 50 DRV=drive : drive=0
  245. 60 dir$="\stos\"
  246. 70 reserve as screen 6
  247. 80 load "pic.pi1",6
  248. 90 dir$="A:\"
  249. 100 get palette (6)
  250. 110 screen copy 6 to back :screen copy 6 to physic
  251. 120 drive=DRV
  252. 130 rem
  253. 140 rem draw boxes
  254. 150 rem
  255. 160 rem
  256. 170 X=0 : Y=Y
  257. 180 X1=X : X2=X1+60
  258. 190 Y1=Y : Y2=Y1+60
  259. 200 for F=1 to 8
  260. 210 box X1,Y1 to X2,Y2
  261. 220 X1=X2+10 : X2=X1+60
  262. 230 if X1>=260 then X1=X : X2=X1+60 : Y1=Y2+10 : Y2=Y1+60
  263. 240 next F
  264. 250 locate 0,16 260 print "press a key"
  265. 270 wait key
  266.  
  267. Once you can understand what I have done so far, then you are 
  268. almost ready to start your own programmes in earnest.  I know that
  269. some of you will have wrote simple guess the word type games.  
  270. Well this is how to use the mouse to select options for your
  271. games, or it will be by the next tutorial.
  272.  
  273. The only thing that you need to add to this, is how to save the 
  274. screen to a bank and then save the everything to disk.  I will
  275. cover that in a the next tutorial if you are not sure about it.
  276.  
  277. The reason for this is to create active zones within the screen to 
  278. control your games.  i.e. start; high score table; set up control
  279. method etc...
  280.  
  281. But as I say, that is for later, when I will also be touching upon 
  282. the Sprite Editor.
  283.  
  284.  
  285. lines:
  286. 10 rem Set up boxes/zones         
  287. 20 rem
  288.  
  289. Tell you what the programme does.  Although in this case the zones 
  290. have not been activated, so are really just boxes.
  291.  
  292. lines:
  293. 30 if mode<>0 then mode 0          
  294. 40 cls back : cls physic
  295.  
  296. Set up the screen. You can actually just use one (CLS) command, 
  297. here instead of clearing the Physical and Back Ground screens.
  298.  
  299. lines:
  300. 50 DRV=drive : drive=0           
  301. 60 dir$="\stos\"
  302.  
  303. Stores the current drive value in the variable (DRV) and then sets 
  304. up where the picture is to be found on disk.  It must be on drive
  305. (A:) and within the (STOS) folder.
  306.  
  307. lines:
  308. 70 reserve as screen 6          
  309. 80 load "pic.pi1",6  
  310. 90 dir$="A:\"
  311.  
  312. Reserves a temporary screen at bank 6, and then loads the picture 
  313. into the bank.  Then it returns you to the root directory of the
  314. disk.  i.e. not in any folders.
  315.  
  316.  
  317. lines:
  318. 100 get palette (6)          
  319. 110 screen copy 6 to back :screen copy 6 to physic  
  320. 120 drive=DRV
  321.  
  322. Reads the colours of the picture in bank 6 (in this case) and then 
  323. uses them to replace the default colours in Stos.  i.e .the start
  324. up colours.
  325.  
  326. lines:
  327. 130 rem        
  328. 140 rem draw boxes 
  329. 150 rem
  330. 160 rem
  331.  
  332. Shows you that this is a small sub-routine within the main 
  333. programme, and tells you what it should do.
  334.  
  335. lines:
  336. 170 X=0 : Y=Y         
  337. 180 X1=X : X2=X1+60 
  338. 190 Y1=Y : Y2=Y1+60
  339.  
  340. Contain the data needed to draw the boxes.  i.e size and placement 
  341. on the screen.  Done like this it is much easier to move the boxes
  342. around.  For instance if you wanted 12 boxes instead of the 8 that 
  343. this draws, then you would just need to change the values of (X1;
  344. X2; Y1; Y2) to the new size.  And then change the  following 
  345. command from 8 to 12.
  346.  
  347. Ideally, (X1=X) is not a good idea, as (X) is being used as the 
  348. start location and the size of the boxes as well.  So if you are
  349. not careful, you could lose control of what the programme is 
  350. doing, so I will change this bit in lesson 4.
  351.  
  352. However, I am trying to keep things simple here.  But as a rule of 
  353. thumb, you should avoid using the same variable for more than one
  354. function.  Create a new variable for each function, until you 
  355. become a better programmer in Stos.
  356.  
  357. lines:
  358. 200 for F=1 to 8          
  359. 210 box X1,Y1 to X2,Y2  
  360. 220 X1=X2+10 : X2=X1+60         
  361. 230 if X1>=260 then X1=X :X2=X1+60 : Y1=Y2+10 :Y2=Y1+60 
  362. 240 next F
  363.  
  364. Contain the commands for how many boxes, where to start drawing 
  365. them, and how many per row.  In this case it is determined by how
  366. many can fit onto a row.  So if you change the size of the boxes, 
  367. then that might alter how many fit on each row.
  368.  
  369. lines:
  370. 250 locate 0,16          
  371. 260 print "press a key" 
  372. 270 wait key
  373.  
  374. Prints a message to screen, telling you that the computer is 
  375. waiting for a keypress, then waits for that key to be pressed.  In
  376. this case any key would do, but you can define a specific key if 
  377. you wanted to add a few more lines of code.
  378.  
  379.  
  380. Now I will show you how I would code this bit of the programme.  I 
  381. have altered it very slightly from the previous one.  But it is
  382. basically the same.
  383.  
  384.  
  385. LESSON 4:
  386.  
  387.  
  388. 10 rem     Draw a box onto the screen
  389. 20 rem     then use same co-ords to
  390. 30 rem     create a zone under the box.
  391. 40 rem
  392. 50 rem    set up the screen
  393. 60 rem
  394. 70 if mode=1 then mode 0
  395. 80 cls : key off : hide on : curs off
  396. 90 drive=0 : dir$="\stos\" 100 reserve as screen 5
  397. 110 load "pic.pi1",5
  398. 120 get palette (5) 130 screen copy 5 to physic : screen copy 5 to 
  399. back
  400. 140 dir$="A:" 150 rem
  401. 160 rem    set up the position &
  402. 170 rem    size of the box & zone.
  403. 180 rem
  404. 190 X=0 : Y=0 : SIZE=60
  405. 200 X1=X : X2=X1+SIZE 210 Y1=Y : Y2=Y1+SIZE
  406. 220 rem
  407. 230 rem    Draw box and zone
  408. 240 rem 250 reset zone
  409. 260 for F=1 to 4
  410. 270 box X1,Y1 to X2,Y2
  411. 280 set zone F,X1,Y1 to X2,Y2
  412. 290 X1=X2+10 : X2=X1+SIZE
  413. 300 next F
  414. 310 rem
  415. 320 locate 0,15 : pen 2 : print "PRESS A MOUSE KEY TO PLAY"
  416. 330 locate 0,22 : pen 2 : print "CONTROL C TO QUIT"
  417. 340 rem    set up zone detection
  418. 350 rem
  419. 360 MX1=X : MX2=X2 370 MY1=Y : MY2=Y2
  420. 380 if MX2>=320 then MX2=319
  421. 390 limit mouse MX1,MY1 to MX2,MY2
  422. 400 show on
  423. 410 MK=0
  424. 420 repeat
  425. 430 MK=mouse key
  426. 440 until MK<>0 450 BUTTUN=zone(0)
  427. 460 locate 0,12 : print "YOU ARE IN ZONE";BUTTUN
  428. 470 wait 100
  429. 480 locate 0,12 : print "                   "
  430. 490 goto 410
  431. 500 rem    reset the screen for editing
  432. 510 rem
  433. 520 curs on : show on : limit mouse : pen 1
  434.  
  435. And now what it does and why.
  436.  
  437. The first thing that you will notice, is that I have used quite a 
  438. lot of (REMs) to explain what I have done.  I find, that if I do
  439. not use lots of them, then when I come back to the programme after 
  440. a couple of weeks, that I can not understand what it was created
  441. to do, and how I managed to get things to work.
  442.  
  443. Lines:
  444. 10 rem     Draw a box onto the screen
  445. 20 rem     then use same co-ords to
  446. 30 rem     create a zone under the box.
  447.  
  448. Are the main title, or what the main programme is about.  In an 
  449. actual programme I would use equal signs or plus/minus signs to
  450. highlight the different parts.  I will show you what I mean in the 
  451. next programme.
  452.  
  453. Lines:
  454. 40 rem
  455. 50 rem    set up the screen
  456. 60 rem
  457. 70 if mode=1 then mode 0
  458. 80 cls : key off : hide on : curs off
  459. 90 drive=0 : dir$="\stos\"
  460. 100 reserve as screen 5
  461. 110 load "pic.pi1",5
  462. 120 get palette (5)
  463. 130 screen copy 5 to physic : screen copy 5 to back
  464. 140 dir$="A:"
  465.  
  466. Are the first subroutine.  In this case the setting up of the 
  467. screen resolution and the screen colours etc...  and have all been
  468. covered before.  It finishes by returning the programme back to 
  469. the root directory of drive (A:).
  470.  
  471. The last line is important.  It must be ("A:") and not ("a:").  
  472. That means you must use a capital letter, as Stos will not change
  473. this for you.  If you forget to use a capital, then the line will 
  474. not work, and you will remain within the (STOS) folder.
  475.  
  476. Lines:
  477. 150 rem
  478. 160 rem    set up the position &
  479. 170 rem    size of the box & zone.
  480. 180 rem
  481.  
  482. Tell you what this subroutine is going to do.
  483.  
  484.  
  485. Lines:
  486. 190 X=0 : Y=0 : SIZE=60
  487. 200 X1=X : X2=X1+SIZE 210 Y1=Y : Y2=Y1+SIZE
  488.  
  489. Set up the start location, and size of the boxes.  Notice that 
  490. this time there is a new variable.  I called it (size) because it
  491. governs the size of the square.  If it had not been a square, then 
  492. I would have needed an extra variable - one for the height and one
  493. for the width - but I am keeping things as as simple as I can.
  494.  
  495. Lines:
  496. 220 rem
  497. 230 rem    Draw box and zone
  498. 240 rem
  499.  
  500. Inform you that this is where the drawing is to be done.
  501.  
  502. Line:
  503. 250 reset zone
  504.  
  505. Clears all the (zones) out of memory, and makes sure that the only 
  506. (zones) on the screen are those that you are about to create.
  507.  
  508. Lines:
  509. 260 for F=1 to 4
  510. 270 box X1,Y1 to X2,Y2
  511. 280 set zone F,X1,Y1 to X2,Y2
  512. 290 X1=X2+10 : X2=X1+SIZE
  513. 300 next F
  514.  
  515. Set up the number of boxes.  Note that the (Zone) command is the 
  516. same as the (box) command, except that each zone must have a
  517. value, unlike the boxes.
  518.  
  519. Each (Zone) has its own value, so the first zone will be (zone1) 
  520. because (F=1) the first time.  And the other (zones) will number
  521. up to 4 in this example, as that is as high a value as (F) takes 
  522. in this example.
  523.  
  524. Lines:
  525. 310 rem
  526. 320 locate 0,15 : pen 2 : print "PRESS A MOUSE KEY TO PLAY"
  527. 330 locate 0,22 : pen 2 : print "CONTROL C TO QUIT"
  528.  
  529. Print messages to screen to inform you of what is happening, and 
  530. how to stop the programme.
  531.  
  532. Lines:
  533. 340 rem    set up zone detection
  534. 350 rem
  535.  
  536. Tell you that this is where the (Zones) are detected.
  537.  
  538. Lines:
  539. 360 MX1=X : MX2=X2
  540. 370 MY1=Y : MY2=Y2
  541. 380 if MX2>=320 then MX2=319
  542. 390 limit mouse MX1,MY1 to MX2,MY2
  543. 400 show on
  544.  
  545. Limit the mouse to the area where the boxes are drawn, and then 
  546. reveal the mouse on screen.
  547.  
  548. If you are wondering why the mouse moves past the last box, the 
  549. answer lies in the (MX2=X2) which is wrong.  Think back to when we
  550. had more than four boxes on the screen, and had to reset (X2) 
  551. because (X1) was too large.
  552.  
  553. Another clue would be that (F=5) but there are only 4 boxes drawn 
  554. onto the screen. I will explain it in the last lesson if you have
  555. not got it yet.
  556.  
  557. Line:
  558. 410 MK=0
  559.  
  560. Sets the value of the mouse key to zero.  This is a variable that 
  561. I have created to zero the mouse key value.  Each mouse key has a
  562. value - as does each joystick direction - and by testing the value 
  563. of the mouse keys, you can test whether a key is being pressed.
  564.  
  565. I always put the value at the start of the routine.  It is as well 
  566. being there as being anywhere else, and will be the point in the
  567. programme that is jumped to to retest the mouse keys.
  568.  
  569. Lines:
  570. 420 repeat
  571. 430 MK=mouse key
  572. 440 until MK<>0
  573.  
  574. Form a loop that will be repeated until something happens.  What 
  575. that something is, is determined by you.  In this case it is a
  576. mouse key being pressed.  So the command means (REPEAT UNTIL MK 
  577. does not equal zero).  Notice that (MK) has already been set to
  578. zero in line 410, and now it is being reset to the mouse keys.
  579.  
  580. No mouse key = 0
  581. The left mouse key =1
  582. The right mouse key = 2
  583. Both keys = 3 (1+2=3)
  584.  
  585. Line:
  586. 450 BUTTUN=zone(0)
  587.  
  588. Creates a variable for the squares on screen.  Remember that they 
  589. are supposed to be buttons to activate things.  And it test for a
  590. sprite entering the zone.  In this case it is testing for the 
  591. mouse, and as the mouse is (sprite 0) then this is the value that
  592. is tested for, and (buttun) will then hold the value of he zone.
  593.  
  594. If you do not click in a square - zones 1 to 4 - the the value of 
  595. the zone will be zero.
  596.  
  597. Notice also that the word is not buttOn but buttUn.  This is to 
  598. get around the command word (ON) which would be part of butt(ON),
  599. and you are not allowed to use command words in variables.
  600.  
  601. Oddly enough the variable sim(ON) would work, at least it does on 
  602. my computer.  You can tell that something is wrong with your
  603. variables when you list them.
  604.  
  605. buttun would list as buttun, however;
  606.  
  607. button would list as  butt ON.
  608.  
  609. Or it could be the other way around, depending upon whether 
  610. commands or variables take capitals in your setup.
  611.  
  612. ie. BUTT on.
  613.  
  614. Lines:
  615. 460 locate 0,12 : print "YOU ARE IN ZONE";BUTTUN
  616. 470 wait 100
  617. 480 locate 0,12 : print "                   "
  618. 490 goto 410
  619.  
  620. Prints the value of the zone that you are in, waits a short while, 
  621. and then erases the message by printing a blank message on top. 
  622. Then it returns to line 410 which resets the variable (MK) back to 
  623. zero.  If it was not reset somewhere, than the (REPEAT UNTIL) loop
  624. would fail because (MK) would still hold the value of the mouse 
  625. key that was pressed.
  626.  
  627. The spaces printed - in line 480 - are two greater than the 
  628. letters printed - in line 460 - to allow for the value of buttun
  629. to also be erased.  It should be one figure and one space away 
  630. from the message, thus two extra spaces are needed.
  631.  
  632. Lines:
  633. 500 rem    reset the screen for editing
  634. 510 rem
  635. 520 curs on : show on : limit mouse : pen 1
  636.  
  637. Would reset the screen, but in this programme they are never acted 
  638. upon, because the only escape is via the break key.  I will change
  639. it slightly now to show you how to set up a series of choises.
  640.  
  641.  
  642. This is basically the same programme, but I have altered certain 
  643. lines to improve the programme a bit.
  644.  
  645. Notice the way that I have highlighted the (REM) statements, and 
  646. used different ways for different parts of the programme.
  647.  
  648.  
  649.  
  650. LESSON 5
  651.  
  652.  
  653. 10 rem =======================================
  654. 20 rem =======================================
  655. 30 rem ===  Draw a box onto the screen    ===
  656. 40 rem ===  then use same co-ords to      ===
  657. 50 rem ===  create a zone under the box.  ===
  658. 60 rem =======================================
  659. 70 rem =======================================
  660. 80 rem
  661. 90 rem ---- store screen res and drive ----
  662. 100 rem
  663. 110 MD=mode
  664. 120 DRV=drive
  665. 130 rem
  666. 140 rem ---- set up the screen  ----
  667. 150 rem 160 if mode=1 then mode 0
  668. 170 cls : key off : hide on : curs off 180 drive=0 : dir$="\stos\" 
  669.  
  670. 190 reserve as screen 5
  671. 200 load "pic.pi1",5
  672. 210 get palette (5)
  673. 220 screen copy 5 to physic : screen copy 5 to back
  674. 230 dir$="a:"
  675. 240 rem
  676. 250 rem ----   set up the position &     ----
  677. 260 rem ----   size of the box & zone.  ----
  678. 270 rem
  679. 280 X=0 : Y=0 : SIZEH=60 : SIZEV=30
  680. 290 X1=X : X2=X1+SIZEH 300 Y1=Y : Y2=Y1+SIZEV
  681. 310 rem
  682. 320 rem ++++   Draw box and zone  ++++
  683. 330 rem
  684. 340 reset zone
  685. 350 for F=1 to 4
  686. 360 box X1,Y1 to X2,Y2
  687. 370 set zone F,X1,Y1 to X2,Y2
  688. 380 X1=X2+10 : X2=X1+SIZEH
  689. 390 next F
  690. 400 rem
  691. 410 rem ++++ SCREEN MESSAGE +++++
  692. 420 rem
  693. 430 locate 0,15 : pen 4 : print "PRESS LEFT KEY TO PLAY"
  694. 440 locate 0,22 : pen 4 : print "PRESS RIGHT KEY TO QUIT"
  695. 450 rem
  696. 460 rem ----   set up zone detection  ----
  697. 470 rem
  698. 480 rem
  699. 490 rem ++++ limit mouse to zones ++++
  700. 500 rem
  701. 510 MX1=X : MX2=X1-10
  702. 520 MY1=Y : MY2=Y2
  703. 530 rem
  704. 540 limit mouse MX1,MY1 to MX2,MY2
  705. 550 show on
  706. 560 rem
  707. 570 rem ---- detect mouse key ----
  708. 580 rem
  709. 590 MK=0
  710. 600 repeat
  711. 610 MK=mouse key
  712. 620 until MK<>0
  713. 630 rem
  714. 640 rem ++++ test for not key one ++++
  715. 650 rem
  716. 660 if MK<>1 then goto 780
  717. 670 rem
  718. 680 rem ++++ only if key one ++++
  719. 690 rem
  720. 700 BUTTUN=zone(0)
  721. 710 locate 0,12 : print "YOU ARE IN ZONE";BUTTUN
  722. 720 wait 100
  723. 730 locate 0,12 : print "                   "
  724. 740 goto 590
  725. 750 rem
  726. 760 rem ---- reset the screen for editing ----
  727. 770 rem
  728. 780 curs on : show on : limit mouse : pen 1 : mode MD : drive=DRV
  729.  
  730.  
  731. This is the final lesson of this tutorial, so I have included 
  732. everything that we have been going over so far.  And if you are
  733. wondering, I do indeed use this many (REMS) when I programme.  OK 
  734. it takes a couple of hours to remove them - if you want to - when
  735. the programme is finished, but it saves hours upon hours of 
  736. wondering how I achieved something.
  737.  
  738. Lines:
  739. 10 rem =======================================
  740. 20 rem =======================================
  741. 30 rem ===  Draw a box onto the screen    ===
  742. 40 rem ===  then use same co-ords to      ===
  743. 50 rem ===  create a zone under the box.  ===
  744. 60 rem =======================================
  745. 70 rem =======================================
  746.  
  747. Are the title, and everything should have a title.  I use the (=) 
  748. because it stands out.  I then use the (-) for each sub routine,
  749. and the (+) for each part of that subroutine.
  750.  
  751. The upshot is, that in a programme several 100 lines long, can be 
  752. listed and stopped at the right spot.
  753.  
  754. Lines:
  755. 80 rem
  756. 90 rem ---- store screen res and drive ----
  757. 100 rem
  758. 110 MD=mode
  759. 120 DRV=drive
  760.  
  761. Are somewhat new.  I have included a variable to store both the 
  762. drive and the screen resolution.  The screen resolution is the
  763. most important, as most things run in low resolution, but are 
  764. easier read from medium resolution.  So I edit in medium, but run
  765. in low resolution.
  766.  
  767. Lines:
  768. 130 rem
  769. 140 rem ---- set up the screen  ----
  770. 150 rem
  771. 160 if mode=1 then mode 0
  772. 170 cls : key off : hide on : curs off
  773. 180 drive=0 : dir$="\stos\"
  774. 190 reserve as screen 5
  775. 200 load "pic.pi1",5
  776. 210 get palette (5)
  777. 220 screen copy 5 to physic : screen copy 5 to back
  778. 230 dir$="A:"
  779.  
  780. Have not been changed.  They just set up a screen bank after 
  781. checking on screen resolution etc.. and then get picture and store
  782. it in bank 5.  Then it returns the programme back to the root 
  783. directory of drive (A:).
  784.  
  785. Lines:
  786. 240 rem
  787. 250 rem ----   set up the position &     ----
  788. 260 rem ----   size of the box & zone.  ----
  789. 270 rem
  790. 280 X=0 : Y=0 : SIZEH=60 : SIZEV=30
  791. 290 X1=X : X2=X1+SIZEH
  792. 300 Y1=Y : Y2=Y1+SIZEV
  793.  
  794. Set up the size and location of the first box.  Notice that this 
  795. time the boxes are not square.  As a result I have had to include
  796. a variable for both the height and width.  In this case I have 
  797. just tagged a (V) for vertical and (H) for horizontal onto the old
  798. variable.  So (SIZEH) means size horizontal.
  799.  
  800. There is no particular reason for the box sizes, other than to be 
  801. large enough to hold something, but small enough to fit nicely
  802. onto the screen.
  803.  
  804. Lines:
  805. 310 rem
  806. 320 rem ++++   Draw box and zone  ++++
  807. 330 rem
  808.  
  809. Tell you what is going to happen.  Notice that I have used (+) to 
  810. show that it is still part of the setting up of boxes subroutine.
  811.  
  812. Line:
  813. 340 reset zone
  814.  
  815. Resets all zones.  It removes all zones in fact.  You need to 
  816. include this to control the number and place of the zones.  In
  817. this example it does not matter, because there is only the one set 
  818. of zones being created.  But if you create others later on, you
  819. need a way of turning the old zones off.
  820.  
  821. Lines:
  822. 350 for F=1 to 4
  823. 360 box X1,Y1 to X2,Y2
  824. 370 set zone F,X1,Y1 to X2,Y2
  825. 380 X1=X2+10 : X2=X1+SIZEH
  826. 390 next F
  827.  
  828. Draw the boxes and zones to screen.  Notice that all I needed to 
  829. change here was the variable (SIZE) to (SIZEH) even though the
  830. boxes are not the same height as those drawn previously.
  831.  
  832. Lines:
  833. 400 rem
  834. 410 rem ++++ SCREEN MESSAGE +++++
  835. 420 rem
  836. 430 locate 0,15 : pen 4 : print "PRESS LEFT KEY TO PLAY"
  837. 440 locate 0,22 : pen 4 : print "PRESS RIGHT KEY TO QUIT"
  838.  
  839. Show the new messages.  Notice that I have changed the (PEN) 
  840. colour to avoid flashing when the cursor is reactivated.
  841.  
  842. Notice also that the left mouse key will activate the programme, 
  843. whilst the right one will now quit back to the screen.  Actually,
  844. pressing both keys will also quit.
  845.  
  846. Lines:
  847. 450 rem
  848. 460 rem ----   set up zone detection  ----
  849. 470 rem
  850. 480 rem
  851.  
  852. The start of a new subroutine, is shown by(-).
  853.  
  854. Lines:
  855. 490 rem ++++ limit mouse to zones ++++
  856. 500 rem
  857. 510 MX1=X : MX2=X1-10 520 MY1=Y : MY2=Y2
  858. 530 rem
  859. 540 limit mouse MX1,MY1 to MX2,MY2
  860. 550 show on
  861.  
  862. I have changed the (MX2) bit and have removed the test for the 
  863. mouse moving off of the screen in the (LIMIT MOUSE) command.
  864.  
  865. The reason the mouse moved too far to the left was because the 
  866. (X1) command was read 5 times, but only used 4 times, so was now
  867. holding the location of the start of the 5th box.  The reason for 
  868. subtracting 10 from (X1) in (MX2=X1-10) is because that is the
  869. spacing provided earlier (line 380 X1 =X2-10), so if you take 10 
  870. from (X1) you have location of the end of the last box.
  871.  
  872. This could also have been done by subtracting the value of (SIZEH) 
  873. plus 10 from (X2)  ie (MX2 = X2-(SIZEH+10)).  So you take
  874. (60+10=70) and subtract it from (X2).
  875.  
  876. Lines:
  877. 560 rem
  878. 570 rem ---- detect mouse key ----
  879. 580 rem
  880. 590 MK=0
  881. 600 repeat
  882. 610 MK=mouse key
  883. 620 until MK<>0
  884.  
  885. Detecting the mouse key, and no changes have been made.  (MK) 
  886. which will hold the value of the mouse key is reset to zero, which
  887. means no key has been pressed when the (REPEAT UNTIL) command is 
  888. tested.
  889.  
  890. Lines:
  891. 630 rem
  892. 640 rem ++++ test for not key one ++++
  893. 650 rem
  894. 660 if MK<>1 then goto 780
  895.  
  896. Are new, and test to see if (MK=1).  If it does then this line is 
  897. ignored.  However, if you pressed either the right key or both of
  898. them then (MK) will not equal 1 ,  in this case the programme will 
  899. jump to line 780.
  900.  
  901. Remember that the programme loops until a mouse key is pressed, so 
  902. you do not have to check for zero.
  903.  
  904. Lines:
  905. 670 rem
  906. 680 rem ++++ only if key one ++++
  907. 690 rem
  908. 700 BUTTUN=zone(0)
  909. 710 locate 0,12 : print "YOU ARE IN ZONE";BUTTUN
  910. 720 wait 100
  911. 730 locate 0,12 : print "                   "
  912. 740 goto 590
  913.  
  914. Are not changed, and print a message telling you which zone the 
  915. mouse was in when you pressed the mouse key.
  916.  
  917. Lines:
  918. 750 rem
  919. 760 rem ---- reset the screen for editing ----
  920. 770 rem
  921. 780 curs on : show on : limit mouse : pen 1 : mode MD : drive=DRV
  922.  
  923. End the programme and reset the screen for editing.  I did not 
  924. include a variable to reset the screen colours, as you could do
  925. that yourself.
  926.  
  927. But that, as they say, is that.  And is more than enough for now.  
  928. Next time I intend to cover the different screens, and touch upon
  929. the Sprite Editor, and how to use it to make sprites that can be 
  930. used with the Zone command to control your programmes.
  931. ~
  932.  
  933.  
  934.