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

  1. 06601010101800
  2. 1
  3. 2#
  4. F0110030
  5. 9[........................................................]001
  6. üANIMATEDSPRITESÇ
  7.  
  8. ByIanSmith
  9.  
  10. There have been many articles relating to the use of Sprites onthe
  11. Archimedes.ThesehavecoveredtheuseofPLOT&ED,X,Ytodisplaya
  12. Spriteinitsdefinedcoloursatpoint(X,Y)andtheuseofaMaskto
  13. allowabackgroundtoappearthroughthe'unused'partsofasprite.
  14. TheyhavealsoshowntheuseofExclusiveORplottingusingGCOL11,0to
  15. allowthespritetobemovedoveranycolouredbackground.
  16.  
  17. TheEORsolutiontothislastproblem,ofmovingamulti-colouredsprite
  18. overamulticolouredbackground,worksBUTunlessagreatdealof
  19. thoughtisgiventopaletteselectionthespriteDOESNOTretainits
  20. definedcolourduringmovement.
  21.  
  22. Manygameswillrequirethefacilitytodefineaspriteinspecified
  23. colours,withamask,andtomoveitSTILLretainingthosecolours
  24. ratherthanthoseproducedbyEOR.
  25.  
  26. AsolutionistousethestandardMove/Display/EraseinaloopBUTNOT
  27. touseEOR.ThefollowingAlgorithmdoesthis:
  28.  
  29.  
  30.  1   Definethesprite'MySprite'WITHaMASK(usingSEDITonthe
  31.      WelcomeDisk).
  32.  
  33.  2  Determinethesizeof'MySprite'.
  34.      ThismaybeknownBUTaSYScalldoesitforyou.
  35.  
  36. LOOP
  37.  
  38.  3   Determinethepositionwhere'MySprite'istobeplotted.
  39.      
  40.  4   GRABasprite'Temp'fromthescreenatthispositionthe
  41.      samesizeas'MySprite'.
  42.  
  43.  5   PLOT'MySprite'withthemask.
  44.  
  45. 6   PLOTthegrabbedsprite'Temp'toERASE'Mysprite'.
  46.  
  47. ENDLOOP
  48.  
  49. Thefollowingprogramdemonstratesthis:
  50. Ç
  51.    10 REM > SpritePlot
  52.    20 REM  Copyright Ian Smith
  53.    30 REM  March 1989
  54.    40
  55.    50 REM An example program to show the use of sprites moving
  56.    60 REM across a multi coloured background by grabbing an area
  57.    70 REM of screen as a sprite and then using it to overwrite the
  58.    80 REM moving sprite.
  59.    90
  60.   100 MODE 15          : REM Works in others modes
  61.   110 T$="Temp"        : REM Will be the sprite grabbed from screen
  62.   120 M$="MySprite"    : REM A masked sprite created with SEDIT
  63.   130 *SLOAD !Sprites
  64.   140
  65.   150 SYS &2E,40,,T$ TO ,,,W,H   : REM Find size of sprite to grab
  66.   160                            : REM W)idth and H)eight
  67.   170 PROCDrawBackground         : REM Draw a Multicoloured background
  68.   180 PROCTitle                  : REM and put titles on
  69.   190
  70.   200 REPEAT
  71.   210   REM ****** MOVE ******
  72.   220   MOUSE X,Y,B
  73.   230   SYS &2E,16,,T$,1,X,Y,X+W*2,Y+H*4   : REM Grab sprite from screen
  74.   240
  75.   250   OSCLI("SCHOOSE " + M$ )  : REM Select original sprite
  76.   260
  77.   270   REM ****** DISPLAY ******
  78.   280   GCOL 8,0                 : REM Now plot it with its mask
  79.   290   PLOT &ED, X,Y            : REM at the mouse position
  80.   300   PLOT &ED,900,800         : REM and display it in rectangle
  81.   310
  82.   320   WAIT:WAIT                : REM Synchronise output
  83.   330
  84.   340   OSCLI("SCHOOSE " + T$)   : REM Now plot the grabbed sprite
  85.   350
  86.   360   REM ****** ERASE ******
  87.   370   GCOL 0,0
  88.   380   PLOT &ED,X,Y             : REM at the same place
  89.   390   PLOT &ED,1000,800        : REM and in its rectangle
  90.   400 UNTIL B=7                  : REM 3 buttons terminates
  91.   410 END
  92.   420
  93.   430 DEF PROCDrawBackground
  94.   440   GCOL 3 : RECTANGLE FILL 0,0,300,300      : REM Just a couple of
  95.   450   GCOL 4 : RECTANGLE FILL 50,50,50,50      : REM rectangles and
  96.   460   GCOL 12: CIRCLE FILL 800,400,200         : REM circle
  97.   470   GCOL 5 : CIRCLE FILL 600,300,100
  98.   480   OSCLI("SCHOOSE " +  M$)
  99.   490   PLOT &ED,75,90                           : REM and the sprite
  100.   500 ENDPROC
  101.   510
  102.   520 DEF PROCTitle
  103.   530   GCOL 1
  104.   540   RECTANGLE 900-2,800-4,W*2+4,H*4+8   : REM Draw rectangles
  105.   550   RECTANGLE 1000-2,800-4,W*2+4,H*4+8  : REM in which sprires
  106.   560   PRINT TAB(53,2);"S P R I T E S"     : REM are displayed
  107.   570   PRINT TAB(52,3);"original grabbed"
  108.   580   PRINT TAB(0,1);"SPRITE DEMONSTRATION : use mouse to move sprite"
  109.   590 ENDPROC
  110.  
  111.  
  112. ÇCommentsontheprogram:
  113.  
  114. PROCDrawBackgoundsetsupabackgroundtomoveover.
  115. PROCTitleSimplyputsTextandacoupleofrectanglesonthescreen
  116.  
  117. 150UsesaSYScalltofindtheWidthandHeightof'MySprite'
  118. Thisisneededsothattherightsize'Temp'canbegrabbed.
  119.    (SeeProgrammersReferenceManualpp429,433)
  120. 
  121. 230GrabsthespritefromthescreenusingaSYScall.
  122. Notethe*2and*4tocompensateforscreenMODE15
  123. You'llneedtochangethisforotherresolutionmodes.
  124.  
  125. 250Selects'MySprite'
  126.  
  127. 280SelectstheMaskPlotoptionGCOL8.
  128.  
  129. 290PlotsthespriteattheMouseselectedpoint
  130.  
  131. 300Plotsthespriteinarectangletoshowitsoriginalcolours.
  132.  
  133. 340Selects'Temp'
  134.  
  135. 380Plots'Temp'effectivelyerasing'MySprite'
  136.  
  137. 390Plots'Temp'initsrectangle.
  138.  
  139. Theeffectof390hasaninterestingside-effect.
  140. Whenyouruntheprogrammovethespriteovertherectangle!Seewhat
  141. happens!
  142.  
  143. Theprogram'SpritePlot'andSpriteFile'!Sprites'areonthismonth's
  144. diskBUTyoucanusetheprogrambykeyingitinANDALSOCREATINGA
  145. MASKEDSPRITEINMODE15USINGSEDITSAVEDAS!SPRITES.
  146.  
  147. TheprogramcanobviouslybemodifiedtoruninotherModes.
  148. TheflickerontheSpritecanberemovedbymodifyingtheprogramto
  149. plotONLYifthemousehasbeenmoved.
  150.  
  151.