top of page
Search
Writer's pictureTom Grove

Flying Shark: Object Description

All object instances ( player, enemies, bullets, etc ) use the same type. This is a large - by eighties arcade game standards - struct of 29 bytes:

Some points of interest:


The objects are stored in a list rather than ( as was more common ) an array. Using a list allows objects to be added and removed ( to a free list ) with a constant time as opposed to a linear cost. The active list of objects is initialised with four dummy records: these serve as insertion points for different types of objects. These ensure that the list is sorted by object type so that when the objects are drawn, they are drawn in the correct order. That is, that objects on the ground are drawn before those in the air.


Making the link pointer the first field means that traversing a list using the stack is simple and cheap:


         LD         IY ,(ActiveObjects[3].Link )                                      
LAB_ram_bbf9                                   
         :
                  some code
	 :
         LD         SP ,IY         ; follow list next pointer
         POP        IY
         DJNZ       LAB_ram_bbf9

Object positions and velocities are represented as fixed point values. The particular choice of 8.5 is chosen to keep the character cell index ( e.g. 0-31 in X, 0-23 in Y ) inside the most significant byte, which helps with drawing. 5 bits of mantissa is more than enough precision for an arcade game.


To find the floor of this value is simple enough:

       LD         A,(IY +0xb )  ; LSB byte of position
       AND        0xe0		; clear fractional part
       OR         (IY +0xc )    ; OR in upper integer part from MSB
       RLCA	                ;  wrong way round, so 3 left rotates 
       RLCA
       RLCA

And to add to update position from velocity. By carefully laying out the fields, this can be accomplished elegantly using by once again using the stack:

AddVelocity     
        LD         (LAB_ram_ba1e+1 ),SP	; save the current SP
	LD         SP ,IY	; sp points to current object 
        LD         HL ,0x7	; offset to Fixed point Dx 
        ADD        HL ,SP	; adjust SP
        LD         SP ,HL
        POP        HL		; pop Dx
        POP        DE		; pop Dy
        POP        BC		; pop X	
        ADD        HL ,BC	; HL = X + Dx
        EX         DE ,HL	; store in DE
        POP        BC		; pop Y
        ADD        HL ,BC	; HL = Y + Dy
        PUSH       HL		; store Y back in object
        PUSH       DE		; store X back in object
 LAB_ram_ba1e+1                                 
        LD         SP ,0x0	; restore stack 
        AND        A
        RET

Some of the other fields:


SpriteData. Pointer to a structure holding the sprite size and image data.

Type. The object type. Used to select a tick routine.

FrameID. Animation frame id. Used to select which image the sprite will draw.

Speed and Orientation. Used to compute the object's velocity.

ActivationDelay. How long this object should continue to remain dormant.

WaveIndex. Index into an array of wave instances. This is the wave the object is part of ( or 0xff if the object is not part of a wave )

Script. Pointer to script opcodes.

CollisionMask. 8 flags indicating what the object has collided with.


Plus miscellaneous flags.


15 views0 comments

Recent Posts

See All

Flying Shark : Object Logic

Every object has a type field ( 0x5 ) that selects a tick routine. The tick routine for a bomb power-up is shown below (link to video)....

Comments


bottom of page