home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 229 / 229.d81 / t.js2 < prev    next >
Text File  |  2022-08-26  |  11KB  |  481 lines

  1. u
  2.           J O Y S P R I T E
  3.                PART II
  4.            by Dave Moorman
  5.  
  6.  
  7. [ANIMATION]
  8. [---------]
  9.  
  10.     Sprites are just too much fun to
  11. be static. Not only should they move
  12. around the screen, the image should
  13. include motion -- walking, rolling,
  14. bouncing, flipping, whatever. So
  15. JoySprite adds Animation to the
  16. sprites Attributes.
  17.  
  18.     Animation is created by having a
  19. number of images, each slightly
  20. different that the previous. When
  21. flipped rapidly, the image seems to
  22. be alive. You must use your sprite
  23. editor software (SPRITE ON! is
  24. recommended) to draw consecutive
  25. animation images.
  26.  
  27.     Each sprite can have one
  28. animation sequence at a time. These
  29. are defined by the First Image# and
  30. the Last Image#.
  31.  
  32. ANIMATION SET
  33.     SYS AD+33 ,SP,S,F,L,SK,T
  34.  where
  35.     SP = Sprite Number
  36.     S = Static Image#
  37.     F = First Image #
  38.     L = Last Image#
  39.     SK = Skipped Jiffies between
  40. images
  41.     T = Times animation sequences
  42.         (0 = continuous)
  43.  
  44.  The Static Image is what is shown
  45. when the animation is stopped.
  46. Skipped Jiffies range from 1
  47. (fastest) to 255 (slowest). The
  48. animation can happen once (T = 1),
  49. Fifteen times (T = 15), or Forever (T
  50. = 0).
  51.  
  52.     Now all we need to do is turn the
  53. animation on or off.
  54.  
  55.  
  56. ANIMATION ON
  57.     SYS AD+36 ,SP,OFF/ON
  58.  where
  59.     SP = Sprite Number
  60.     OFF/OF = 0 - Off, 1 - On
  61.  
  62.  When the animation is turned off by
  63. this command or by having run the
  64. defined number of times, the Static
  65. Image is placed on the screen.
  66.  
  67. [NOTE:] As with all IRQ driven
  68. effects, it is important to turn them
  69. off after use. Weird stuff can happen
  70. if ANIMATION, TIMER, GOSUBS, SPRITE
  71. MOVE or JOYSPRITE are left on.
  72.  
  73.  
  74.     Again, we need to know what our
  75. Attributes are.
  76.  
  77.  
  78. ANIMATION ASK
  79.     SYS AD+39,DIR
  80.  where
  81.     SP = Sprite Number
  82.  
  83.  The Attribute data is returned in
  84. the following integer variables:
  85.  
  86.   AS% - Static Image#
  87.   AF% - First Image#
  88.   AL% - Last Image#
  89.   AK% - Jiffies Skipped
  90.   AO% - Animation On (0-1)
  91.  
  92.  As with SPR.ASK, the variables
  93. return information for the sprite
  94. requested in the command.
  95.  
  96.  
  97. [JOYSTICK]
  98. [--------]
  99.  
  100.     JoySprite obviously needs
  101. Joystick functions! When you turn on
  102. the IRQ driver (IRQ.ON), two integer
  103. variables immediately begin returning
  104. information about the joystick:
  105.  
  106.   F% - Fire Button (0-Not, 1-Pressed)
  107.   J% - Joystick Direction (0-8)
  108.  
  109.  The Joystick Direction is simplified
  110. by JoySprite to 8 directions, with 0
  111. being No Direction.
  112.  
  113.             8  1  2
  114.  
  115.             7  0  3
  116.  
  117.             6  5  4
  118.  
  119.     The variables are automatically
  120. updated. If you want to use the
  121. joystick to move a menu bar, you
  122. could do something like this:
  123.  
  124.  LOOP IF T% = 1 THEN GOTO <BAR UP>
  125.       IF T% = 5 THEN GOTO <BAR DOWN>
  126.       GOTO LOOP
  127.  
  128.     Simple? You bet. But there is
  129. more! You can attach one sprite to
  130. the joystick, and animate it both
  131. while moving and while standing
  132. still. You must define the animation
  133. for each direction, 0-8.
  134.  
  135. JOYSPRITE ANIMATE
  136.     SYS AD+42 ,DR,SF,SL,SK,MF,ML,ST,W
  137.  where
  138.     DR = Direction of this animation
  139.     SF = Standing First Image#
  140.     SL = Standing Last Image#
  141.     SK = Standing Jiffies Skipped
  142.     MF = Move First Image#
  143.     ML = Move Last Image#
  144.     ST = Pixels Moved each Jiffy
  145.     W  = Wait # of Jiffies between
  146.             Moves
  147.  
  148.     The animation works much like the
  149. ANI.SET command, but you can set the
  150. Standing animation for each
  151. direction. That way, if you have been
  152. moving to the right, the animation
  153. that begins when you release the
  154. joystick will be what is assigned for
  155. a "right facing" sprite.
  156.  
  157.     Movement is in pixels -- the
  158. greater ST, the faster the sprite
  159. will zip across the screen. However,
  160. I found that I needed to slow down
  161. the Joy Sprite to synchronize the
  162. animation with the movement. So W
  163. waits a number of Jiffies between
  164. moves. The moving sprite animates
  165. with each moved step.
  166.  
  167.     If you want to attach a sprite to
  168. the joystick and not have standing
  169. animation or moving animation, simply
  170. put the same Image# in each First and
  171. Last parameters.
  172.  
  173.     You may or may not want the Joy
  174. Sprite to move in all directions all
  175. the time. The JOY.DIR command uses
  176. bit-logic to tell the Joy Sprite
  177. which directions it can go.
  178.  
  179.           128  1  2
  180.  
  181.            64  0  4
  182.  
  183.            32 16  8
  184.  
  185.  Just add up the values for the
  186. direction(s) in which you want the
  187. Joy Sprite to be able to move. If the
  188. Sprite can only move left or right,
  189. the byte would be 64+4.
  190.  
  191.  
  192. JOYSPRITE DIRECTION
  193.     SYS AD+45 ,BYT
  194.  where
  195.     BYT = Bit-logic Directions
  196.             Enabled
  197.  
  198.     Finally, we need to turn the Joy
  199. Sprite on and off.
  200.  
  201.  
  202. JOYSPRITE ON
  203.     SYS AD+48 ,SP,OFF/ON
  204.  where
  205.     SP = Sprite Attached to Joystick
  206.     OFF/ON = 0 - Off, 1 - On
  207.  
  208.  Note that the regular animation of
  209. the Joy Sprite is turned off when the
  210. Joy Sprite is enabled. You will have
  211. to manually turn the regular
  212. animation back on when the Joy Sprite
  213. is disabled.
  214.  
  215.     Now you have a moving, animated
  216. sprite connected to your joystick (in
  217. Port 2). What can you do with it?
  218.  
  219.     What [can't] you do with it?!
  220.  
  221.     As with the other Attributes, the
  222. Joy Sprite data is available as
  223. integer variables in BASIC by using
  224. this command:
  225.  
  226.  
  227. JOYSPRITE ASK
  228.     SYS AD+51 , DR
  229.  where
  230.     DR = Direction information (0-8)
  231.  
  232.  The values are returned in the
  233. following integer variables:
  234.  
  235.   DR% = Direction Enable Byte
  236.   JS% = Joy Sprite#
  237.   SF% = Standing First Image#
  238.   SL% = Standing Last Image#
  239.   SK% = Standing Jiffies Skipped
  240.   MF% = Moving First Image#
  241.  
  242.  
  243. [TIMERS]
  244. [------]
  245.  
  246.     We already have an IRQ driver
  247. going, clicking away 60 times a
  248. second. Wouldn't if be great to have
  249. a Jiffy countdown timer? Wouldn't it
  250. be even better to have [eight]
  251. countdown timers?
  252.  
  253.     I know, we all can do this:
  254.  
  255.  T=TI+120:FOR X=0 TO 1:
  256.  X=-(TI>T):NEXT
  257.  
  258.  OK, you haven't used this two second
  259. timer. (X is reset to 0 by the
  260. comparison until TI, the Jiffy Time
  261. variable, is greater than T. As long
  262. as X is 0, the NEXT keeps on NEXTing.)
  263.  
  264.     But with JoySprite, you have
  265. eight independent countdown timers,
  266. with the results automatically
  267. reported in T% every Jiffy. T% is a
  268. bit-logic byte. When Timer0 goes off,
  269. T% will hold 1. When Timer1 is
  270. finished, T% will hold 2 (plus any
  271. other Timer bit).
  272.  
  273. TIMER SET
  274.     SYS AD+54 ,T#,TIME
  275.  where
  276.     T# is the Timer Number (0-7)
  277.  
  278.  This does [not] start the timer, just
  279. sets it. You start it with the next
  280. command.
  281.  
  282.  
  283. TIMER START
  284.     SYS AD+57 ,T#
  285.  where
  286.     T# is the Timer Number (0-7)
  287.  
  288.  And stop it with this command:
  289.  
  290. TIMER STOP
  291. SYS AD+60 , T#
  292.  where
  293.     T# is the Timer Number (0-7)
  294.  
  295.     After the Timer has gone off, you
  296. can clear the bit in T% with this:
  297.  
  298. TIMER CLR
  299.     SYS AD+63 ,T#
  300.  where
  301.     T# is the Timer Number (0-7)
  302.  
  303.     And if you want to start several
  304. timers at once, use the following to
  305. put a bit-logic byte into the Timer
  306. Enable byte.
  307.  
  308. TIMER BYTE
  309.     SYS AD+66 , TENABLE
  310.  where
  311.     TENABLE is the bit-logic byte to
  312.       Enable any or all Timers (0-255)
  313.  
  314.     Let's consider the possibilities.
  315. I want to move a sprite to the left
  316. for one second. I might do something
  317. like this (assuming Sprite 3 is set
  318. up, enabled and on):
  319.  
  320.       SYS TIM.SET,0,60
  321.       SYS TIM.START,0
  322.  LOOP SYS SPR.ASK,3
  323.       SYS SPR.AT,3,X%+1,Y
  324.       IF T%=0 THEN LOOP
  325.  
  326.     Nifty, huh!
  327.  
  328.  
  329. [EVENT DRIVEN PROGRAMMING]
  330. [------------------------]
  331.  
  332.     Here is a new idea, taken from
  333. modern programming languages such as
  334. Visual BASIC -- Event Driven
  335. Programming. In Visual BASIC, one
  336. does not have to write a loop to
  337. constantly look at the joystick or
  338. fire button or timer. These processes
  339. run behind the scenes. When an even
  340. happens, the program GOSUBS to the
  341. Event Handling Routine the programmer
  342. writes.
  343.  
  344.     For JoySprite, I have included
  345. two Event Driven functions -- Timer0
  346. and Fire Button. Here are the
  347. commands:
  348.  
  349.  
  350. TIMER GOSUB
  351.     SYS AD+69 , GOSUB,OFF/ON
  352.  where
  353.     GOSUB = Line Number of Subroutine
  354.     OFF/ON = 0 - Off, 1 - On
  355.  
  356.  
  357. FIRE GOSUB
  358.     SYS AD+72 , GOSUB,OFF/ON
  359.  where
  360.     GOSUB = Line Number of Subroutine
  361.     OFF/ON = 0 - Off, 1 - On
  362.  
  363. SPRITE-SPRITE GOSUB
  364.     SYS AD+75 ,SP,GOSUB,OFF/ON
  365.  Where
  366.     SP = Sprite Number
  367.     GOSUB = Line Number of Subroutine
  368.     OFF/ON = 0 - Off, 1 - On
  369.  
  370.     When you use one of these
  371. commands, the GOSUB line number is
  372. tucked away, and JoySprite waits
  373. until Timer0 goes off (in TIM.GOSUB),
  374. the Fire Button