No Box Sprites

Area:    Quik_Bas
  Msg:    #1581
 Date:    06-28-92 01:27 (Public) 
 From:    Steve Gartrell           
 To:      All                      
 Subject: No Box Sprites           
'You guessed it, I made a goof that didn't show up until
'I modified it to easily allow people to use color 0 if
'they wished.  Fixed it...Some day I just know I'm going
'to get it right the first time....|-}

DEFINT A-Z
DECLARE SUB NoBoxSprite (StartX%, StartY%, Sprite%())
CONST C$ = "Created 6/27/92 by Steve Gartrell.  No rights reserved."

'this constant is the color you won't use.
CONST NoColor% = 1

SCREEN 13

'paint with color you don't want copied!!
PAINT (10, 10), NoColor%

'Ain't nothing like a personalized example!! (What ego?)
'Draw a sprite (I've been called less flattering things!?)

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

cell% = 0

REDIM Sprite%(0 TO 441)
Sprite%(0) = 21        'make things easier-# of rows in cell 0
                       ' which is always EndY% - StartY% + 1!!!

'Copy the sprite into an array...

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

CALL NoBoxSprite(StartX%, StartY%, Sprite%())

DO
   DO: t$ = UCASE$(INKEY$): LOOP UNTIL LEN(t$)

   SELECT CASE LEN(t$)
      CASE 2
         SELECT CASE ASC(RIGHT$(t$, 1))
            CASE &H48                  ' 72
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
               StartY% = StartY% - 10  'UP
               IF StartY% < 0 THEN StartY% = 180
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
            CASE &H50                  ' 80
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
               StartY% = StartY% + 10  'DOWN
               IF StartY% > 180 THEN StartY% = 0
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
            CASE &H4B                  ' 75
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
               StartX% = StartX% - 10  'LEFT   (Down 10)
               IF StartX% < 0 THEN StartX% = 300
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
            CASE &H4D                  ' 77
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
               StartX% = StartX% + 10  'RIGHT
               IF StartX% > 300 THEN StartX% = 0
               CALL NoBoxSprite(StartX%, StartY%, Sprite%())
            CASE ELSE
               BEEP: BEEP
         END SELECT
      CASE ELSE
         IF t$ = "Q" THEN
            EXIT DO
         ELSE
            BEEP: BEEP
         END IF
   END SELECT

LOOP

SCREEN 0
WIDTH 80
COLOR 7, 0
END

SUB NoBoxSprite (StartX%, StartY%, Sprite%())

cell% = 1
NumCells% = UBOUND(Sprite%)
NumRows% = ABS(Sprite(0))
EndX% = StartX% + NumCells% \ NumRows% - 1
StartY& = StartY% * 320&
EndY& = StartY& + (NumRows% - 1) * 320&

'check sign to see if it's a sprite or a background

SELECT CASE Sprite%(0)
   CASE IS > 0
      FOR y& = StartY& TO EndY& STEP 320
         FOR x% = StartX% TO EndX%
            IF Sprite%(cell%) <> NoColor% THEN
               DEF SEG = &HA000
               addr& = y& + x%
               CurrentPix% = PEEK(addr&)
               POKE addr&, Sprite%(cell%)
               IF CurrentPix% = NoColor% THEN
                  CurrentPix% = -1
               END IF
               Sprite%(cell%) = CurrentPix%
               DEF SEG
            END IF
            cell% = cell% + 1
         NEXT
      NEXT
   CASE ELSE
      FOR y& = StartY& TO EndY& STEP 320
         FOR x% = StartX% TO EndX%
            IF Sprite%(cell%) <> NoColor% THEN
               IF Sprite%(cell%) < 0 THEN
                  Sprite(cell%) = NoColor%
               END IF
               DEF SEG = &HA000
               addr& = y& + x%
               CurrentPix% = PEEK(addr&)
               POKE addr&, Sprite%(cell%)
               Sprite%(cell%) = CurrentPix%
            END IF
            cell% = cell% + 1
         NEXT
      NEXT
END SELECT

'Toggle sign so know if it's the sprite, or the background
Sprite%(0) = Sprite%(0) * -1

END SUB


--- DB B1073/071082
 * Origin: RadioLink! Columbus, OH (614)766-2162 HST/DS (1:226/140)

Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET