Commodore VIC-20 User Manual page 261

Hide thumbs Also See for VIC-20:
Table of Contents

Advertisement

UI
PRINT
":1'
20 FOR T-38400 TO 38421
30
POKE
T,6:NE~T
40 FOR T-7680 TO 7701
58 FOR Y-e TO
10:NE~T
60 POKE T-l, 32:POKE
T,81:~T
70 FOR T-7701 TO 7680 STEP -1
80 FOR Y-0 TO
10:NE~T
90 POKE T+l,32: POKE T,81: NEXT
100 OOTO 40
Chapter 7: Sound
247
Now we will add sound with the following lines:
15
POI<E
36878, 15
6S
POKE 36876,248:
POKE
36876,0
95 POKE 36876,230: POKE 36876,8
The addition of sound helps create the effect of a bouncing ping-pong ball.
To synchronize the sound with a visual event on the screen, you will
have to be aware ofthe position ofthe objects on the screen. In the example
above, the timing was straightforward because the sound was created at the
end of each loop. To make simple sounds synchronize with movements, the
sounds should generally take place when one object collides with another.
The following program determines object movement and sound based on
the numeric position on the screen:
10 POKE 36878,15: R
a
l: RT-.7: PRINT ":']"
20 FOR T-38400 TO 38421: POKE T,5:NEXT
30 FOR T
a
38422 TO 38443:POKE T,6:NEXT
40 T-7680: TT-7702
50 POKE T,SI:POKE T-l,32:POKE T+l,32
60 POKE TT,81: POKE TT-l,32: POKE 1T+l,32
70 T-T+R: TT-TT+RT
S0 IF T-7680 OR T-7701 THEN R-R*-1
90 IF TT)7723 OR T(7702 THEN RT-RT*-l
1.00 OOTO 50
Because different tone values are used, it is immediately apparent which
object has just hit the wall.
Tailoring the Sound
to
The Picture
Now let's look at some exploding ping-pong balls. The next program
will take our familiar ping-pong sound and combine it with a picture. After a

Advertisement

Table of Contents
loading

Table of Contents