home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / STOSBTS1.ARJ / stosbts1.msa / DATA / PMDBO.DAT < prev    next >
Text File  |  1987-04-22  |  5KB  |  112 lines

  1.  
  2.  THE COOL CARROT PRESENTS:
  3.  
  4.   DeBounce: A Demo Dissected.
  5.  
  6.   The DeBounce program is the one section of code I have written 
  7. that I am completly satisfied with.  Written in STOS (although it 
  8. could be converted) and never published before, it (while 
  9. pretending to be an unsophisticted demo) is a "perfect" model of 
  10. a bouncing ball (albeit only in 2D!).
  11.   It shows a ball projected into the air, bouncing faster and 
  12. faster while going lower and lower. The version I was hoping to 
  13. release included sample code (and the bounce sample from 
  14. MindBomb, cleverly nicked!) but I have taken out the sample 
  15. driver code here.
  16.   So, in order, here comes the listing!  
  17.  
  18.      100 rem COSINE DeBOUNCE V2.3C                          
  19.      110 rem SET UP SAMPLE
  20.      120 mode 0 : menu off : key off : curs off : click off : hide 
  21.   The first few lines just set up the screen, and if neccessary 
  22. set up the sample also.  The commands may vary if you are writing 
  23. for another BASIC.
  24.  
  25.      140 repeat
  26.      150 sprite off : unpack 2,logic : unpack 2,back : wait vbl 
  27.      160 C#=237 : X=rnd(180)+10
  28.      170 ink 1 : ellipse X,195,8,3
  29.      180 I=rnd(2)+1
  30.      190 if I=1 then colour 7,$400 : colour 8,$700 : colour 9,$744
  31.      200 if I=2 then colour 7,$40 : colour 8,$70 : colour 9,$474
  32.      210 if I=3 then colour 7,$4 : colour 8,$7 : colour 9,$447
  33.   This section controls the setup. The "repeat" sets up the first 
  34. loop, while a screen is set up in line 150. Line 160 sets C#, a 
  35. floating-point variable that sets the upper limit of the ball's 
  36. climb, and X, the ball's X-co-ordinate. 170 draws the ball's 
  37. shadow, while 180 I determines the colour of the ball while 190-
  38. 210 set up this colour. (If you draw a screen for this, make sure 
  39. colours 7-9, counting from 0-15, are left unused; or change the 
  40. code!)
  41.  
  42.      220 for B=1 to 30
  43.      230 D#=C#*0.75 : E=int(D#)
  44.      240 for A=180 to 1 step-B
  45.      250 Z#=A*0.01745329*0.5
  46.      260 Y=195-(cos(Z#)*E)
  47.      270 sprite 1,X,Y,9 
  48.      280 next A
  49.   This is the first section of the second loop. B sets the number 
  50. of times the ball will bounce (30). D# is the new, smaller value 
  51. of C# (meaning the bounce gets lower) and E is an integer 
  52. version. 240 starts the third loop (with the B meaning it gets 
  53. faster as B increases) while Z# is the cosine of A. (The long 
  54. number converts from degrees to radians). 260 sets Y, converting 
  55. Z to this for the screen (including E, setting the height, or 
  56. amplitude, of the bounce) and 270 plots a ball sprite (size: 
  57. 16*16; only 3 colours) at the right co-ords. 280 finishes the 
  58. loop.
  59.   When this point is reached, the ball will have reached (195-E), 
  60. its highest point. 
  61.  
  62.      290 for A=2 to 179 step B
  63.      300 Z#=A*0.01745329*0.5
  64.      310 Y=194-(cos(Z#)*E)
  65.      320 sprite 1,X,Y,9
  66.      330 next A
  67.      340 C#=D#
  68.      350 rem PLAY SAMPLE
  69.      360 next B
  70.   The first part of this (290-330) repeats (but in the opposite 
  71. direction) the section immediatly above it. Then it replaces the 
  72. old value of C# with the new one. If you wish, a sample can be 
  73. played now, then it loops back to start again. This will repeat 
  74. for 30 times, getting faster and lower.
  75.  
  76.      370 for I=1 to 50 : wait vbl : next I
  77.      380 sprite off : ink 0 : bar 0,186 to 319,199 : REM STOP 
  78.          SAMPLE
  79.      390 until mouse key<>0
  80.   This section gives a pause of 1 second (in Britain on a TV, 
  81. anyway!) and clears the graphics. Then comes the end of the first 
  82. loop, with a decision (on whether or not to continue) is made by 
  83. checking the mousekey. Again, this may need to be changed (for 
  84. other BASICS).
  85.  
  86.      400 fade 3,$777,$777,$777,$777,$777,$777,$777,$777,$777,$777,
  87.          $777,$777,$777,$777,$777,$777 : samstop 
  88.      410 for I=1 to 30 : wait vbl : next I
  89.      420 logic=default logic
  90.      430 back=default back
  91.      440 physic=default physic
  92.      450 show 
  93.   This section is optional, and fades out then clears the 
  94. screen. Any other ending is probably OK.
  95.  
  96.   This uses trigonometry, sprites, loops, and (if you want) 
  97. samples, and may be used to teach new programmers. I'm not sure 
  98. if you'll like it, but I hope you do!
  99.  
  100.   You may, on seeing the program, think "this is crap". Well, it 
  101. probably is, but adapt it! Try to add rasters (subroutine? in 
  102. program?), or a background, or another ball (of another colour), 
  103. or, most difficult, rasters with a different coloured ball, out 
  104. of phase with the first! That WOULD be brilliant!  
  105.  
  106.  THE COOL CARROT (an honourary HB?), 4 October 1990.
  107.  
  108. A short note from Eddie - the source code for debounce is in the 
  109. programming directory, but it is a ascii file so you will have to 
  110. load it in to STOS using LOAD "file.ASC" Ok. 
  111. }
  112.