'=========================================================================== ' Subject: VGA ANIMATION SPRITES Date: 7/11/92 (00:00:00) ' Author: Steve Gartrell Code: QB, QBasic ' Keys: VGA,ANIMATION,SPRITES Packet: GRAPHICS.ABC '=========================================================================== DEFINT A-Z DECLARE SUB NoBoxSprite (StartX%, StartY%, NumRows%, NumCols%, Sprite%()) CONST C$ = "Created 7/11/92 by Steve Gartrell. No rights reserved." 'this constant is the color you won't use. CONST NoColor% = 1 SCREEN 13 'VGA 320x200 pixels x 256 colors 'paint with color you don't want copied!! PAINT (10, 10), NoColor% 'Draw a sprite CIRCLE (165, 100), 9, 4 PAINT (165, 100), 90, 4 CIRCLE (165, 100), 8, 4, 0, 3.14 CIRCLE (165, 100), 9, 90, 3.14, 6.28 PSET (162, 99), 122 CIRCLE (162, 99), 3, 6 PSET (168, 99), 122 CIRCLE (168, 99), 3, 6 CIRCLE (165, 103), 3, 42, 3.43, 5.83 'Copy the sprite into an array... cell% = 0 DIM Sprite%(1 TO 441) FOR y% = 90 TO 110 FOR x% = 155 TO 175 cell% = cell% + 1 Sprite%(cell%) = POINT(x%, y%) NEXT NEXT 'Borrowed this random pattern generator from Rich Geldreich!! 'Modified to prohibit use of color 1 for demo purposes. FOR A = 1 TO 400 RANDOMIZE TIMER IF RND > .05 THEN LINE -(RND * 320, RND * 200), RND * 254 + 1 ELSE LINE -(RND * 320, RND * 200), RND * 254 + 1, BF END IF NEXT StartX% = 160: StartY% = 100 'There are actually 21 rows and 21 cols, ' but this makes it faster by eliminating ' some math!!! NumRows% = 20: NumCols% = 20 'First call initializes (places) sprite... CALL NoBoxSprite(StartX%, StartY%, NumRows%, NumCols%, Sprite%()) DO DO: t$ = UCASE$(INKEY$): LOOP UNTIL LEN(t$) SELECT CASE LEN(t$) CASE 2 SELECT CASE ASC(RIGHT$(t$, 1)) CASE &H48 ' 72d = UP StartY% = StartY% - 10 IF StartY% < 0 THEN StartY% = 180 CALL NoBoxSprite(StartX%, StartY%, NumRows%, NumCols%, Sprite%()) CASE &H50 ' 80d = DOWN StartY% = StartY% + 10 IF StartY% > 180 THEN StartY% = 0 CALL NoBoxSprite(StartX%, StartY%, NumRows%, NumCols%, Sprite%()) CASE &H4B ' 75d = LEFT StartX% = StartX% - 10 IF StartX% < 0 THEN StartX% = 300 CALL NoBoxSprite(StartX%, StartY%, NumRows%, NumCols%, Sprite%()) CASE &H4D ' 77d = RIGHT StartX% = StartX% + 10 IF StartX% > 300 THEN StartX% = 0 CALL NoBoxSprite(StartX%, StartY%, NumRows%, NumCols%, Sprite%()) CASE ELSE BEEP: BEEP END SELECT CASE ELSE IF t$ = "Q" THEN EXIT DO ELSE BEEP: BEEP END IF END SELECT LOOP ToggleY% = 1 ToggleX% = -1 DO StartY% = StartY% + ToggleY% IF StartY% < 1 OR StartY% > 179 THEN IF ToggleY% = -1 THEN ToggleY% = 1 ELSE ToggleY% = -1 END IF END IF StartX% = StartX% + ToggleX% IF StartX% < 1 OR StartX% > 299 THEN IF ToggleX% = -1 THEN ToggleX% = 1 ELSE ToggleX% = -1 END IF END IF CALL NoBoxSprite(StartX%, StartY%, NumRows%, NumCols%, Sprite%()) LOOP UNTIL LEN(INKEY$) SCREEN 0 WIDTH 80 COLOR 7, 0 END SUB NoBoxSprite (StartX%, StartY%, NumRows%, NumCols%, Sprite%()) 'Static definition means location of sprite known at ' start of routine if it was placed previously STATIC OldStartY&, OldEndY& 'Calculate vid mem offset address StartY& = StartY% * 320& + StartX% EndY& = StartY& + (NumRows% * 320&) + StartX% cell% = 1 'Vid mem segment in screen 13 DEF SEG = &HA000 WAIT &H3DA, 8, 8 'Wait till _start_ of vertical retrace WAIT &H3DA, 8 'Note that this FOR/NEXT won't execute if first call- ' since both sides of the FOR/NEXT = 0. After first ' call, it restores the background and retrieves the sprite! ' (Which means you can't overwrite the sprite, or it ' is saved in it's overwritten state!!) FOR y& = OldStartY& TO OldEndY& STEP 320 FOR Addr& = y& TO y& + NumCols% IF Sprite%(cell%) <> NoColor% THEN CurrentPix% = PEEK(Addr&) POKE Addr&, Sprite%(cell%) Sprite%(cell%) = CurrentPix% END IF cell% = cell% + 1 NEXT NEXT cell% = 1 WAIT &H3DA, 8, 8 WAIT &H3DA, 8 ' Place the sprite at the StartX%, StartY% location but ' ONLY AFTER storing the background!!! FOR y& = StartY& TO EndY& STEP 320 FOR Addr& = y& TO y& + NumCols% IF Sprite%(cell%) <> NoColor% THEN CurrentPix% = PEEK(Addr&) POKE Addr&, Sprite%(cell%) IF CurrentPix% = NoColor% THEN CurrentPix% = CurrentPix% + 256 END IF Sprite%(cell%) = CurrentPix% END IF cell% = cell% + 1 NEXT NEXT DEF SEG OldStartY& = StartY&: OldEndY& = EndY& END SUB