Patch:Sphereful
Sphereful are globular, black, indestructible enemies found in Keen 5. Though slow moving they pose a hazard on higher difficulty levels due to their persistence.
Sprite Type
Sphereful use sprite type 22 which is used only by the Sphereful and doesn't affect anything else.
Keen 4
#Sphereful sprite type
%patch $1362C $16
Sprite Actions
The Sphereful is quite simple; it has a four action 'floating' cycle which is all it ever does.
Actions: $303AW #Sphereful 1 $3058W #Sphereful 2 $3076W #Sphereful 3 $3094W #Sphereful 4
Keen 5
#When spawned
%patch $13653 [$303AW]
#Floating cycle
%patch $33396 [$3058W]
%patch $333B4 [$3076W]
%patch $333D2 [$3094W]
%patch $333F0 [$303AW]
Sprite Behavior
The Sphereful always uses the same behavior, slowly seek Keen while floating, the only behavior it has.
Behaviors: $11C41A21RL #Slowly float towards Keen
Keen 5
#Sphereful behavior
%patch $3338A $11C41A21RL #Sphereful
%patch $333A8 $11C41A21RL #Sphereful
%patch $333C6 $11C41A21RL #Sphereful
%patch $333E4 $11C41A21RL #Sphereful
Speed and Jump Height
The Sphereful's motion is not a result of its animation and at present cannot be patched.
Animation motion
#Floating
%patch $33386 [$0000W $0000W]
%patch $333A4 [$0000W $0000W]
%patch $333C2 [$0000W $0000W]
%patch $333E0 [$0000W $0000W]
Sprite Collision
The Sphereful's sprite collision is a general one used by other sprites. it will kill Keen and block his shots.
Keen 5
#Sphereful sprite collision
%patch $3338E $11C40D61RL #Kill and block shots
%patch $333AC $11C40D61RL #Kill and block shots
%patch $333CA $11C40D61RL #Kill and block shots
%patch $333E8 $11C40D61RL #Kill and block shots
Animations
The Sphereful's main animation is easy enough to alter, it has four animations, one for each of its floating actions. However its secondary animations are more difficult, there are several 'diamonds' that orbit the Sphereful in a semi-random manner. These have a start animation and then use the next three frames. Setting this to $FFFCW will remove the secondary animations.
The final value, the one that controls the number of diamond frames is complex. For the 'usual' diamond movement pattern its value is 4d - 1. (So for the default four diamond frames this is 16-1 = 15 = $0F.) Each set of frames has four possible movement patterns. (So for example $04, $05, $06 and $07 all use two frames but different movement patterns.)
Keen 5
#Cache
%patch $31A34 [$0166W] #Sphereful cache start
%patch $31A88 [$016DW] #Cache end
#Sphereful float
%patch $3337A $0166W $0166W
%patch $33384 $0006W #Animation speed
%patch $33398 $0167W $0167W
%patch $333A2 $0006W #Animation speed
%patch $333B6 $0168W $0168W
%patch $333C0 $0006W #Animation speed
%patch $333D4 $0169W $0169W
%patch $333DE $0006W #Animation speed
#Diamonds, uses next 3 frames also
%patch $137C0 [$016AW]
#Diamond frames used
%patch $137B6 [$0F]
Diamond movement pattern
This variable controls how the diamonds move, in an unpredicatable manner. Experimenting with different values alters how the diamonds move.
Keen 5
#Diamond movement pattern
%patch $137E8 [$03]
Don't show Sphereful, only diamonds
This patch stops the Sphereful from being drawn and shows only the diamonds that orbit it. It will still bounce about as if the Sphereful were there.
Keen 5
#Don't show Sphereful, only diamonds
%patch $137A4 $90 $90 $90 $90 $90
Change number of diamonds
These patches change how many diamonds orbit the Sphereful. Andy number less than 4 can be used, including none. Use only one of these patches as they are mutually incompatible.
Keen 5
#Sphereful has...
%patch $13887 $5F $5E $8B $E5 $5D $CB #3 diamonds
%patch $1383C $5F $5E $8B $E5 $5D $CB #2 diamonds
%patch $13808 $5F $5E $8B $E5 $5D $CB #1 diamond
%patch $137AC $5F $5E $8B $E5 $5D $CB #No diamonds
Sprite positioning
The Sphereful spawns on tile above it's placement position, though this doesn't affect it much as a floating enemy.
Keen 5
#Sphereful spawn height
%patch $13648 [$FF00W] #1 tile up
Clipping and foreground
Only the Sphereful's foreground variable can be altered at the current time. There Sphereful appears in front of fore tiles, but not much else, by default. The Sphereful's clipping is set to 2 which can cause 'bad ObClass' problems when patching but is used by default to allow it to bounce off of tiles without seeming to touch them.
Keen 5
#Sphereful foreground variable
%patch $13650 $0001W
#Sphereful clipping variable
%patch $13631 $0002W
Sprite-tile interaction
The Sphereful has its own tile collision, that lets it bounce off walls, floors and ceilings, including slopes. It is also responsible for its 'secondary animations'.
Keen 5
#Sphereful tile collision
%patch $33392 $11C41AC4RL #Sphereful
%patch $333B0 $11C41AC4RL #Sphereful
%patch $333CE $11C41AC4RL #Sphereful
%patch $333EC $11C41AC4RL #Sphereful
Tile interaction code
This is the complete tile interaction code for the Sphereful. The first section is quite simple and deals with interacting with tiles. On the first and second lines the Sphereful looks for right and left walls. If found it makes a bouncing noise and reverses its horizontal direction.
At the end of line 3 ceilings are checked for, and if found, a bounce sound is played and the Sphereful's vertical direction reversed. On line 5 floors are checked for, and if found, something more complex happens; the Sphereful's vertical direction reverses, but it also gets an upwards 'kick' of either $FFFCW or $FFF4W depending on how fast down it was traveling. It then plays the floor bounce sound.
The remainder of the code deals with drawing the Sphereful and its diamonds and is quite complex, being made of a number of repetitions of a 'draw sprite' call. It is poorly understood at present. The first diamond animation is highlighted in blue.
Keen 5
#Sphereful tile collision code
%patch $13704 $55 $8B $EC $83 $EC $06 $56 $57 $8B $7E $06 $83 $7D {$3C} [$00] {$75}
$06 $83 $7D {$38} [$00] {$74} $14 $8B $45 $16 $F7 $D8 $89 $45 $16 $B8
[$003BW] $50 $9A $196E09EFRL $83 $C4 $02 $83 $7D {$3A} [$00] {$74}
$14 $8B $45 $18 $F7 $D8 $89 $45 $18 $B8 [$003BW] $50 $9A $196E09EFRL
$83 $C4 $02 $83 $7D {$36} [$00] {$74} $40 $8B $45 $18 $F7 $D8
$89 $45 $18 $8B $1E $3E $9E $8B $47 $0C $3B $45 $0C $73 $05 $FF
$4D $18 $EB $03 $FF $45 $18 $83 $7D $18 [$FC] {$7E} $07 $C7 $45 $18
[$FFFCW] $EB $0B $83 $7D $18 [$F4] {$7D} $05 $C7 $45 $18 [$FFF4W] $B8
[$0010W] $50 $9A $196E09EFRL $83 $C4 $02 $FF $75 $20 $33 $C0
$50 $FF $75 $1E $FF $75 $0C $FF $75 $0A $8B $C7 $05 $46 $00 $50
$9A $174E163ERL $83 $C4 $0C $A1 $B0 $9B $D1 $E8 $E8D1W $D1
$E8 $0F25W $00 $89 $46 $FE $D1 $E8 $E8D1W $05 [$016AW] $89 $46
$FC $83 $7E $FE $08 $72 $07 $C7 $46 $FA $0200W $EB $05 $C7 $46
$FA $0000W $FF $76 $FA $33 $C0 $50 $FF $76 $FC $8B $5E $FE $D1
%patch $137E4 $E3 $8B $45 $0C $03 $87 $B2 $30 $50 $8B $5E $FE $D1 $E3 $8B $45
$0A $03 $87 $B2 $30 $50 $8B $C7 $05 $3E $00 $50 $9A $174E163ERL
$83 $C4 $0C $FF $76 $FA $33 $C0 $50 $FF $76 $FC $8B $5E $FE
$D1 $E3 $8B $45 $0C $03 $87 $B2 $30 $50 $8B $5E $FE $D1 $E3 $8B
$45 $0A $05 $80 $01 $2B $87 $B2 $30 $50 $8B $C7 $05 $0040W $50
$9A $174E163ERL $83 $C4 $0C $83 $46 $FE $08 $83 $66 $FE $0F
$83 $7E $FE $08 $72 $07 $C7 $46 $FA $0200W $EB $05 $C7 $46 $FA
$0000W $FF $76 $FA $33 $C0 $50 $FF $76 $FC $8B $5E $FE $D1 $E3
$8B $45 $0C $03 $87 $B2 $30 $50 $8B $5E $FE $D1 $E3 $8B $45 $0A
$03 $87 $B2 $30 $50 $8B $C7 $05 $42 $00 $50 $9A $174E163ERL
$83 $C4 $0C $FF $76 $FA $33 $C0 $50 $FF $76 $FC $8B $5E $FE $D1
$E3 $8B $45 $0C $03 $87 $B2 $30 $50 $8B $5E $FE $D1 $E3 $8B $45
$0A $05 $80 $01 $2B $87 $B2 $30 $50 $8B $C7 $05 $44 $00 $50 $9A
$174E163ERL $83 $C4 $0C $5F $5E $8B $E5 $5D $CB
Action type
The Sphereful uses type 3 for its actions, allowing it to move smoothly and react instantly to Keen and objects.
Keen 5
#Sphereful action type
%patch $3337E [$0003W]
%patch $3339C [$0003W]
%patch $333BA [$0003W]
%patch $333D8 [$0003W]
Deprotect and stick to ground
The Sphereful has no use for either value, both of which are zero by default.
Keen 5
#Sphereful
%patch $33380 $0000W $0000W
%patch $3339E $0000W $0000W
%patch $333BC $0000W $0000W
%patch $333DA $0000W $0000W
Sounds
The Sphereful has three distinct sounds depending on whether it is bouncing off the walls, floor or ceiling.
Keen 5
#Sphereful sounds
%patch $13724 $3B #Sphereful hit walls
%patch $1373E $3B #Sphereful hit ceiling
%patch $13784 $10 #Sphereful hit floor
#Don't play Sphereful sounds
%patch $13723 $EB $0A #Sphereful hit walls
%patch $1373D $EB $0A #Sphereful hit ceiling
%patch $13783 $EB $0A #Sphereful hit floor
Sprite spawn code
Only partial spawn code is available for the Sphereful. Notice that there are three kinds of Sphereful; one for each difficulty. The Sphereful's cache is set in $C7 $06 $C287W $0001W
Keen 5
#Location of initiation code
%patch $F596 [$62DW] #Easy Sphereful (At $F37D)
%patch $F598 [$626W] #Normal Sphereful (At $F376)
%patch $F59A [$61FW] #Hard Sphereful (At $F36F)
#Sphereful Initiation code
%patch $F36F $83 $3E [$6F6CW] {$03 $7C} $31 $83 $3E [$6F6CW] {$02 $7C} $2A $57 $56
$9A {$11C419D8RL} $83 $C4 $04 $C7 $06 $C287W $0001W $EB $18