CLEAR ALL
PRINT "Press 'A' to add a sprite, 'Z' to remove a sprite, or Esc to quit."
top=256
num=0
DIM b(7)
FOR i=1 TO 7
    b(i)=FREE.BITMAP
    BITMAP b(i) LOAD "Floyd"+STR$(i)+".bmp"
NEXT i
DIM x(top),y(top)
DIM xs(top),ys(top)
s=1
addSprite()
DO
    LOCATE 1,3
    PRINT "Number of sprites: ";num;" "
    FOR i=1 TO num
        x(i)=x(i)+xs(i)
        y(i)=y(i)+ys(i)
        IF x(i)<0 OR x(i)>=1280 THEN xs(i)=-xs(i)
        IF y(i)<0 OR y(i)>=800 THEN ys(i)=-ys(i)
        SPRITE i MOVE x(i),y(i)
    NEXT i
    IF KEY.PRESSED(ASC("a")) THEN addSprite()
    IF KEY.PRESSED(ASC("z")) THEN removeSprite()
    IF KEY.PRESSED(27) THEN EXIT DO
    PAUSE
LOOP
END
FUNCTION addSprite()
    SHARE top,num,b(),s
    SHARE x(),y(),xs(),ys()
    IF num<top THEN
        i=num+1
        x(i)=RANGE(0,1279)
        y(i)=RANGE(0,799)
        xs(i)=RANGE(8,24)
        ys(i)=RANGE(8,24)
        SPRITE i BIND BITMAP b(s)
        s=s+1:IF s>7 THEN s=1
        SPRITE i SHOW MOVE x(i),y(i)
        num=i
    END IF
END FUNCTION
FUNCTION removeSprite()
    SHARE num
    IF num>1 THEN
        i=num
        SPRITE i HIDE
        num=num-1
    END IF
END FUNCTION
