Classic Computer Magazine Archive COMPUTE! ISSUE 65 / OCTOBER 1985 / PAGE 117

Programming the TI

C.Regena


Sprites In TI Extended BASIC

Since this month's COMPUTE! is a game issue, let me remind you that COMPUTE!'s First Book of TI Games is still available. It offers a variety of games that do not require TI Extended BASIC.
    Eventually, however, game programmers usually want the Extended BASIC command module because it adds several programming features, including up to 28 sprites (smoothly moving screen objects). With one statement you can define a sprite and set it in continuous motion. For example, try this short program:

100 REM TI EXTENDED BASIC
110 REM SPRITE DEMO
120 DEF R(X)=INT(X*RND)
130 CALL CLEAR
140 FOR S=1 TO 28 :: RAND
    OMIZE
150 CALL SPRITE(#S,64+S,R
    (15)+2,90,128,R(255)-
    127,R(255)-127)
160 NEXT S
170 GOTO 170
180 END

    This month's main program, "Sprite Tester," offers a way to test your sprites before putting them into a program of your own. After it displays a sprite on the screen, it lets you change various characteristics of the sprite by entering different numbers. You may experiment as much as you wish. When you have the sprite moving as you want, simply jot down the CALL SPRITE statement shown at the bottom of the screen.

Designing The Sprite
To get started, type in and run Sprite Tester. Choose a magnification factor from 1 to 4. (A regularsize character is magnification 1 and a four-times size is magnification 2. Magnification 3 is made up of four regular-size characters, and magnification 4 is four large characters.)
    Next choose a character number from 33 to 95-one of the characters from the regular ASCII character set. If you prefer to use your own graphic character, insert a CALL CHAR statement to redefine a character.
    You may then choose a sprite color. Since 1 is transparent (the screen color), you must choose a color number from 2 to 16. If you choose color 8, the screen changes so you'll be able to see the sprite. All other colors use the cyan background screen.
    Next choose a dot row and dot column position from which the sprite should start moving. Then, to move the sprite, select a row velocity and column velocity. Since these may be positive or negative numbers, first choose + or -, press ENTER, then pick the number and press ENTER again. If you want to experiment with the position of the sprite, keep the row velocity and column velocity at +0. Otherwise, the sprite will be in motion, and you may not be able to see the dot row and dot column changes.
    As you enter parameters, the CALL MAGNIFY and CALL SPRITE statements at the lower part of the screen show the sprite's present conditions. The program continues until you press FCTN-CLEAR.

Extended BASIC Features
Extended BASIC contains a number of statements which make programs such as Sprite Tester easier to write. The DISPLAY AT statements, for instance, allow you to print at a specified row and column. USING helps to format output, right-justifying numbers in this case.
    The ACCEPT statement is quite versatile for accepting input. BEEP sounds a tone when the computer is waiting for the input. AT() lets you receive the input starting at a certain row and column on the screen, and SIZE limits the input to a specified number of characters. VALIDATE allows you to specify what characters are acceptable as input. To erase or change before you press ENTER, you can press FCTN-ERASE. Unfortunately, if you enter something wrong, an error message appears and the printing on the screen starts to scroll. Afterward, the cursor may not be lined up with the original question.
    Unlike Console BASIC, Extended BASIC lets you follow THEN and ELSE in IF statements with either a line number or a command.
    The CALL SPRITE statement specifies the sprite number, the character number for the sprite, the foreground color, the beginning dot row and dot column positions, and the row velocity and column velocity.
    CALL MAGNIFY sets the magnification factor. You can change characteristics of the sprite either by using another CALL SPRITE statement or CALL PATTERN for the character number, CALL COLOR for color, and CALL MOTION for the velocities.
    If you prefer to save typing effort, you can obtain a copy of this program by sending a blank cassette or disk, a stamped, selfaddressed mailer, and $3 to:

C. Regena
P.O. Box 1502
Cedar City, UT 84720

Please be sure to specify that you want Sprite Tester.

100 REM TI EXTENDED BASIC
110 REM SPRITE TESTER
120 CALL CLEAR
130 CALL SCREEN(8)
140 CALL CHAR(96,"080402F
    F020408")
150 CALL COLOR(9,10,1)
160 CALL CHAR(95,"10107C1
    010007C")
170 CH=42
180 COLOR=2
190 DROW=96
200 DCOL=128
210 VROW=0
220 VCOL=0
230 M=1
240 CALL MAGNIFY(M)
250 DISPLAY AT(20,1):"CAL
    L MAGNIFY(1)"
260 DISPLAY AT(22,1):"CAL
    L SPRITE(#1,42, 2, 96
    ,{3 SPACES}128,
    {3 SPACES}0,
    {3 SPACES}0)"
270 CALL SPRITE(#1,CH,COL
    OR,DROW,DCOL,VROW,VCO
    L)
280 CALL HCHAR(1,3,96)
290 DISPLAY AT(1,2):"MAGN
    IFY 1-4:"
300 ACCEPT AT(1,16)VALIDA
    TE("1234")BEEP SIZE(1
    ):M
310 CALL MAGNIFY(M)
320 CALL HCHAR(20,16,M+48
    )
330 CALL HCHAR(1,3,32)
340 CALL HCHAR(3,3,96)
350 DISPLAY AT(3,2):"CHAR
    ACTER 33-95:"
360 ACCEPT AT(3,20)VALIDA
    TE(DIGIT)BEEP SIZE(2)
    :CH
370 IF (CH<33)+(CH>95)THE
    N 360
380 CALL PATTERN(#1,CH)
390 DISPLAY AT(22,16):USI
    NG "##":CH;
400 CALL HCHAR(3,3,32)
410 CALL HCHAR(5,3,96)
420 DISPLAY AT(5,2):"COLD
    R 2-16:"
430 ACCEPT AT(5,15)VALIDA
    TE(DIGIT)BEEP SIZE(2)
    :COLOR
440 IF (COLOR<2)+(COLOR>1
    6)THEN 430
450 IF COLOR<>8 THEN 480
460 CALL SCREEN(16)
470 GOTO 490
480 CALL SCREEN(8)
490 CALL COLOR(#1,COLOR)
500 DISPLAY AT(22,19):USI
    NG "##":COLOR;
510 CALL HCHAR(5,3,32)
520 CALL HCHAR(7,3,96)
530 DISPLAY AT(7,2):"DOT
    ROW 1-196:"
540 ACCEPT AT(7,18)VALIDA
    TE(DIGIT)BEEP SIZE(3)
    :DROW
550 IF (DROW<1)+(DROW>196
    )THEN 540
560 CALL SPRITE(#1,CH,COL
    OR,DROW,DCOL,VROW,VCO
    L)
570 DISPLAY AT(22,22):USI
    NG "###":DROW;
580 CALL HCHAR(7,3,32)
590 CALL HCHAR(9,3,96)
600 DISPLAY AT(9,2):"DOT
    COLUMN 1-256:"
610 ACCEPT AT(9,21)VALIDA
    TE(DIGIT)BEEP SIZE(3)
    :DCOL
620 IF (DCOL<1)+(DCOL>256
    )THEN 610
630 CALL SPRITE(#1,CH,COL
    OR,DROW,DCOL,VROW,VCO
    L)
640 DISPLAY AT(23,1):USIN
    G "###":DCOL;
650 CALL HCHAR(9,3,32)
660 CALL HCHAR(9,3,32)
670 CALL HCHAR(11,3,96)
680 DISPLAY AT(11,2):"ROW
     VELOCITY _127:  +"
690 ACCEPT AT(11,22)VALID
    ATE("+-")BEEP SIZE(1)
    :S$
700 ACCEPT AT(11,23)VALID
    ATE(DIGIT)SIZE(3):VRO
    W
710 IF VROW>127 THEN 680
720 IF S$="-" THEN VROW=-
    VROW
730 CALL MOTION(#1,VROW,V
    COL)
740 DISPLAY AT(23,5):USIN
    G "####":VROW;
750 CALL HCHAR(11,3,32)
760 CALL HCHAR(13,3,96)
770 DISPLAY AT(13,2):"COL
    UMN VELOCITY _127: +
    "
780 ACCEPT AT(13,25)VALID
    ATE("+-")BEEP SIZE(1)
    :S$
790 ACCEPT AT(13,26)VALID
    ATE(DIGIT)SIZE(3):VCO
    L
800 IF VCOL)127 THEN 770
810 IF S$="-" THEN VCOL=-
    VCOL
820 CALL MOTION(#1,VROW,V
    COL)
830 DISPLAY AT(23,10):USI
    NG "####":VCOL;
840 CALL HCHAR(13,3,32)
850 GOTO 280
860 END