home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / UTILS / AMOSPRO4.DMS / in.adf / Tutorials / Computed_Sprites.AMOS / Computed_Sprites.amosSourceCode
Encoding:
AMOS Source Code  |  1992-09-28  |  5.3 KB  |  169 lines

  1. '*************************** 
  2. '*    AMOS Professional    * 
  3. '*                         * 
  4. '*    COMPUTED SPRITES     * 
  5. '*                         * 
  6. '* (c) Europress Software  * 
  7. '*                         * 
  8. '*     Ronnie Simpson      * 
  9. '*************************** 
  10. '
  11. '------------------- 
  12. 'GENERAL 
  13. '------------------- 
  14. 'The maximum of 8 hardware sprites would obviously be a big drawback, but
  15. 'AMOS Professional allows each of these sprites to be sliced into a number 
  16. 'of segments giving a set of 'computed sprites'. 
  17. 'The sprite numbers 0-7 are reserved for the individual hardware sprites so
  18. 'computed sprite numbers start from 8 upwards to a maximum of 63.
  19. '
  20. '------------------- 
  21. 'LIMITATIONS 
  22. '------------------- 
  23. 'Before you start using the computed sprites there are a number of   
  24. 'restrictions that you must be aware of. 
  25. '
  26. '1) The same width and colour restrictions of the hardware sprites apply 
  27. '   equally to computed sprites  ie. a maximum of 128 pixels wide in total 
  28. '   per horizontal line in the 3 colour mode or 64 pixels wide in the 15 
  29. '   colour mode. 
  30. '
  31. '2) Another unavoidable side effect is that a 1 pixel wide gap must be left
  32. '   between segments taken from any one hardware sprite. 
  33. '           +----------+ 
  34. 'eg.        | sprite 8 | 
  35. '           +----------+----------+ ----a 1 pixel gap must be left to
  36. '                      | sprite 9 |     avoid any overlap. 
  37. '                      +----------+  
  38. '
  39. '3) Computed sprites are managed by the software, so you never know exactly  
  40. '   which hardware sprite is being used to display your image. 
  41. '
  42. '4) The mouse pointer is normally used by hardware sprite 0, you will have 
  43. '   to free this with the Hide instruction if you wish to have the maximum 
  44. '   number of computed sprites.
  45. '
  46. 'If any of the above restrictions are ignored then no error will be  
  47. 'generated but it will result in the unexpected disappearance of some
  48. 'of the computed sprites from the screen.
  49. '
  50. '------------------- 
  51. 'OVERVIEW
  52. '------------------- 
  53. 'There are a total of 8 hardware sprites each 16 pixels wide by 255 high.
  54. '
  55. 'Each hardware sprite can be cut into slices which are controlled by the 
  56. 'software -these are the computed sprites. 
  57. '
  58. 'Each computed sprite taken from any one hardware sprite must be spaced
  59. 'on the screen with at least a 1 pixel gap between. (vertically) 
  60. '
  61. 'The same restrictions of hardware sprites of size and number of colours 
  62. 'apply to computed sprites.
  63. '
  64. 'Computed sprites joined or overlaid to increase size or number of colours 
  65. 'are managed by the system and require no further user control.
  66. '
  67. 'If restrictions on total width are exceeded then some computed sprites will 
  68. 'not be displayed. 
  69. '
  70. '------------------- 
  71. 'WIDTH RESTRICTIONS
  72. '------------------- 
  73. 'The formula for maximum width:- 
  74. '
  75. '1) Add together the maximum total width of all the 3 colour sprites that
  76. '   may have to share the same horizontal line.
  77. '
  78. '2) Do the same for your 15 colour sprites and double this value.
  79. '
  80. '3) Add together values from 1 and 2.
  81. '
  82. 'The total value must never be more than 128 pixels or this will result in 
  83. 'some sprites not being displayed. 
  84. '
  85. '------------------- 
  86. 'SPRITE UPDATES
  87. '------------------- 
  88. 'Normally whenever a sprite is moved the position is updated at the next 
  89. 'vertical blank. If a large number of sprites are being moved there may not
  90. 'be enough time to move them all 1/50th. of a second resulting 
  91. 'in a noticeable jump in the sprite movements. Under these circumstances it
  92. 'may become necessary to turn off the automatic updating with Sprite Update
  93. 'Off. Once the new sprite positions have all been calculated they can be 
  94. 'flicked into place with a call to Sprite Update.
  95. '
  96. 'eg.         Sprite Update Off 
  97. '            Do  
  98. '            Rem **** move all the sprites 
  99. '            Sprite Update 
  100. '            Loop  
  101. '
  102. 'The normal automatic system may be turned back on at any time with a single 
  103. 'call to Sprite Update On. 
  104. '
  105. '------------------- 
  106. 'WORKING EXAMPLE 
  107. '------------------- 
  108. Rem *** dimension arrays which hold coordinates and directions 
  109. '
  110. Dim X(63),Y(63),I(63)
  111. '
  112. '
  113. Rem *** load some sprite images
  114. '
  115. Load "AMOSPro_Tutorial:Objects/Sprites.abk"
  116. '
  117. '
  118. Rem *** set the palette and change the colour indexes 16 to 31 used by sprites 
  119. '
  120. Flash Off : Get Sprite Palette 
  121. Curs Off : Cls 0 : Hide 
  122. For N=15 To 28 Step 4
  123.    Colour N+1,0 : Colour N+2,$81F : Colour N+3,$FF0 : Colour N+4,$F00
  124. Next 
  125. '
  126. '
  127. Rem *** plot some stars and bars 
  128. '
  129. For N=1 To 100
  130.    X=Rnd(319) : Y=Rnd(199) : Plot X,Y
  131. Next 
  132. Ink 7
  133. For X=1 To 3
  134.    Bar X*70,180 To X*70+30,199
  135. Next 
  136. Pen 8 : Paper 0 : Centre "PRESS ANY MOUSE KEY TO QUIT"
  137. '
  138. '
  139. Rem *** set the start positions of compured sprites
  140. '
  141. For N=0 To 7
  142.    X(N+8)=N*25+150 : Y(N+8)=175 : I(N+8)=7
  143.    X(N+16)=N*25+150 : Y(N+16)=155 : I(N+16)=7
  144.    X(N+24)=N*25+150 : Y(N+24)=135 : I(N+24)=7
  145.    X(N+32)=N*25+150 : Y(N+32)=115 : I(N+32)=7
  146.    X(N+40)=N*25+150 : Y(N+40)=95 : I(N+40)=7
  147.    X(N+48)=N*25+150 : Y(N+48)=75 : I(N+48)=7
  148. Next 
  149. '
  150. '
  151. COUNT=8 : COUNTB=55
  152. Rem *** start main loop
  153. '
  154. DX=1
  155. Do 
  156.    If X(8)<128 or X(15)>434 Then DX=-DX
  157.    For N=8 To 55
  158.       If N=8 and I(COUNT)=7 and Rnd(3)=1 Then COUNT=Rnd(47)+8
  159.       If N=9 Then Add COUNTB,1,8 To 55 : Add I(COUNTB),1,7 To 8
  160.       If N mod 6=1 Then Add I(COUNT),1 : If I(COUNT)=12 Then I(COUNT)=7
  161.       Add X(N),DX
  162.       Sprite N,X(N),Y(N),I(N)
  163.    Next 
  164.    Exit If Mouse Key
  165. Loop 
  166. If N=8 Then Add COUNT,1,8 To 55 : Add I(COUNT),1,7 To 8
  167. '
  168. '
  169. Edit