home *** CD-ROM | disk | FTP | other *** search
- u
- J O Y S P R I T E
- PART II
- by Dave Moorman
-
-
- [ANIMATION]
- [---------]
-
- Sprites are just too much fun to
- be static. Not only should they move
- around the screen, the image should
- include motion -- walking, rolling,
- bouncing, flipping, whatever. So
- JoySprite adds Animation to the
- sprites Attributes.
-
- Animation is created by having a
- number of images, each slightly
- different that the previous. When
- flipped rapidly, the image seems to
- be alive. You must use your sprite
- editor software (SPRITE ON! is
- recommended) to draw consecutive
- animation images.
-
- Each sprite can have one
- animation sequence at a time. These
- are defined by the First Image# and
- the Last Image#.
-
- ANIMATION SET
- SYS AD+33 ,SP,S,F,L,SK,T
- where
- SP = Sprite Number
- S = Static Image#
- F = First Image #
- L = Last Image#
- SK = Skipped Jiffies between
- images
- T = Times animation sequences
- (0 = continuous)
-
- The Static Image is what is shown
- when the animation is stopped.
- Skipped Jiffies range from 1
- (fastest) to 255 (slowest). The
- animation can happen once (T = 1),
- Fifteen times (T = 15), or Forever (T
- = 0).
-
- Now all we need to do is turn the
- animation on or off.
-
-
- ANIMATION ON
- SYS AD+36 ,SP,OFF/ON
- where
- SP = Sprite Number
- OFF/OF = 0 - Off, 1 - On
-
- When the animation is turned off by
- this command or by having run the
- defined number of times, the Static
- Image is placed on the screen.
-
- [NOTE:] As with all IRQ driven
- effects, it is important to turn them
- off after use. Weird stuff can happen
- if ANIMATION, TIMER, GOSUBS, SPRITE
- MOVE or JOYSPRITE are left on.
-
-
- Again, we need to know what our
- Attributes are.
-
-
- ANIMATION ASK
- SYS AD+39,DIR
- where
- SP = Sprite Number
-
- The Attribute data is returned in
- the following integer variables:
-
- AS% - Static Image#
- AF% - First Image#
- AL% - Last Image#
- AK% - Jiffies Skipped
- AO% - Animation On (0-1)
-
- As with SPR.ASK, the variables
- return information for the sprite
- requested in the command.
-
-
- [JOYSTICK]
- [--------]
-
- JoySprite obviously needs
- Joystick functions! When you turn on
- the IRQ driver (IRQ.ON), two integer
- variables immediately begin returning
- information about the joystick:
-
- F% - Fire Button (0-Not, 1-Pressed)
- J% - Joystick Direction (0-8)
-
- The Joystick Direction is simplified
- by JoySprite to 8 directions, with 0
- being No Direction.
-
- 8 1 2
-
- 7 0 3
-
- 6 5 4
-
- The variables are automatically
- updated. If you want to use the
- joystick to move a menu bar, you
- could do something like this:
-
- LOOP IF T% = 1 THEN GOTO <BAR UP>
- IF T% = 5 THEN GOTO <BAR DOWN>
- GOTO LOOP
-
- Simple? You bet. But there is
- more! You can attach one sprite to
- the joystick, and animate it both
- while moving and while standing
- still. You must define the animation
- for each direction, 0-8.
-
- JOYSPRITE ANIMATE
- SYS AD+42 ,DR,SF,SL,SK,MF,ML,ST,W
- where
- DR = Direction of this animation
- SF = Standing First Image#
- SL = Standing Last Image#
- SK = Standing Jiffies Skipped
- MF = Move First Image#
- ML = Move Last Image#
- ST = Pixels Moved each Jiffy
- W = Wait # of Jiffies between
- Moves
-
- The animation works much like the
- ANI.SET command, but you can set the
- Standing animation for each
- direction. That way, if you have been
- moving to the right, the animation
- that begins when you release the
- joystick will be what is assigned for
- a "right facing" sprite.
-
- Movement is in pixels -- the
- greater ST, the faster the sprite
- will zip across the screen. However,
- I found that I needed to slow down
- the Joy Sprite to synchronize the
- animation with the movement. So W
- waits a number of Jiffies between
- moves. The moving sprite animates
- with each moved step.
-
- If you want to attach a sprite to
- the joystick and not have standing
- animation or moving animation, simply
- put the same Image# in each First and
- Last parameters.
-
- You may or may not want the Joy
- Sprite to move in all directions all
- the time. The JOY.DIR command uses
- bit-logic to tell the Joy Sprite
- which directions it can go.
-
- 128 1 2
-
- 64 0 4
-
- 32 16 8
-
- Just add up the values for the
- direction(s) in which you want the
- Joy Sprite to be able to move. If the
- Sprite can only move left or right,
- the byte would be 64+4.
-
-
- JOYSPRITE DIRECTION
- SYS AD+45 ,BYT
- where
- BYT = Bit-logic Directions
- Enabled
-
- Finally, we need to turn the Joy
- Sprite on and off.
-
-
- JOYSPRITE ON
- SYS AD+48 ,SP,OFF/ON
- where
- SP = Sprite Attached to Joystick
- OFF/ON = 0 - Off, 1 - On
-
- Note that the regular animation of
- the Joy Sprite is turned off when the
- Joy Sprite is enabled. You will have
- to manually turn the regular
- animation back on when the Joy Sprite
- is disabled.
-
- Now you have a moving, animated
- sprite connected to your joystick (in
- Port 2). What can you do with it?
-
- What [can't] you do with it?!
-
- As with the other Attributes, the
- Joy Sprite data is available as
- integer variables in BASIC by using
- this command:
-
-
- JOYSPRITE ASK
- SYS AD+51 , DR
- where
- DR = Direction information (0-8)
-
- The values are returned in the
- following integer variables:
-
- DR% = Direction Enable Byte
- JS% = Joy Sprite#
- SF% = Standing First Image#
- SL% = Standing Last Image#
- SK% = Standing Jiffies Skipped
- MF% = Moving First Image#
-
-
- [TIMERS]
- [------]
-
- We already have an IRQ driver
- going, clicking away 60 times a
- second. Wouldn't if be great to have
- a Jiffy countdown timer? Wouldn't it
- be even better to have [eight]
- countdown timers?
-
- I know, we all can do this:
-
- T=TI+120:FOR X=0 TO 1:
- X=-(TI>T):NEXT
-
- OK, you haven't used this two second
- timer. (X is reset to 0 by the
- comparison until TI, the Jiffy Time
- variable, is greater than T. As long
- as X is 0, the NEXT keeps on NEXTing.)
-
- But with JoySprite, you have
- eight independent countdown timers,
- with the results automatically
- reported in T% every Jiffy. T% is a
- bit-logic byte. When Timer0 goes off,
- T% will hold 1. When Timer1 is
- finished, T% will hold 2 (plus any
- other Timer bit).
-
- TIMER SET
- SYS AD+54 ,T#,TIME
- where
- T# is the Timer Number (0-7)
-
- This does [not] start the timer, just
- sets it. You start it with the next
- command.
-
-
- TIMER START
- SYS AD+57 ,T#
- where
- T# is the Timer Number (0-7)
-
- And stop it with this command:
-
- TIMER STOP
- SYS AD+60 , T#
- where
- T# is the Timer Number (0-7)
-
- After the Timer has gone off, you
- can clear the bit in T% with this:
-
- TIMER CLR
- SYS AD+63 ,T#
- where
- T# is the Timer Number (0-7)
-
- And if you want to start several
- timers at once, use the following to
- put a bit-logic byte into the Timer
- Enable byte.
-
- TIMER BYTE
- SYS AD+66 , TENABLE
- where
- TENABLE is the bit-logic byte to
- Enable any or all Timers (0-255)
-
- Let's consider the possibilities.
- I want to move a sprite to the left
- for one second. I might do something
- like this (assuming Sprite 3 is set
- up, enabled and on):
-
- SYS TIM.SET,0,60
- SYS TIM.START,0
- LOOP SYS SPR.ASK,3
- SYS SPR.AT,3,X%+1,Y
- IF T%=0 THEN LOOP
-
- Nifty, huh!
-
-
- [EVENT DRIVEN PROGRAMMING]
- [------------------------]
-
- Here is a new idea, taken from
- modern programming languages such as
- Visual BASIC -- Event Driven
- Programming. In Visual BASIC, one
- does not have to write a loop to
- constantly look at the joystick or
- fire button or timer. These processes
- run behind the scenes. When an even
- happens, the program GOSUBS to the
- Event Handling Routine the programmer
- writes.
-
- For JoySprite, I have included
- two Event Driven functions -- Timer0
- and Fire Button. Here are the
- commands:
-
-
- TIMER GOSUB
- SYS AD+69 , GOSUB,OFF/ON
- where
- GOSUB = Line Number of Subroutine
- OFF/ON = 0 - Off, 1 - On
-
-
- FIRE GOSUB
- SYS AD+72 , GOSUB,OFF/ON
- where
- GOSUB = Line Number of Subroutine
- OFF/ON = 0 - Off, 1 - On
-
- SPRITE-SPRITE GOSUB
- SYS AD+75 ,SP,GOSUB,OFF/ON
- Where
- SP = Sprite Number
- GOSUB = Line Number of Subroutine
- OFF/ON = 0 - Off, 1 - On
-
- When you use one of these
- commands, the GOSUB line number is
- tucked away, and JoySprite waits
- until Timer0 goes off (in TIM.GOSUB),
- the Fire Button is pressed (in
- FIRE.GOSUB), or sprite #SP has been
- touched by another sprite (in
- SPSP.GOSUB). When the event happens,
- BASIC finishes with whatever it is
- currently doing, then does a GOSUB on
- the spot to the line number you gave.
-
- In the Subroutine, you write the
- code that handles the event. Maybe a
- Fire makes your character do a karate
- chop. That would be programmed in the
- Subroutine. When RETURN is
- encountered, the program returns to
- where it left off.
-
- In order to avoid GOSUBs cutting
- into GOSUBs, the Event GOSUB function
- is turned off before going to the
- Event Handling Subroutine. You must
- turn it back on again. For a Fire
- Event or Sprite to Sprite Collision,
- just use the following command just
- before the RETURN:
-
-
- GOSUB ON
- SYS AD+78
-
- For a Timer0 Event, you must restart
- Timer0 if you want to repeat the
- process.
-
- 3000 REM HANDLE TIMER
- 3010 do whatever you need to do
- 3090 SYS TIM.SET,0,120
- 3091 SYS TIM.START,0
- 3093 SYS GOSUB.ON
- 3096 RETURN
-
-
- [DATA FILES]
- [----------]
-
- This module is getting to sound
- like an Infomercial -- "But wait!
- There's MORE!"
-
- Setting up all these Objects will
- require a lot of SYS commands.
- Wouldn't it be grand to have a way to
- save all the Attributes and load them
- into the program? Good News!
-
-
- SAVE
- SYS AD+81 "FILENAME",DV
-
- I am sure you fully understand
- this syntax. This command saves the
- Attribute data into a small file. You
- might want to give it a .DAT
- extension.
-
- After writing all the code that
- makes your program do what you want
- it to do, use the SAVE command to
- save the information. Then you can
- erase all the SYS commands, and add
- this command:
-
- LOAD
- SYS AD+84 "FILENAME",DV
-
- The information is loaded into
- your program in a snap. All that is
- left is enabling various things --
- and doing your program wishes.
-
-
- [LAST NOTE]
- [---------]
-
- After testing the program, I
- discovered that doing an IRQ OFF at
- the very beginning is a good idea.
- IRQ OFF does not affect anything for
- the IRQ driver which is not running.
- (It just sets a flag to 0.) But it
- also clears a flag that enables the
- ASK commands to find the integer
- variables. Call it a bit of good
- programming practice:
-
- 10 AD=4096:SYS AD+3
-
-
- What can you imagine? What can
- you do with JoySprite? This module
- turns the Joystick and Sprites into
- easy to handle objects, and gives you
- some never before seen capabilities.
- I am waiting to see what you do with
- it!
-
- DMM
-
-
-