Patch:Sparky

From KeenWiki
Jump to navigation Jump to search

Sparkys are one of the most common enemies in Keen 5. They are black robotic creatures that charge keen when they see him.


Sprite Type

Sparky use type 9, which affects no other sprites and is used only by them.

Keen 5

#Sparky sprite type
%patch $11038 $09


Sprite Actions

The Sparky's actions are complex. It is spawned walking back and forth, and will randomly go to its 'look for Keen' cycle. If it meets walls or the edge of its platform, it will run its 'turn' cycle. (This happens whether it is walking or charging.)

While looking it will return to walking if Keen is not found, or prepare to charge him if he is. Charging Sparky will only stop (and turn) at platform edges or walls.

Turning Sparky resume walking. A sparky will spawn a shot Sparky when shot, which cannot be shot further.

Actions:
$1F0CW #Sparky walk 1
$1F2AW #Sparky walk 2
$1F48W #Sparky walk 3
$1F66W #Sparky walk 4
$1F84W #Sparky look 1
$1FA2W #Sparky look 2
$1FC0W #Sparky look 3
$1FDEW #Sparky look 4
$1FFCW #Sparky look 5
$201AW #Sparky look 6
$2038W #Sparky look 7
$2056W #Sparky look 8
$2074W #Sparky prepare to charge 1
$2092W #Sparky prepare to charge 2
$20B0W #Sparky prepare to charge 3
$20CEW #Sparky prepare to charge 4
$20ECW #Sparky charge 1
$210AW #Sparky charge 2
$2128W #Sparky charge 3
$2146W #Sparky charge 4
$2164W #Sparky turn 1
$2182W #Sparky turn 2
$21A0W #Sparky turn 3
$21BEW #Stunned Sparky

Keen 4

#Sparky placed in-level
%patch $11081 [$1F0CW] #Sparky Walk 1

#While walking
%patch $110A3 [$1F84W] #Sparky look for Keen (Random)

#At platform edges (walking or charging)
%patch $11234 [$2164W] #Sparky reaches edge of platform (Turn)

#While looking for Keen
%patch $110BD [$20ECW] #Sparky charge (After preparing to charge and Keen is present)
%patch $11005 [$2074W] #Sparky prepare to charge (Looking and sees Keen left)
%patch $11150 [$2074W] #Sparky prepare to charge (Looking and sees Keen right)

#Walk cycle
%patch $32268 [$1F2AW] #Sparky walk
%patch $32286 [$1F48W] #Sparky walk
%patch $322A4 [$1F66W] #Sparky walk
%patch $322C2 [$1F0CW] #Sparky walk

#Look cycle
%patch $322E0 [$1FA2W] #Sparky look
%patch $322FE [$1FC0W] #Sparky look
%patch $3231C [$1FDEW] #Sparky look
%patch $3233A [$1FFCW] #Sparky look
%patch $32358 [$201AW] #Sparky look
%patch $32376 [$2038W] #Sparky look
%patch $32394 [$2056W] #Sparky look
%patch $323B2 [$1F2AW] #Sparky look

#Prepare to charge cycle
%patch $323D0 [$2092W] #Sparky prepare to charge
%patch $323EE [$20B0W] #Sparky prepare to charge
%patch $3240C [$20CEW] #Sparky prepare to charge
%patch $3242A [$2074W] #Sparky prepare to charge

#Charge cycle
%patch $32448 [$210AW] #Sparky charge
%patch $32466 [$2128W] #Sparky charge
%patch $32484 [$2146W] #Sparky charge
%patch $324A2 [$20ECW] #Sparky charge

#Turn cycle
%patch $324C0 [$2182W] #Sparky turn
%patch $324DE [$21A0W] #Sparky turn
%patch $324FC [$1F0CW] #Sparky turn

#When shot
%patch $11196 [$21BEW] #Spawn stunned Sparky

#When stunned
%patch $3251A [$0000W] #Stunned Sparky


Sparky doesn't randomly look for Keen, charge him

This patch stops the Sparky randomly looking for Keen, this also stops it charging

Keen 4

#Sparky doesn't randomly look for Keen
%patch $1109E $EB


Sprite Behavior

The Sparky has no less than six different behaviors. The first, its 'walk' behavior is used during only one frame of its walk cycle. It is only this frame that randomly pauses to look for Keen. Making all four frames use this behavior will quadruple the average searching rate of the Sparky.

The two look behaviors are likewise used only for one frame each when the Sparky is looking for Keen. Each one only checks one side of the screen for Keen. (Meaning if Keen is very fast and very lucky he can jump over a searching Sparky, land in front of it and still not be seen.)

The start charging behavior is used likewise only just before the Sparky charges. The two charging behaviors (Whose function is unknown) are only used for one frame each of the four frame charging loop, again for unknown reasons. The stunned Sparky uses a generic stunned behavior.

Behaviors:
$1102006FRL #Sparky walk (Randomly Sparky look for Keen)
$1102008ERL #Sparky start charging
$110200A2RL #Sparky look left
$110200EFRL #Sparky look right
$1102013CRL #Sparky charge 1
$1102014CRL #Sparky charge 2

Keen 5 Sparky behaviors

#Walk
%patch $3225C $1102006FRL #Sparky walk
%patch $3227A $00000000L  #Nothing
%patch $32298 $00000000L  #Nothing
%patch $322B6 $00000000L  #Nothing

#Look for Keen
%patch $322D4 $00000000L  #Nothing
%patch $322F2 $00000000L  #Nothing
%patch $32310 $00000000L  #Nothing
%patch $3232E $110200A2RL #Sparky look left
%patch $3234C $00000000L  #Nothing
%patch $3236A $00000000L  #Nothing
%patch $32388 $00000000L  #Nothing
%patch $323A6 $110200EFRL #Sparky look right

#Start charging (Zzzt!)
%patch $323C4 $00000000L  #Nothing
%patch $323E2 $00000000L  #Nothing
%patch $32400 $00000000L  #Nothing
%patch $3241E $1102008ERL #Sparky start charging

#Charge
%patch $3243C $00000000L  #Nothing
%patch $3245A $1102013CRL #Sparky charge 1
%patch $32478 $00000000L  #Nothing
%patch $32496 $1102014CRL #Sparky charge 2

#Turn
%patch $324B4 $00000000L  #Nothing
%patch $324D2 $00000000L  #Nothing
%patch $324F0 $00000000L  #Nothing

#Stunned
%patch $3250E $090B1710RL #Fall


Sparky walk behavior code

This is the complete code for the Sparky walking behavior. It can be seen to be quite simple; it merely randomly changes the Sparky's action to 'search for Keen' The random check is in line 1 and the action change in line 2.

Sparky walk behavior code

#Sparky walk behavior code
%patch $1108F $55 $8B $EC $56 $8B $76 $06 $9A $1DFB0036RL     $3D [$0040W]  {$7D}
              $0B $C7 $44 $1C [$1F84W]  $C7 $06 $85 $BF [$0000W]  $5E $5D $CB


Sparky search behavior code

This is the complete behavior code for the Sparky searching for Keen left\right. On the first line of the first patch the Sparky checks to see whether Keen is vertically 1-2 tiles above the sparky. (That is, the top of keen's head is $0100W units or $10 pixels or 1 tile or less above the top of the Sparky.)

On the end of the second line Keen's vertical position is again checked. On the third line the Sparky checks to see if Keen is horizontally left of the Sparky (That is, in 'front' of the Sparky when it is looking left.) If not, nothing happens.

If so however the sparky changes its horizontal direction to left (-1) and plays sound $3A. It also changes its action to a charging Sparky and its misc variable to 3 (for unknown reasons.)

The second patch is for searching right. This is nearly identical to the first patch with some directions reversed.

Keen 5

#Sparky look left behavior code
%patch $110C2 $55 $8B $EC $83 $EC $02 $56 $8B $76 $06 $8B $1E $3E $9E $8B $47
              $28 $05 [$0100W]  $2B $44 $28 $89 $46 $FE $81 $7E $FE [$0200W]  $77
              $27 $8B $1E $3E $9E $8B $47 $0A $3B $44 $0A $73 $1B $C7 $44 $0E
              [$FFFFW]  $B8 [$003AW]  $50 $9A $196E09EFRL     $83 $C4 $02 $C7 $44
              $1C [$2074W]  $C7 $44 $3E [$0003W]  $5E $8B $E5 $5D $CB

Keen 5

#Sparky look right behavior code
%patch $1110F $55 $8B $EC $83 $EC $02 $56 $8B $76 $06 $8B $1E $3E $9E $8B $47
              $28 $05 [$0100W]  $2B $44 $28 $89 $46 $FE $81 $7E $FE [$0200W]  $77
              $27 $8B $1E $3E $9E $8B $47 $0A $3B $44 $0A $76 $1B $C7 $44 $0E
              [$0001W]  $B8 [$003AW]  $50 $9A $196E09EFRL     $83 $C4 $02 $C7 $44
              $1C [$2074W] $C7 $44 $3E [$0003W]  $5E $8B $E5 $5D $CB


Speed and Jump Height

The Sparky's speed is entirely defined by its animation motion. Notice the Sparky's walk and charge speeds are the same, but the charge speed is affected by its animation speed, which is twice as short when charging. (See section below.)

Animation motion

#Sparky walk
%patch $32258 [$0080W $0000W]
%patch $32276 [$0080W $0000W]
%patch $32294 [$0080W $0000W]
%patch $322B2 [$0080W $0000W]

#Look
%patch $322D0 [$0000W $0000W]
%patch $322EE [$0000W $0000W]
%patch $3230C [$0000W $0000W]
%patch $3232A [$0000W $0000W]
%patch $32348 [$0000W $0000W]
%patch $32366 [$0000W $0000W]
%patch $32384 [$0000W $0000W]
%patch $323A2 [$0000W $0000W]

#Prepare to charge
%patch $323C0 [$0000W $0000W]
%patch $323DE [$0000W $0000W]
%patch $323FC [$0000W $0000W]
%patch $3241A [$0000W $0000W]

#Charge
%patch $32438 [$0080W $0000W]
%patch $32456 [$0080W $0000W]
%patch $32474 [$0080W $0000W]
%patch $32492 [$0080W $0000W]

#Turn
%patch $324B0 [$0000W $0000W]
%patch $324CE [$0000W $0000W]
%patch $324EC [$0000W $0000W]

#Stunned
%patch $3250A [$0000W $0000W]


Sprite Collision

The Sparky is deadly to touch, but can be brought down with a single shot from Keen. This makes its collision quite simple.


Collision values

All of the Sparky's actions use the same collision, except its stunned action. This is to be expected.

Keen 5 collision values

#Walk
%patch $32260 $1102015CRL #Sparky
%patch $3227E $1102015CRL #Sparky
%patch $3229C $1102015CRL #Sparky
%patch $322BA $1102015CRL #Sparky

#Look
%patch $322D8 $1102015CRL #Sparky
%patch $322F6 $1102015CRL #Sparky
%patch $32314 $1102015CRL #Sparky
%patch $32332 $1102015CRL #Sparky
%patch $32350 $1102015CRL #Sparky
%patch $3236E $1102015CRL #Sparky
%patch $3238C $1102015CRL #Sparky
%patch $323AA $1102015CRL #Sparky

#Prepare to charge
%patch $323C8 $1102015CRL #Sparky
%patch $323E6 $1102015CRL #Sparky
%patch $32404 $1102015CRL #Sparky
%patch $32422 $1102015CRL #Sparky

#Charge
%patch $32440 $1102015CRL #Sparky
%patch $3245E $1102015CRL #Sparky
%patch $3247C $1102015CRL #Sparky
%patch $3249A $1102015CRL #Sparky

#Turn
%patch $324B8 $1102015CRL #Sparky
%patch $324D6 $1102015CRL #Sparky
%patch $324F4 $1102015CRL #Sparky

#Stunned
%patch $32512 $00000000L  #Nothing


Collision code

This is the complete collision code for the landed Sparky. It responds to two sprite types, Keen, and his shot. If Keen is detected, he is killed. If the shot is detected, it is destroyed and the Sparky stunned.

Keen 5

#Sparky sprite collision
%patch $1117C $55 $8B $EC $56 $8B $76 $08 $83 $3C [$02] {$75 $08} $9A $0AAF1517RL #Check for Keen, if yes, kill
                      $5E $5D $CB $83 $3C [$03] {$75 $10} $B8 [$21BEW]  $50 $56 $FF #Check for Keen shot, if yes, stun
                  $76 $06 $9A $090B16CDRL     $83 $C4 $06 $5E $5D $CB


Animations

The Sparky's animations are complex and interesting. It has a four frame walking cycle. This uses exactly animations as the four frame charging cycle (Which moves faster) and the four frame 'preparing to charge' cycle. (Which stands still.)

The Sparky also has a two frame turning animation for when it must turn around and a one frame stunned cycle. It also has a complex eight frame 'look for Keen' cycle. This is expected for the most commonly seen enemies in the game.

Notice the Sparky's walk and charge speeds are the same, but the charge speed is affected by its animation speed, which is twice as short when charging.

Keen 5

#Sparky walk
%patch $3224C $0170W $0177W #Sparky walk
%patch $32256 $0008W        #Animation speed
%patch $3226A $0171W $0178W #Sparky walk
%patch $32274 $0008W        #Animation speed
%patch $32288 $0170W $0177W #Sparky walk
%patch $32292 $0008W        #Animation speed
%patch $322A6 $0171W $0178W #Sparky walk
%patch $322B0 $0008W        #Animation speed

#Sparky look
%patch $322C4 $0172W $0172W #Sparky look
%patch $322CE $0006W        #Animation speed
%patch $322E2 $0173W $0173W #Sparky look
%patch $322EC $0006W        #Animation speed
%patch $32300 $0174W $0174W #Sparky look
%patch $3230A $0006W        #Animation speed
%patch $3231E $0175W $0175W #Sparky look
%patch $32328 $0006W        #Animation speed
%patch $3233C $0174W $0174W #Sparky look
%patch $32346 $0006W        #Animation speed
%patch $3235A $0173W $0174W #Sparky look
%patch $32364 $0006W        #Animation speed
%patch $32378 $0172W $0174W #Sparky look
%patch $32382 $0006W        #Animation speed
%patch $32396 $016EW $0175W #Sparky look
%patch $323A0 $0006W        #Animation speed

#Sparky prepare to charge
%patch $323B4 $016EW $0175W #Sparky prepare to charge
%patch $323BE $0004W        #Animation speed
%patch $323D2 $016FW $0176W #Sparky prepare to charge
%patch $323DC $0004W        #Animation speed
%patch $323F0 $0170W $0177W #Sparky prepare to charge
%patch $323FA $0004W        #Animation speed
%patch $3240E $0171W $0178W #Sparky prepare to charge
%patch $32418 $0004W        #Animation speed

#Sparky charge
%patch $3242C $016EW $0175W #Sparky charge
%patch $32436 $0004W        #Animation speed
%patch $3244A $016FW $0176W #Sparky charge
%patch $32454 $0004W        #Animation speed
%patch $32468 $0170W $0177W #Sparky charge
%patch $32472 $0004W        #Animation speed
%patch $32486 $0171W $0178W #Sparky charge
%patch $32490 $0004W        #Animation speed

#Sparky turn
%patch $324A4 $0174W $0172W #Sparky turn
%patch $324AE $0008W        #Animation speed
%patch $324C2 $0173W $0173W #Sparky turn
%patch $324CC $0008W        #Animation speed
%patch $324E0 $0172W $0174W #Sparky turn
%patch $324EA $0008W        #Animation speed

#Stunned Sparky
%patch $324FE $0179W $0179W ##Stunned Sparky
%patch $32508 $0000W        #Animation speed


Sounds

There are two, identical sounds played by the Sparky. Both are played when the Sparky looks for, and sees Keen, but each is played when it sees Keen in a different direction.

Keen 5

#Sparky sounds
%patch $110F5 $3A #Sparky see Keen left sound
%patch $11142 $3A #Sparky see Keen right sound

#Don't play Sparky sounds
%patch $110F4 $EB $0A #Don't play Sparky see Keen left sound
%patch $11141 $EB $0A #Don't play Sparky see Keen right sound


Sprite positioning

The Sparky spawns 1 tile higher than where it is placed, needed to ensure that it is level with the ground. This is very important and the Sparky will need this value changed if its sprite height is changed/

Keen 5

#Spawn height
%patch $11054 $FF00W #1 tile up


Clipping and foreground

The Sparky has a foreground variable of 0, meaning it appears behind all sprites and foreground tiles. This fits its role as the unobtrusive most common enemy.

Sparky foreground variable

#Sparky foreground variable
%patch $11042 $0000W


Sprite-tile interaction

The Sparky has its own special tile collision, used when it walks and charges, as well as when preparing to charge. The Sparky uses a general 'stay out of solid tiles' collision when looking (except oddly, for two frames) and turning. The stunned Sparky uses a generic stunned sprite collision.

Keen 5

#Walk
%patch $32264 $11020188RL #Sparky
%patch $32282 $11020188RL #Sparky
%patch $322A0 $11020188RL #Sparky
%patch $322BE $11020188RL #Sparky

#Look
%patch $322DC $090B17B5RL #Solid
%patch $322FA $090B17B5RL #Solid
%patch $32318 $090B17B5RL #Solid
%patch $32336 $11020188RL #Sparky
%patch $32354 $090B17B5RL #Solid
%patch $32372 $090B17B5RL #Solid
%patch $32390 $090B17B5RL #Solid
%patch $323AE $11020188RL #Sparky

#Prepare to charge
%patch $323CC $11020188RL #Sparky
%patch $323EA $11020188RL #Sparky
%patch $32408 $11020188RL #Sparky
%patch $32426 $11020188RL #Sparky

#Charge
%patch $32444 $11020188RL #Sparky
%patch $32462 $11020188RL #Sparky
%patch $32480 $11020188RL #Sparky
%patch $3249E $11020188RL #Sparky

#Turn
%patch $324BC $090B17B5RL #Solid
%patch $324DA $090B17B5RL #Solid
%patch $324F8 $090B17B5RL #Solid

#Stunned
%patch $32516 $090B195ARL #Stunned


Action type

The Sparky uses type 0 for all of its actions, which means its motion is technically jerky, though this is hard to see. The stunned Sparky of course uses type 2, as do all stunned sprites.

Keen 5 Motion

#Walk
%patch $32250 [$0000W]
%patch $3226E [$0000W]
%patch $3228C [$0000W]
%patch $322AA [$0000W]

#Look
%patch $322C8 [$0000W]
%patch $322E6 [$0000W]
%patch $32304 [$0000W]
%patch $32322 [$0000W]
%patch $32340 [$0000W]
%patch $3235E [$0000W]
%patch $3237C [$0000W]
%patch $3239A [$0000W]

#Prepare to charge
%patch $323B8 [$0000W]
%patch $323D6 [$0000W]
%patch $323F4 [$0000W]
%patch $32412 [$0000W]

#Charge
%patch $32430 [$0000W]
%patch $3244E [$0000W]
%patch $3246C [$0000W]
%patch $3248A [$0000W]

#Turn
%patch $324A8 [$0000W]
%patch $324C6 [$0000W]
%patch $324E4 [$0000W]

#Stunned
%patch $32502 [$0002W]


Deprotect and stick to ground

Sparky use a value of 1 for their 'stick to ground' variables, because they must move up and down hills. The only exception to this is the stunned Sparky. The preparing to charge and charging Sparky also use the deprotect animation variable, though this does not seem to have any specific effect.

Keen 5

#Walk
%patch $32252 [$0000W $0001W]
%patch $32270 [$0000W $0001W]
%patch $3228E [$0000W $0001W]
%patch $322AC [$0000W $0001W]

#Look
%patch $322CA [$0000W $0001W]
%patch $322E8 [$0000W $0001W]
%patch $32306 [$0000W $0001W]
%patch $32324 [$0000W $0001W]
%patch $32342 [$0000W $0001W]
%patch $32360 [$0000W $0001W]
%patch $3237E [$0000W $0001W]
%patch $3239C [$0000W $0001W]

#Prepare to charge
%patch $323BA [$0001W $0001W]
%patch $323D8 [$0001W $0001W]
%patch $323F6 [$0001W $0001W]
%patch $32414 [$0001W $0001W]

#Charge
%patch $32432 [$0001W $0001W]
%patch $32450 [$0001W $0001W]
%patch $3246E [$0001W $0001W]
%patch $3248C [$0001W $0001W]

#Turn
%patch $324AA [$0000W $0001W]
%patch $324C8 [$0000W $0001W]
%patch $324E6 [$0000W $0001W]

#Stunned
%patch $32504 [$0000W $0000W]


Probability and randomness

This patch controls how often the Sparky randomly looks for Keen, this also affects how often it goes to charging.

Keen 5

#Frequency of searching
%patch $1109C [$0040W]


Sprite spawn code

Only partial spawning code is available for the Sparky. Notice that there are three kinds of Sparky, one for each difficulty setting. The Sparky's cache is set in $C7 $06 $C289W $0001W.

The last blue highlighted value is the sprite action the sprite uses as it proceeds to act in-level. $C7 $02 $xxxxW sets the sprite activity, $C7 $47 $06 $xxxxW sets the clipping, $C7 $07 $xxxxW sets the sprite type, $C7 $20 $xxxxW sets the foreground value., Finally $D3 $E0 $05 $xxxx is how far down (Or more usually up) the sprite is spawned from where it is placed. This is necessary for sprites that walk on the ground as they can only be placed in the level at multiples of 16 pixels high while their actual height can be anything.

$C7 $47 $0E $xxxxW is the horizontal direction the sprite starts moving in, either $0001W (Facing right), $FFFFW (Facing left) or $0000W (Neither, never used.) $C7 $47 $10 $xxxxW is the vertical direction and works similarly. Some sprites have a probability check to determine which way they face this is always 50:50 (Though it needn't be.) and the code responsible for this is $9A $1D02002ARL $3D $0080W

The spawn code contains and is thus incompatible with a number of other patches on this page.

Keen 5

#Location of initiation code
%patch $F4CC [$1F5W] #Easy Sparky (At $EF45)
%patch $F4CE [$1EBW] #Normal Sparky (At $EF3B)
%patch $F4D0 [$1E1W] #Hard Sparky (At $EF31)

#Sparky Initiation code
%patch $EF31 $83 $3E [$6F6CW]  {$03 $7D} $03 $E9 $046CW $83 $3E [$6F6CW]  {$02 $7D}
             $03 $E9 $0462W  $57 $56 $9A {$11020004RL}    $83 $C4 $04 $C7 $06
             $C289W  $0001W  $E9 $044FW

#Sparky spawn code
%patch $11024 $55 $8B $EC $33 $C0 $50 $9A $06B91DCDRL     $83 $C4 $02 $8B $1E
              $40 $9E $C7 $07 [$0009W]  $C7 $47 $02 [$0001W]  $C7 $47 $20 [$0000W]
              $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $05
              [$FF00W]  $89 $47 $0C $9A $1DFB0036RL     $3D $0080W  $7D $0B $8B
              $1E $40 $9E $C7 $47 $0E [$0001W]  $EB $09 $8B $1E $40 $9E $C7 $47
              $0E [$FFFFW]  $8B $1E $40 $9E $C7 $47 $10 [$0001W]  $B8 [$1F0CW]  $50
              $53 $9A $090B11C4RL     $83 $C4 $04 $5D $CB