Back in September of ’84, SUM published my program that showed how to print a pattern on the screen that was not a slave of the 8×8 pixel dimension, but it only worked vertically. At the time it seemed impossible to do the same thing horizontally without doing an endless character creation session. It was not worth it.
At first I tried to poke the characters in real time to move the pattern right or left but it took too long. In order to move the pattern right or left rapidly, it is necessary to do the POKEing ahead of time. Lines 3000 to 3100 do this by setting up eight different character sets for the eight horizontal positions of the pixel pattern in the 8X8 character grid. This works because when you halve a binary number the pattern is preserved and shifted right one pixel. If an odd number is halved, that is the ones position is filled, that pixel is shifted two characters to the right. This shift is done by adding 128 to that character after its value has been halved. The first screen dump shows the eight USR character sets.
Notice in the sets there are blank characters between every two filled characters because the sprite is two characters high. If the sprite were three CHR$ high the pattern would be three CHR$ and then the blank. To move vertically, USR graphics location is poked. This makes the pixels move vertically within each CHR$ and from one character to the next. Characters next to each other in a character set are printed in a column on the screen.
The listing uses a non-standard character set for clarity. Where you see normal characters, that means that those are USR graphics characters. To move the saucer up or down, USR is changed by one. To move right and left, the start of USR characters is poked by 168 which shifts it one complete CHR$ set. Every eight shifts, horizontal or vertical, the printing position is changed and the USR CHR$ are reset to the start. Just for fun, by pressing either “L” or “R” an automatic movement takes place which can be stopped with “S”. The arrow keys move the saucer manually.
Sprites guzzle memory, but can make impressive animations. Try the following program and use it’s fundamental ideas for your own program. When you RUN the program, press enter when the characters stop forming. Happy saucering!
Products
Media
Image Gallery
Source Code
10 REM SPRITES
20 REM By John Monkus
30 REM 2-25-86
50 POKE 23675,X-256*INT (X/256): POKE 23676,INT (X/256): RETURN
990 BEEP .2,10
999 STOP
3000 REM Make CHR$ Sets
3010 LET X=65368: GO SUB 50: PRINT TAB 6;"ABCDEFGHIJKLMNOPQRSTU"
3020 FOR S=1 to 7: LET A=65352-168*S
3030 FOR A=A to A+15: DIM M(2,5): FOR I=1 TO 4: LET M=PEEK ((A+24*I)+168): LET M=M/2: IF M-INT M<>0 THEN LET M(2,I+1)=128: LET M=INT M
3040 LET M(1,I)=M+M(2,I): POKE A+24*I,M(1,I): NEXT I: NEXT A
3050 LET X=65368-168*S: GO SUB 50: PRINT TAB 5;"ABCDEFGHIJKLMNOPQRSTU"
3060 NEXT S: PRINT TAB 6;"ABCDEFGHIJKLMNOPQRSTU"
3100 PAUSE 0
8000 REM Move Sprite
8010 CLS: LET X=65368: GO SUB 50: LET SC=0
8020 PRINT AT 6,11; OVER 1;"BEH";AT 7,11;"CFI": LET C=6: LET T=14: LET V=0: LET H=4: GO TO 8090
8050 IF INKEY$="6" THEN LET V=V-1: IF V=-6 THEN LET V=2: LET C=C+1: IF C=20 THEN LET C=19: LET V=-5
8060 IF INKEY$="5" THEN LET H=H-1: IF H=-1 THEN LET H=6: LET T=T-1: IF T=-1 THEN LET T=0: LET H=0
8070 IF INKEY$="7" THEN LET V=V+1: IF V=4 THEN LET V=-4: LET C=C-1: IF C=-1 THEN LET C=0: LET V=3
8080 IF INKEY$="8" THEN LET H=H+1: IF H=8 THEN LET H=0: LET T=T+1: IF T=29 THEN LET T=28: LET H=7
8090 IF INKEY$="9" THEN GO TO 990
8100 IF INKEY$="s" THEN LET SC=0
8110 IF INKEY$="L" THEN LET SC=-1
8120 IF INKEY$="R" THEN LET SC=1
8130 IF SC=-1 THEN LET H=H-1: IF H=-1 THEN LET H=6: LET T=T-1: IF T=-1 THEN LET T=0: LET SC=0: LET H=0
8140 IF SC=1 THEN LET H=H+1: IF H=8 THEN LET H=0: LET T=T+1: IF T=29 THEN LET T=28: LET SC=-1: LET H=7
8190 LET X=65368-168*H+V: POKE 23675,X-256*INT (X/256): POKE 23676,INT (X/256)
8200 PRINT AT C,T;"BEHK";AT C+1,T;"CFIL";AT C+2,T;"DGJ "
8210 PRINT AT 0,6;"ABCDEFGHIJKLMNOPQRSTU";AT 1,5;"
ABCDEFGHIJKLMNOPQRSTU"
8220 GO TO 8030
8998 STOP
9000 REM USR CHR$
9010 POKE 23658,8: RESTORE: LET X=65368: GO SUB 50: FOR J=144 TO 156: FOR I=0 TO 7: READ C: POKE USR CHR$ J+I,C: NEXT I: NEXT J
9018 DATA 0,0,0,0,0,0,0,0
9020 DATA 0,0,0,0,3,3,15,63
9022 DATA 64,63,15,3,0,0,0,0
9026 DATA 0,0,0,0,0,0,0,0
9028 DATA 0,0,0,254,255,109,109,255
9030 DATA 0,255,255,255,254,0,0,0
9032 DATA 0,0,0,0,0,0,0,0
9034 DATA 0,0,0,0,128,128,224,248
9036 DATA 4,248,224,128,0,0,0,0
9038 DATA 0,0,0,0,0,0,0,0
9040 DATA 0,0,0,0,0,0,0,0
9042 DATA 0,0,0,0,0,0,0,0
9044 DATA 0,0,0,0,0,0,0,0
9100 GO TO 3000
9998 STOP
9999 SAVE "SPRITES" LINE 9000: VERIFY ""