Commodore 128 Programmer's Reference Manual page 288

Hide thumbs Also See for 128:
Table of Contents

Advertisement

278
COMMODORE 128
The third sprite example provides an algorithm to overlay two sprites and move
them on the screen on a 45-degree angle. Again, this program assumes your sprite data
resides in sprite storage. If your sprite images are not stored there, fill the sprites with
data as you did in the last adjoining example.
Here's the listing:
10 REM OVERLAY EXAMPLE
20 REM THIS PROGRAM ASSUMES SPRITE DATA RESIDES IN SPRITE STORAGE
30
1=1
:REM INITIALIZE DISTANCE
I
35
SCNCLR
40 MOVSPR 8,50,100:REM SET ORIG POSITION OF SPRITE 8
50 MOVSPR 7,50,100:REM SET ORIG POSITION OF SPRITE 7 TO OVERLAY SPR 8
60 DO
70 SPRITE 8,1,3
:REM ENABLE SPR 8
80 MOVSPR 8,1;45
:REM MOVE SPR 8
I UNITS AT A 45 DEGREE ANGLE
90
SPRITE 8,0,3
:REM TURN OFF SPR8
100 SPRITE 7,1,4
:REM ENABLE SPR 7
110 MOVSPR 7,I;45
:REM MOVE SPR 8
I UNITS AT A 45 DEGREE ANGLE
120 SPRITE 7,0,3
:REM TURN OFF SPR 7
140 LOOP
Q
0
LJ
D
As in the last program, line 30 initializes the distance variable I to 1.
] 1
Lines 40 and 50 position sprites 8 and 7, respectively, at coordinate 50,100. At
Lj
this point the sprites are not yet enabled, but when they are, sprite 7 will overlay sprite 8
since the lower sprite number has display priority over the higher sprite number.
\ ,
Line 60 initiates a DO loop to move the sprites along the sprite coordinate plane.
lj
Line 70 enables sprite 8 and colors it red. Line 80 moves sprite 8 a distance of one
coordinate according to the current value of I. Line 90 disables sprite 8.
Lines 100 through 120 perform the same operations for sprite 7 as lines 70 through
j j
90 did for sprite 8: enable, move a single distance coordinate according to I and disable.
^
Line 140 repeats the process.
Since this process is repeated so quickly, it appears as though the two sprites
) [
alternate movements. When you create the actual images you will use in your overlay
jj
sprite program, the images between which you alternate will be ones that simulate the
movement of two images and create one animated image.
r f
Create two sprites that appear to form a single animated image. You may have to
j
perfect the timing of the enabling and disabling of the images to make the animated
image appear more smooth. Nonetheless, you have a basis for animating two objects
into one single moving object.
] j
uJ
Although these program examples are written in BASIC, the algorithms are the
same whether you are programming in BASIC or machine language. The next section
w
discusses sprite operations independent of the BASIC language. Since this section
JJ
explained sprites according to BASIC, the next section elaborates on the inner workings
of sprites from a machine level (language) perspective.
Lj
LJ

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents