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