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 >
Wrap
Text File
|
1987-04-22
|
5KB
|
112 lines
THE COOL CARROT PRESENTS:
DeBounce: A Demo Dissected.
The DeBounce program is the one section of code I have written
that I am completly satisfied with. Written in STOS (although it
could be converted) and never published before, it (while
pretending to be an unsophisticted demo) is a "perfect" model of
a bouncing ball (albeit only in 2D!).
It shows a ball projected into the air, bouncing faster and
faster while going lower and lower. The version I was hoping to
release included sample code (and the bounce sample from
MindBomb, cleverly nicked!) but I have taken out the sample
driver code here.
So, in order, here comes the listing!
100 rem COSINE DeBOUNCE V2.3C
110 rem SET UP SAMPLE
120 mode 0 : menu off : key off : curs off : click off : hide
The first few lines just set up the screen, and if neccessary
set up the sample also. The commands may vary if you are writing
for another BASIC.
140 repeat
150 sprite off : unpack 2,logic : unpack 2,back : wait vbl
160 C#=237 : X=rnd(180)+10
170 ink 1 : ellipse X,195,8,3
180 I=rnd(2)+1
190 if I=1 then colour 7,$400 : colour 8,$700 : colour 9,$744
200 if I=2 then colour 7,$40 : colour 8,$70 : colour 9,$474
210 if I=3 then colour 7,$4 : colour 8,$7 : colour 9,$447
This section controls the setup. The "repeat" sets up the first
loop, while a screen is set up in line 150. Line 160 sets C#, a
floating-point variable that sets the upper limit of the ball's
climb, and X, the ball's X-co-ordinate. 170 draws the ball's
shadow, while 180 I determines the colour of the ball while 190-
210 set up this colour. (If you draw a screen for this, make sure
colours 7-9, counting from 0-15, are left unused; or change the
code!)
220 for B=1 to 30
230 D#=C#*0.75 : E=int(D#)
240 for A=180 to 1 step-B
250 Z#=A*0.01745329*0.5
260 Y=195-(cos(Z#)*E)
270 sprite 1,X,Y,9
280 next A
This is the first section of the second loop. B sets the number
of times the ball will bounce (30). D# is the new, smaller value
of C# (meaning the bounce gets lower) and E is an integer
version. 240 starts the third loop (with the B meaning it gets
faster as B increases) while Z# is the cosine of A. (The long
number converts from degrees to radians). 260 sets Y, converting
Z to this for the screen (including E, setting the height, or
amplitude, of the bounce) and 270 plots a ball sprite (size:
16*16; only 3 colours) at the right co-ords. 280 finishes the
loop.
When this point is reached, the ball will have reached (195-E),
its highest point.
290 for A=2 to 179 step B
300 Z#=A*0.01745329*0.5
310 Y=194-(cos(Z#)*E)
320 sprite 1,X,Y,9
330 next A
340 C#=D#
350 rem PLAY SAMPLE
360 next B
The first part of this (290-330) repeats (but in the opposite
direction) the section immediatly above it. Then it replaces the
old value of C# with the new one. If you wish, a sample can be
played now, then it loops back to start again. This will repeat
for 30 times, getting faster and lower.
370 for I=1 to 50 : wait vbl : next I
380 sprite off : ink 0 : bar 0,186 to 319,199 : REM STOP
SAMPLE
390 until mouse key<>0
This section gives a pause of 1 second (in Britain on a TV,
anyway!) and clears the graphics. Then comes the end of the first
loop, with a decision (on whether or not to continue) is made by
checking the mousekey. Again, this may need to be changed (for
other BASICS).
400 fade 3,$777,$777,$777,$777,$777,$777,$777,$777,$777,$777,
$777,$777,$777,$777,$777,$777 : samstop
410 for I=1 to 30 : wait vbl : next I
420 logic=default logic
430 back=default back
440 physic=default physic
450 show
This section is optional, and fades out then clears the
screen. Any other ending is probably OK.
This uses trigonometry, sprites, loops, and (if you want)
samples, and may be used to teach new programmers. I'm not sure
if you'll like it, but I hope you do!
You may, on seeing the program, think "this is crap". Well, it
probably is, but adapt it! Try to add rasters (subroutine? in
program?), or a background, or another ball (of another colour),
or, most difficult, rasters with a different coloured ball, out
of phase with the first! That WOULD be brilliant!
THE COOL CARROT (an honourary HB?), 4 October 1990.
A short note from Eddie - the source code for debounce is in the
programming directory, but it is a ascii file so you will have to
load it in to STOS using LOAD "file.ASC" Ok.
}