home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_2 / issue_07 / spriteplot / SPRITE_TXT next >
Text File  |  1989-03-16  |  5KB  |  146 lines

  1. ANIMATED SPRITES
  2.  
  3. By Ian Smith
  4.  
  5. There have been many articles relating to the use of Sprites on the 
  6. Archimedes.  These have covered the use of PLOT &ED,X,Y to display a 
  7. Sprite in its defined colours at point (X,Y) and the use of a Mask to 
  8. allow a background to appear through the 'unused' parts of a sprite.  
  9. They have also shown the use of Exclusive OR plotting using GCOL 11,0 to 
  10. allow the sprite to be moved over any coloured background.
  11.  
  12. The EOR solution to this last problem, of moving a multi-coloured sprite 
  13. over a multicoloured background, works BUT unless a great deal of 
  14. thought is given to palette selection the sprite DOES NOT retain its 
  15. defined colour during movement.  
  16.  
  17. Many games will require the facility to define a sprite in specified 
  18. colours, with a mask, and to move it STILL retaining those colours 
  19. rather than those produced by EOR. 
  20.  
  21. A solution is to use the standard Move/Display/Erase in a loop BUT NOT 
  22. to use EOR. The following Algorithm does this :
  23.  
  24.  
  25.  1   Define the sprite 'MySprite' WITH a MASK (using SEDIT on the 
  26.      Welcome Disk).
  27.  
  28.  2   Determine the size of 'MySprite'.
  29.      This may be known BUT a SYS call does it for you.
  30.  
  31.  LOOP
  32.  
  33.      3   Determine the position where 'MySprite' is to be plotted.
  34.      
  35.      4   GRAB a sprite 'Temp' from the screen at this position the 
  36.          same size as 'MySprite'.
  37.  
  38.      5   PLOT 'MySprite' with the mask.
  39.  
  40.      6   PLOT the grabbed sprite 'Temp' to ERASE 'Mysprite'.
  41.  
  42.  ENDLOOP
  43.  
  44. The following program demonstrates this :
  45.  
  46.    10 REM > SpritePlot
  47.    20 REM  Copyright Ian Smith
  48.    30 REM  March 1989
  49.    40
  50.    50 REM An example program to show the use of sprites moving
  51.    60 REM across a multi coloured background by grabbing an area
  52.    70 REM of screen as a sprite and then using it to overwrite the
  53.    80 REM moving sprite.
  54.    90
  55.   100 MODE 15          : REM Works in others modes
  56.   110 T$="Temp"        : REM Will be the sprite grabbed from screen
  57.   120 M$="MySprite"    : REM A masked sprite created with SEDIT
  58.   130 *SLOAD !Sprites
  59.   140
  60.   150 SYS &2E,40,,T$ TO ,,,W,H   : REM Find size of sprite to grab
  61.   160                            : REM W)idth and H)eight
  62.   170 PROCDrawBackground         : REM Draw a Multicoloured background
  63.   180 PROCTitle                  : REM and put titles on
  64.   190
  65.   200 REPEAT
  66.   210   REM ****** MOVE ******
  67.   220   MOUSE X,Y,B
  68.   230   SYS &2E,16,,T$,1,X,Y,X+W*2,Y+H*4   : REM Grab sprite from screen
  69.   240
  70.   250   OSCLI("SCHOOSE " + M$ )  : REM Select original sprite
  71.   260
  72.   270   REM ****** DISPLAY ******
  73.   280   GCOL 8,0                 : REM Now plot it with its mask
  74.   290   PLOT &ED, X,Y            : REM at the mouse position
  75.   300   PLOT &ED,900,800         : REM and display it in rectangle
  76.   310
  77.   320   WAIT:WAIT                : REM Synchronise output
  78.   330
  79.   340   OSCLI("SCHOOSE " + T$)   : REM Now plot the grabbed sprite
  80.   350
  81.   360   REM ****** ERASE ******
  82.   370   GCOL 0,0
  83.   380   PLOT &ED,X,Y             : REM at the same place
  84.   390   PLOT &ED,1000,800        : REM and in its rectangle
  85.   400 UNTIL B=7                  : REM 3 buttons terminates
  86.   410 END
  87.   420
  88.   430 DEF PROCDrawBackground
  89.   440   GCOL 3 : RECTANGLE FILL 0,0,300,300      : REM Just a couple of
  90.   450   GCOL 4 : RECTANGLE FILL 50,50,50,50      : REM rectangles and
  91.   460   GCOL 12: CIRCLE FILL 800,400,200         : REM circle
  92.   470   GCOL 5 : CIRCLE FILL 600,300,100
  93.   480   OSCLI("SCHOOSE " +  M$)
  94.   490   PLOT &ED,75,90                           : REM and the sprite
  95.   500 ENDPROC
  96.   510
  97.   520 DEF PROCTitle
  98.   530   GCOL 1
  99.   540   RECTANGLE 900-2,800-4,W*2+4,H*4+8   : REM Draw rectangles
  100.   550   RECTANGLE 1000-2,800-4,W*2+4,H*4+8  : REM in which sprires
  101.   560   PRINT TAB(53,2);"S P R I T E S"     : REM are displayed
  102.   570   PRINT TAB(52,3);"original grabbed"
  103.   580   PRINT TAB(0,1);"SPRITE DEMONSTRATION : use mouse to move sprite"
  104.   590 ENDPROC
  105.  
  106.  
  107. Comments on the program :
  108.  
  109. PROCDrawBackgound sets up a background to move over.
  110. PROCTitle Simply puts Text and a couple of rectangles on the screen
  111.  
  112. 150 Uses a SYS call to find the Width and Height of 'MySprite'
  113.     This is needed so that the right size 'Temp' can be grabbed.
  114.     (See Programmers Reference Manual pp 429,433)
  115.  
  116. 230 Grabs the sprite from the screen using a SYS call.
  117.     Note the *2 and *4 to compensate for screen MODE 15
  118.     You'll need to change this for other resolution modes.
  119.  
  120. 250 Selects 'MySprite'
  121.  
  122. 280 Selects the Mask Plot option GCOL 8.
  123.  
  124. 290 Plots the sprite at the Mouse selected point
  125.  
  126. 300 Plots the sprite in a rectangle to show its original colours.
  127.  
  128. 340 Selects 'Temp'
  129.  
  130. 380 Plots 'Temp' effectively erasing 'MySprite'
  131.  
  132. 390 Plots 'Temp' in its rectangle.
  133.  
  134. The effect of 390 has an interesting side-effect.  
  135. When you run the program move the sprite over the rectangle ! See what 
  136. happens !
  137.  
  138. The program 'SpritePlot' and Sprite File '!Sprites' are on this month's 
  139. disk BUT you can use the program by keying it in AND ALSO CREATING A 
  140. MASKED SPRITE IN MODE 15 USING SEDIT SAVED AS !SPRITES.
  141.  
  142. The program can obviously be modified to run in other Modes.
  143. The flicker on the Sprite can be removed by modifying the program to 
  144. plot ONLY if the mouse has been moved.
  145.  
  146.