Patch:Poison Slug

From KeenWiki
Jump to: navigation, search

This page covers patches relating to the Poison Slugs in Keen 4. The slugs are found in many levels and spend their time moving back and forth and leaving slime puddles everywhere.

Sprite Type

Slugs use sprite type 5 which is used only by the Slug and doesn't affect anything else. Its slime puddles are type 1 (Misc).

Patch: Keen 4
#Slug sprite types
%patch $FD92 $05
#Poison Slug
%patch $FE3F $01
#Poison Slug slime

Sprite Actions

Slugs have 7 actions, two crawling, one sliming, two different stunned animations and two slime puddle actions. The first two make up the bulk of the Slug's time and make it move back and forth. It randomly slimes leaving a slime puddle behind that eventually dries. Because it is the most common enemy it has not one by two different possible death animations.

Slugs are spawned crawling and can themselves spawn puddles of slime, something rather unique in the game. (One sprite spawning another.) The slime will vanish after a time. Sliming occurs randomly.

$2012W #Poison Slug
$2030W #Poison slug
$204EW #Poison Slug sliming
$206CW #Short stunned poison slug
$208AW #Tall stunned poison slug
$20A8W #Slug Slime
$20C6W #Slug Slime drying

Patch: Keen 4
#Slug placed in-level
%patch $FDDB $2012W
#Spawn Slug
%patch $FE5B $20A8W
#Spawn Slug slime
#Slug behavior
%patch $30E9E $2030W
#Crawl 1
%patch $30EBC $2012W
#Crawl 2
#Slug sliming (Occurs randomly)
%patch $FE15 $204EW
%patch $30EDA $2012W
#Return to crawling
#When shot
%patch $FE93 $206CW
#Spawn tall stunned slug
%patch $FEA3 $208AW
#Spawn short stunned slug
#Stunned Slug
%patch $30EF8 $0000W
#Do nothing
%patch $30F16 $0000W
#Do nothing
#Slug slime
%patch $30F34 $20C6W
#Slug slime 1
%patch $30F52 $0000W
#Slug slime 2 (Vanish)

Sprite Behavior

The Slug's behaviors are simple. There is one behavior that controls the slug's crawling, it moves back and forth, randomly stopping to turn into a sliming slug. The sliming behavior makes a puddle of slime then returns the slug to crawling. The slug moves between these two behaviors. Slug slime has no behavior, it just sits.

It is notable that in order to reduce the chance of sliming the Slug uses its 'crawl' behavior only half the time, the rest of the time it does nothing. This doesn't make much sense, but then this is Keen we're talking about.

$09DC16C9RL #Shot sprite
$0FA80369RL #Slug crawling (Randomly slime)
$0FA803A6RL #Produce Slug Slime and return to Slug_Crawling

Patch: Keen 4
#Slug crawl (Notice only uses behavior 50% of time)
%patch $30E92 $00000000L
%patch $30EB0 $0FA80369RL
#Slug crawling
#Sliming slug
%patch $30ECE $0FA803A6RL
#Produce slime
#When shot
%patch $30EEC $09DC16C9RL
#Shot sprite
%patch $30F0A $09DC16C9RL
#Shot sprite
%patch $30F28 $00000000L
%patch $30F46 $00000000L

Poison Slug doesn't slime

This patch makes the Slug not pause and slime, instead simply turning to face Keen randomly.

Patch: Keen 4
#Poison Slug doesn't slime
%patch $FE12 $5E $5D $CB

Behavior code

This is the actual code used by the Slug.

Sliming behavior code

This is the full code for the Slug producing slime. It can be seen that this is just a 'create sprite' code that sets a number of the sprite's properties; the first blue value isn't related but the others are. The second value is the slime's sprite type; in this case 'misc'. The third value is its activity; set to 3 it is always active even when offscreen. This means it will dry up even if Keen can't see it, preventing it building up and crashing the game.

The fourth value is the slime's clipping; here set to 1 or 'normal' so it can interact with the ground. (Though it has no need to.) Finally the fifth value is the spawn height; since the slime is shorter than the slug it must be spawned 8 pixels down from the top of the slug. If the slug or the slime's heights are changed this variable must be changed too.

This can be used as a behavior by any other sprite to produce another. However it is important to note that the activity variable will need to be changed to 1 if the slime is not intended to vanish.

Patch: Keen 4
#Slug sliming behavior
%patch $FE26 $55 $8B $EC $56 $8B $76 $06 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0001W $C7 $47 $02 $0003W $C7 $47 $20 $0001W $8B $44 $0A $89 $47 $0A $8B $44 $28 $2D $0080W $89 $47 $0C $B8 $20A8W $50 $53 $9A $09DC118CRL $83 $C4 $04 $5E $5D $CB

Crawling behavior code

This is the code used when the slug is crawling. It leads to the slug sliming. Notice that all the patches in this section have the potential to interfere with other patches on this page (E.g. sound patches.) so care must be taken when using them. The default patch is given first, followed by a number of other interesting patches. Still other variations are possible (E.g. randomly play a sound and change direction but not behavior.) and are simple enough to construct.


The default behavior begins with a random check (in brown, $0010W is how likely the Slug is to do something. See also Patch:Jump conditions.) If the check is passed then three things will occur. First a second check will be performed to find Keen's position, the slug will then change its horizontal direction to face him ($0001\$FFFF.) Second the Slug's action will change to sliming ($204EW.) And finally sound $2E will play.

Patch: Keen 4
#Slug randomly slime code
%patch $FDE9 $55 $8B $EC $56 $8B $76 $06 $9A $1D02002ARL $3D $0010W $7D $29 $8B $44 $0A $8B $1E $D6 $A7 $3B $47 $0A $73 $07 $C7 $44 $0E $0001W $EB $05 $C7 $44 $0E $FFFFW $C7 $44 $1C $204EW $B8 $002EW $50 $9A $187409F1RL $83 $C4 $02 $5E $5D $CB

Don't play sliming sound

This patch removes the sound from the above code, so the Slug does not make a noise when it slimes. (It is identical in effect to the no sound patch in the sound section below.) notice that the brown $29 has changed to $1D as the code size has changed.

Patch: Keen 4
#Slug randomly slime code - no sound
%patch $FDE9 $55 $8B $EC $56 $8B $76 $06 $9A $1D02002ARL $3D $0010W $7D $1D $8B $44 $0A $8B $1E $D6 $A7 $3B $47 $0A $73 $07 $C7 $44 $0E $0001W $EB $05 $C7 $44 $0E $FFFFW $C7 $44 $1C $204EW $5E $5D $CB

Don't face Keen

This patch removes the 'face Keen' code. This differs from the 'seek Keen' patches below in that Keen's position has no effect on which way the Slug faces after sliming.

Patch: Keen 4
#Slug randomly slime code - don't face Keen
%patch $FDE9 $55 $8B $EC $56 $8B $76 $06 $9A $1D02002ARL $3D $0010W $7D $14 $8B $44 $0A $C7 $44 $1C $204EW $B8 $002EW $50 $9A $187409F1RL $83 $C4 $02 $5E $5D $CB

Only change behavior

This patch removes both the direction change and sound from the default code, resulting in the Slug doing nothing but randomly changing its behavior to sliming.

Patch: Keen 4
#Slug randomly slime code -only change action
%patch $FDE9 $55 $8B $EC $56 $8B $76 $06 $9A $1D02002ARL $3D $0010W $7D $08 $8B $44 $0A $C7 $44 $1C $204EW $5E $5D $CB

Randomly play sound

This patch removes the change direction and behavior code making the slug simply randomly play the sliming sound. This can be useful to add ambiance and background sounds to a game.

Patch: Keen 4
#Randomly play sound
%patch $FDE9 $55 $8B $EC $56 $8B $76 $06 $9A $1D02002ARL $3D $0010W $7D $0F $8B $44 $0A $B8 $002EW $50 $9A $187409F1RL $83 $C4 $02 $5E $5D $CB

Randomly seek Keen

This is the Arachnut behavior.See its page for details.

Seeking Keen

The Slug will face (and thus head towards) Keen each time it slimes. This does not have too much of an effect.

Patch: Keen seeking
#Face Keen after sliming
%patch $FE09 $0001W %patch $FE10 $FFFFW

Speed and Jump Height

Slugs rely on animation motion for their crawling speed. The only other parameter is the height they jump when shot, controlled by their collision. (See section below.) The slug slime and stunned slugs do not otherwise move. Due to the movement parameter, slug motion is in jerks, like inchworms.

Patch: Slug jump height
%patch $FEB3  $FFE8W 
#Jump height when shot

Patch: Animation motion
%patch $30EE8 $0000W $0000W
#Speed (A)
%patch $30F06 $0000W $0000W
#Speed (B)
%patch $30E8E $0040W $0000W
#Speed 1
%patch $30EAC $0040W $0000W
#Speed 2
%patch $30ECA $0040W $0000W
#Speed (Moves after sliming)
%patch $30F24 $0000W $0000W %patch $30F42 $0000W $0000W

Sprite Collision

Collision values

The Slug uses its own special collision. It will be killed if hit by Keen's shots, and kill Keen if he touches it. This is used by the crawling and sliming slugs. Unevaporated slug slime will just kill Keen (Using a general collision) and the stunned slugs and drying slime are harmless. (No collision.)

Patch: Keen 4 collision values
%patch $30E96 $0FA803EARL
#Poison slug
%patch $30EB4 $0FA803EARL
#Poison slug
%patch $30ED2 $0FA803EARL
#Poison slug
%patch $30EF0 $00000000L
#No collision (Tall)
%patch $30F0E $00000000L
#No collision (Short)
%patch $30F2C $09DC1752RL
#Kill Keen
%patch $30F4A $00000000L
#No collision

Collision code

It pays to be familiar with the workings of jump conditions in order to use these patches correctly.


The default code is moderately complex. The first check if for Keen (The blue $02) if the sprite is Keen's type, Keen will be killed. ( $9A $0B8013E9RL) The next check is for Keen's shot (The blue $03) and if this is found the slug will be stunned. Replacing the 'kill Keen' code (Marked in brown) with '$90 $90 $90 $90 $90' will make the Slug harmless to Keen, as will replacing the sprite-type check.

Stunning is rather complex. The first step is a probability check; if a randomly picked number is above $0080 then the first type of stunned slug, $206C will be produced, else the second kind $208A will. Finally the slug is made to jump into the air $FFE8 (A negative height.)

Patch: Keen 4
#Slug collision
%patch $FE6A $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $02 $75 $09
#Check for Keen (Type 2)
$9A $0B8013E9RL $5F $5E $5D $CB $83 $3D $03 $75 $39 $9A
#If Keen, kill him; check for shot (Type 3)
$1D02002ARL $3D $0080W $7D $10 $B8 $206CW $50 $57 $56 $9A
#If shot, probability check, if yes become $206C
$09DC1695RL $83 $C4 $06 $EB $0E $B8 $208AW $50 $57 $56 $9A
#Else become $208A
$09DC1695RL $83 $C4 $06 $C7 $44 $18 $FFE8W $8B $44 $0E $D1 $E0
#Jump into the air $FFE8
$D1 $E0 $D1 $E0 $89 $44 $16 $5F $5E $5D $CB

Only produce one type of stunned Slug

This removes the random component from the shot slug, making it always produce the same sprite. It can be seen that the other sprite's transform code is gone, as is the probability check. The Slug will still jump in the air when shot though.

Patch: Keen 4
#Slug collision produces only one type of slug
%patch $FE6A $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $02 $75 $09
#Check for Keen (Type 2)
$9A $0B8013E9RL $5F $5E $5D $CB $83 $3D $03 $75 $1F $B8
#If Keen, kill him; check for shot (Type 3)
$206CW $50 $57 $56 $9A $09DC1695RL $83 $C4 $06 $C7 $44 $18
#If shot, become $206C
$FFE8W $8B $44 $0E $D1 $E0 $D1 $E0 $D1 $E0 $89 $44 $16 $5F $5E $5D
#Jump into the air $FFE8

One type of slug, don't jump when shot

This patch is identical to the above one except the Slug does not jump a distance into the air when shot. This can be combined with other patches; notice that the jump after $03 is not $11 (or 17) less.

Patch: Keen 4
#Slug collision
%patch $FE6A $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $02 $75 $09
#Check for Keen (Type 2)
$9A $0B8013E9RL $5F $5E $5D $CB $83 $3D $03 $75 $0E $B8
#If Keen, kill him; check for shot (Type 3)
$206CW $50 $57 $56 $9A $09DC1695RL $83 $C4 $06 $5F $5E $5D $CB
#If shot, become $206C

Infinitely shootable Slug

This patch will make it such that the slug cannot be stunned, but each time it is shot a stunned slug will appear next to it. This patch must be used carefully, if too many stunned slugs are produced, and they do not vanish, the game will crash. It will be noticed this patch replaces the $8B $76 $06 in the above collision codes (First line) with $90s.

Patch: Keen 4
#Infinite shootability
%patch $FE6F $90 $90 $90


The animation scheme of Slugs is simple enough. There are three values for 'animation speed' that bear keeping in mind. The first is how long it takes the Poison Slug to slime; slime will be produced when the Poison Slug finishes its sliming action, so making this animation speed shorter decreases the warning Keen gets when a slug slimes. The two slime animation speeds control how fast the slime vanishes. The first controls how long before the slime becomes harmless, the second how long before it vanishes.

The two crawling animation speeds will also affect the Slug's movement speed, because of the way it moves.

Patch: Keen 4
%patch $306E6 $013BW
#Slug Cache start
%patch $30730 $0144W
#Slug cache end
#Stunned slug
%patch $30EDC $013EW $013EW
#'Tall' slug
%patch $30EE6 $0000W
#Animation speed
%patch $30EFA $013FW $013FW
#'Short' slug
%patch $30F04 $0000W
#Animation speed
#Poison slug crawl
%patch $30E82 $0140W $013BW %patch $30E8C $0008W
#Animation speed
%patch $30EA0 $0141W $013CW %patch $30EAA $0008W
#Animation speed
#Poison slug sliming
%patch $30EBE $0142W $013DW %patch $30EC8 $003CW
#Sliming time
#Poison slug slime
%patch $30F18 $0143W $0143W %patch $30F22 $012CW
#Time before half-dry
%patch $30F36 $0144W $0144W %patch $30F40 $003CW
#Time before vanishing


Patch: Keen 4
%patch $FE18 $2E
#Sliming sound
#Don't make sound:
%patch $FE1B $90 $90 $90 $90 $90
#Sliming sound

Sprite positioning

If the Slug's sprite size is changed, its spawn height must also be changed; by default it spawns -7 pixels above the ground. The slug is very sensitive to not being *exactly* on ground level, which results i 'air spinning'

The slime's spawn height ensures that it spawns on ground level instead of level with the Slug's head. If the Slug's height is changed this will need to be changed too.

Patch: Keen 4
#Spawn height
%patch $FDAE $FF8FW
#7 pixels up
#Slime spawn height
%patch $FE55 $0080W
#8 pixels down from Slug top

Clipping and foreground

The Slug's foreground variable is set when it is spawned. It appears in front of everything but foreground tiles. The slime's is similarly set, it will appear behind all foreground tiles and other sprites.

Patch: Keen 4
%patch $FD9C $0002W
#Poison slug
%patch $FE49 $0000W
#Poison Slug slime

Sprite-tile interaction

The Slug has its own special tile collision, used when crawling and sliming. This makes it turn around when it hits walls or the edges of platforms. (This is also what makes it spin madly in the air when the ground vanishes underneath it.) The shot slugs use the shot sprite tile collision as expected and the slime uses a 'sit still' collision.

Patch: Keen 4
%patch $30E9A $09DC1847RL
#Crawling 1
%patch $30EB8 $09DC1847RL
#Crawling 2
%patch $30ED6 $09DC1847RL
%patch $30EF4 $09DC1913RL
#Stunned tall
%patch $30F12 $09DC1913RL
#Stunned short
%patch $30F30 $09DC176ERL
#Slug slime 1
%patch $30F4E $09DC176ERL
#Slug slime 2

Action type

The Slug action paramter is quite important to how it moves. It is set to 0 for all the slug's actiosn, meaning that it moves in 'jerks' every time it animates. (Thus animation speed also controls its speed.) The shot slugs are value 2, so they can smoothly fly up into the air and land on the ground.

Patch: Keen 4
%patch $30E86 $0000W
#Crawl 1
%patch $30EA4 $0000W
#Crawl 2
%patch $30EC2 $0000W
#Poison slug sliming
%patch $30F1C $0000W
#Poison slug slime 1
%patch $30F3A $0000W
#Poison slug slime 2
%patch $30EF0 $0002W
#Stunned A
%patch $30EFE $0002W
#Stunned B

Deprotect and stick to ground

The Slug has a 'stick to ground' value of 1 for most of its actions, as it needs to crawl up and down hills. (The stunned slugs and slime are exempt of course.)

Patch: Keen 4
%patch $30E88 $0000W $0001W
#Crawl 1
%patch $30EA6 $0000W $0001W
#Crawl 2
%patch $30EC4 $0000W $0001W
%patch $30EE2 $0000W $0000W
#Stunned A
%patch $30F00 $0000W $0000W
#Stunned B
%patch $30F1E $0000W $0000W
#Slime 1
%patch $30F3C $0000W $0000W
#Slime 2

Probability and randomness

There are three opportunities for randomness in the Slug, how often it slimes, which of the two sprites it produces when shot and what direction it initially moves in. The slug has a 50/50 chance of initially moving right or left and of producing the short or tall stunned slugs when shot. Its probability of sliming is much, much lower, and changing this can have a big effect on the slug's behavior.

Patch: Keen 4
#Spawn moving right or left
%patch $FDB9 $80
#Sliming frequency
%patch $FDF6 $10
#Probability of shot slug being 'small'
%patch $FE8E $80

Sprite spawn code

In the initiation code notice the difficulty checks, allowing three difficulties of Slug, as well as the Slug cache being set ($C7 $06 $51 $CB $0001W.)

In the spawning code 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 $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.

The Slug always starts the level moving down. (Odd, it has no reason to.) $C7 $47 $10 $xxxxW is the vertical direction the sprite starts moving in, either $0001W (Facing down), $FFFFW (Facing up) or $0000W (Neither, never used.) There is however randomness in what horizontal direction the Slug spawns with. A 50:50 probability check is made which causes the Slug to spawn either facing left ($FFFFW) or right ($0001W; $C7 $47 $0E $xxxxW is the horizontal direction.)

Patch: Keen 4
#Location of initiation code
%patch $EEAF $0338W
#Easy Slug (At $EC28)
%patch $EED9 $032EW
#Medium Slug (At $EC1E)
%patch $EEDB $0324W
#Hard Slug (At $EC14)
#Slug Initiation code
%patch $EC14 $83 $3E $7A6CW $03 $7D $03 $E9 $01DFW $83 $3E $7A6CW $02 $7D $03 $E9 $01D5W $FF $76 $FC $57 $9A $0FA802FERL $83 $C4 $04 $C7 $06 $51 $CB $0001W $E9 $01C0W
#Slug Spawning code
%patch $FD7E $55 $8B $EC $33 $C0 $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0005W $C7 $47 $02 $0001W $C7 $47 $20 $0002W $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $05 $FF8FW $89 $47 $0C $9A $1D02002ARL $3D $0080W $7D $0B $8B $1E $D8 $A7 $C7 $47 $0E $0001W $EB $09 $8B $1E $D8 $A7 $C7 $47 $0E $FFFFW $8B $1E $D8 $A7 $C7 $47 $10 $0001W $B8 $2012W $50 $53 $9A $09DC118CRL $83 $C4 $04 $5D $CB


This section contains patches that do not fit in any other section.

Slug chases Keen, fires at him

This patch makes the Poison Slug chase Keen (using the Inchworm behavior.) and makes its slime fly through the air like a shot. The slime will also head towards Keen no matter which way the Slug is facing. (So the first line can be removed, making the Slug not chase Keen and it will still fire towards him.)

This patch is incompatible with the Slug slime spawn height and action patches as it already contains them.

Patch: Keen 4
#Slug uses Inchworm behavior
%patch $30E92 $10800770RL
#Spawn special Slug slime action
%patch $FE5B $0004W
#Slime spawn height (Higher, in air)
%patch $FE55 $00F0W
#Slug slime heads in Keen's direction = $0004W
%patch $2EE74 $0143W $0143W $0001W $0000W $0000W $0004W $0000W $0000W $10800770RL $09DC1752RL $11A20CA1RL $20A8W
#Slug slime moves through the air =$20A8W
%patch $30F18 $0143W $0143W $0001W $0000W $0000W $0004W $0040W $0000W $00000000L $09DC1752RL $11A20CA1RL $20C6W %patch $30F36 $0144W $0144W $0001W $0000W $0000W $0004W $0040W $0000W $00000000L $09DC1752RL $11A20CA1RL $20A8W