Commodore VIC-20 User Manual page 74

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

Advertisement

(
Here is a short program to bounce a ball around the screen,
f-
followed by a detailed explanation.
10 PRINT " I " ■:: I fljft^
<
c
c
I
(
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
POKE
POKE
X = 1
Y=1
DX = 1
DY = 1
POKE
FORT
POKE
X-X -
IFX=
36879,9
36878.15
7680 + X + 22*Y,81
= 1TOl0; NEXT
7680+X
:-DX
0ORX-
Y - Y + DY
IFY =
POKE
GOTO
0ORY =
36876, 0
80
+ 22*Y, 32
21 THEN DX = -DX: POKE 36876. 220
22 THEN DY = -DY: POKE 36786, 230
c
c
c
i
Line 10 clears the screen, and line 20 sets the color of the
f
screen to black with a white border. Line 30 sets the loudness
of the sound generators to the loudest level.
(
The X and Y variables used in lines 40 and 50 keep track of the
current column and row position of the ball. The DX and DY
^
used in lines 60 and 70 are the horizontal and vertical direction
of the ball's movement. When a +1 is added to the X value, the
column is moved 1 to the right. When -1 is added to X, the
column of the ball is moved 1 to the left. +1 added to Y moves
the ball down a row, and -1 added to Y moves the ball up a row.
(
Line 80 puts the ball character on the screen at its current
position. Line 90 is a delay loop, leaving the ball on the screen
just long enough for your eye to see it. LinetOOnow erases the
ball by putting a space (code of 32) where it was on the screen.
Line 110 adds the direction factor to X. Line 120 tests to see if
the ball has reached one of the side walls, reversing the
^
direction and beeping if there is a bounce. Lines 130 and 140 do
the same for the top and bottom walls.
(
Line 150 turns off the sound, if any. to complete the bounce
sound effect. Line 160 sends the program back to display and
move the ball again.
c

Advertisement

Table of Contents
loading

Table of Contents