Animation with Player/Missile Graphics
The Great Pumpkin
A common feature of many 8-bit computers is something called sprites or as they are called in the Atari world, player/missile graphics.
Regardless of the name, these are small objects that can be shown and moved around on the screen independent of what might already be shown there. A sprite might be the space ships in Space Invaders, Pac-Man itself or any other avatar or enemy in many games.
The Atari calls these player/missiles because that’s what they were originally called on the VCS/2600. On other systems, a sprite is usually a rectangular area. For example on a Commodore 64 it is a 24x21 pixel rectangle. A Player on an Atari is instead an 8-bit wide strip that is the height of the screen.
For Halloween I thought it might be fun to make a simple Atari BASIC program that moves a pumpkin on the screen using a player.
I also decided that 8 bits was not quite wide enough to draw a nice pumpkin so I thought I would combine two players together to make a slightly bigger pumpkin.
This is the pumpkin pixel drawing I started with:
This pumpkin is 14 pixels wide, so too big for a single Player. But by splitting it in half we can use two Players with 7 bits for the left and 7 bits for the right and display them side-by-side. For the left side, the left-most bit will always be 0. For the right side, the right-most bit will always be 0.
The first step is to convert this to the data needed to POKE into the player memory. Essentially you write each line of the pumpkin as binary, with a 1 for a filled pixel and a 0 for an empty pixel.
Left side:
00000000 = 0
00000001 = 1
00000111 = 7
00011111 = 31
00111111 = 63
01111011 = 123
01110001 = 113
01111111 = 127
01100101 = 101
01110000 = 112
01111010 = 122
00111111 = 63
00011111 = 31
00000111 = 7
Right side:
11000000 = 192
10000000 = 128
11100000 = 224
11111000 = 248
11111100 = 252
11011110 = 222
10001110 = 142
11111110 = 254
10100110 = 166
00001110 = 14
01011110 = 94
11111100 = 252
11111000 = 248
11100000 = 224
The above translates to these DATA statements:
3000 REM * PLAYERS 0 & 1 *
3010 DATA 0,1,7,31,63,123,113,127,101,112,122,63,31,7
3020 DATA 192,128,224,248,252,222,142,254,166,14,94,252,248,224
Atari BASIC has built-in support for some graphics, but it does not have support for player/missile graphics. This means you have to POKE a bunch of value to set things up.
In the case of players, moving their horizontal position just involves POKING a new position. However changing the vertical position requires you to remove the data from the old position and POKE the data into the new position. Atari BASIC is far too slow for this so a machine language subroutine is commonly used.
I decided to try a ML routine from Compute’s First Book of Atari Graphics, specifically the one that moves the player during the Vertical Blank Interrupt by Tom Sak and Sid Meier
.This is the primary part of the program, excluding the VBI routine code:
100 POKE 752,1:GRAPHICS 18:SETCOLOR 2,0,0:PRINT #6;" HAPPY HALLOWEEN"
110 PCOL0=66:PCOL1=PCOL0:REM COLOR OF PLAYERS
120 GOSUB 1000:REM INIT VBLANK ROUTINE
130 POKE PLL,14:POKE PLL+1,14:REM HEIGHT OF PLAYERS
140 POKE PLX,108:POKE PLY,102:REM PLAYER 0'S INITIAL POSITION
150 POKE PLX+1,116:POKE PLY+1,102:REM PLAYER 1'S INITIAL POSITION
160 REM MOVE PLAYERS TOGETHER
161 XPOS=100:YPOS=100
162 XDIFF=0:YDIFF=0
163 IF STICK(0)=11 THEN XDIFF=-4
164 IF STICK(0)=7 THEN XDIFF=4
165 IF STICK(0)=14 THEN YDIFF=-4
166 IF STICK(0)=13 THEN YDIFF=4
167 XPOS=XPOS+XDIFF:YPOS=YPOS+YDIFF
168 IF XPOS<38 THEN XPOS=38
169 IF XPOS>202 THEN XPOS=202
170 IF YPOS<12 THEN YPOS=12
171 IF YPOS>228 THEN YPOS=228
180 POKE PLX,XPOS:POKE PLX+1,XPOS+8
190 POKE PLY,YPOS:POKE PLY+1,YPOS
196 GOTO 162
The main thing to note here is that Player 0 and Player 1 are moved in combination (lines 180, 190) to create the larger pumpkin.
The end result looks like this:
Here is a snippet of the code that moves the players around:
Here’s a video showing it running along with a LISTing of the code:
Notice that the pumpkin does not quite move smoothly. Poor Atari BASIC is too slow for the separate POKES needed to move the two halves of the pumpkin to happen in a single vertical blank interrupt so sometimes the left half moves before the right half.
Running it in a faster BASIC, such BASIC XE is much smoother. BASIC XE also has built-in player/missile commands.
Next time we will look at starting to turn this into a “Pumpkin Man” game as we will draw some “candy” on the screen and have the pumpkin eat them when it moves over them. Note that I’ll be using BASIC XE for this going forward as its extra player/missile commands and other more advanced commands (such as line renumbering and procedures) should help make things a bit easier to read.
The full program is included on one of the many 8-bit disk images that are included as perks to Goto 10 paid subscribers.
Yes, the Sid Meier of Civilization fame!