Classic Computer Magazine Archive COMPUTE! ISSUE 125 / JANUARY 1991 / PAGE G24

Multiple sprites on the move. (Beginner BASIC) (Gazette - Commodore 64 & 128) (column)
by Larry Cotton

Happy New Year! My first New Year's resolution is to finish our multiple-sprite program that we began in December's column. Load that program, and we'll continue by positioning all eight sprites. 100 FORT=0TO14STEP2:POKEV+T,X


V and X were defined in line 90. Since the sprites' horizontal memory registers are V, V+2, V+4, and so on, we use STEP 2 in the FOR-NEXT loop, which causes every other memory register to be poked. The same goes for the sprites' vertical registers (V+1, V+3, V+5, and so on). 110 FORT=1TO15STEP2:POKEV+T,


Memory registers V+23 (53248+23=53271) and V+29 (53248+29=53277) control sprite height and width, respectively.

For sprite 0, if you POKE V+23, 1 and POKE V+29,0, the sprite will be tall and narrow; poking both V+23 and V+29 with a 1 will cause sprite 0 to be tall and wide.

The two sprite-size registers (V+23 and V+29) must be poked very carefully with numbers from 0 to 255. Look at the following chart.

Bit No. 7 6 5 4 3 2 1 0

Values 128 64 32 16 8 4 2 1

On/Off 0 0 0 0 0 0 0 1

Poking 1 to a memory register turns on only bit 0. Poking 4 would turn on only bit 2. Poking a sum of 8 and 16, or 24, turns on bits 3 and 4.

Bit No. 7 6 5 4 3 2 1 0

Values 128 64 32 16 8 4 2 1

On/Off 0 0 0 1 1 0 0 0

Poking a 255 (or K, as defined in line 90) turns on all the bits. The sprites are conventionally numbered the same as the bits. Therefore, poking 1 to V+23 or V+29 controls the size of sprite 0 only. Poking 24 controls sprites 3 and 4. Poking 255 (or K) controls all the sprites. To make all eight as tall and wide as possible, poke V+23 and V+29 with 255 (K). 120 POKEV+23,K:POKEV+29,K

Memory register V+21 (53269) turns sprites on or off (makes them visible or invisible). To turn all eight sprites on, use POKE V + 21,255. (While we're at it, turn the sound on by poking V1 with 23, a funky combination of voice 1, ring mood, and sync.) 130 POKEV+21,K:POKEV1,23

Now define a few variables. 140 J = 1:Q = 1:F1 = 1

Line 140 is the beginning of a repeatable loop. J start as 1. Later it will change to -- 1. Q is the number of pixels the sprites will be displaced from their original locations. F1 is the frequency of voice 1. Now let's make all the sprites green. 150 FORT = 39TO46:POKEV + T,5:


Registers V + 39 through V + 46 control the sprites' colors. Thus, the FOR-NEXT loop assigns color 5 (green) to all eight sprites. Now we need to make a couple of IF-THEN checks to see if the sprites have moved to the extremes of their travel. 160 IFQ>MTHENJ =-1:M$ = "[RED]

MERRY CHRISTMAS":GOSUB300 170 IFQ<0THENM$ ="(15 spaces)":


Recall that Q is the number of pixels each sprite moves from its original position. M was defined as 79.

When Q becomes greater than M, we want the sprites to reverse direction; thus J becomes -- 1. Conversely, if Q becomes less than 0, the sprites have returned to their original position, and we begin a new loop at 140. 180 Q = Q + J

Remember that J can be either 1 or -- 1. Thus Q will either increase or decrease by 1. Line 190 is reserved for a REMark that explains lines 200-220. Those lines move the sprites by increasing or decreasing their horizontal and vertical locations. 200 POKEV,X+Q:POKEV+2,X--Q:




+13,Y+Q:POKEV+14,X+Q 220 POKEV+15,Y+Q

As Q's value increases (J = + 1), the sprites move away from each other. As Q decreases (J = -- 1), the sprites move toward each other. 230 POKEVF,F1:F1 = F1+J

All this does is poke a frequency value to control voice 1's pitch. 240 GOTO160

We need a subroutine that positions the cursor, prints the message, and causes a short delay. 300 POKE214,11:PRINT:POKE211,12:



To use sprites of your own creation, change the data in lines 50-70.