Patch:Inchworm

From KeenWiki
Jump to: navigation, search

This page covers patches relating to the Inchworms in Keen 4. The Inchworms appear in several levels and are notable in that when enough are collected together they become a Foot.

Patches relating to the Foot are found on its page, patches relating to the formation of a Foot from Inchworms are found here.


Sprite Type

Inchworms use sprite type 16 which is one of the few types important by default as it is the type looked for by Inchworms when they are deciding to become a Foot. (See sprite collision.) Aside from this it doesn't affect any other sprites by default.

Patch: Keen 4
#Inchworm sprite type
%patch $10EC6 $10
#Type needed to form Foot
%patch $10FA0 $10


Sprite Actions

Inchworms have two actions, the worm moving. Also associated with it are actions used when the Foot is formed. These manifest as puffs of smoke concealing the Foot's formation. The Foot actions are also tied to the Inchworms, but are on the Foot's patch page.

Inchworms can be placed in the level. Four Foot smoke sprites are created along with the Foot (See sprite collision.), animate and then disappear. The Foot action here is unique and different from the one used by Foot placed in-level. This indicates that the Foot Keen can make may have been intended to behave differently from the one he comes across in the Pyramid of the Forbidden

Actions:
$2E22W #Foot appearing smoke 1
$2E40W #Foot appearing smoke 2
$2E5EW #Foot appearing smoke 3
$2E7CW #Foot appearing smoke 4
$2E9AW #Inchworm 1
$2EB8W #Inchworm 2
$2ED6W #Invisible Foot (Spawned by Inchworms)
$2EF4W #Foot

Patch: Keen 4
#Inchworm placed in-level
%patch $10F0C $2E9AW
#Inchworm 1
#Inchworm actions
%patch $31D26 $2EB8W
#Inchworm 1
%patch $31D44 $2E9AW
#Inchworm 2 (Go to 1)
#Foot smoke spawned during Foot creation
%patch $11012 $2E22W
#Spawn smoke Left
%patch $11046 $2E22W
#Spawn smoke Middle
%patch $1107A $2E22W
#Spawn smoke Right
%patch $110AB $2E22W
#Spawn smoke Top
#Foot smoke actions
%patch $31CAE $2E40W
#Foot smoke 2
%patch $31CCC $2E5EW
#Foot smoke 3
%patch $31CEA $2E7CW
#Foot smoke 4
%patch $31D08 $0000W
#Foot smoke vanish
#Invisible Foot is produced from Inchworms
%patch $10FDE $2ED6W
#Invisible Foot becomes visible
%patch $31D62 $2EF4W


Sprite Behavior

The Inchworm's behavior is quite simple, it will change its direction to always be facing Keen. Since it also moves (Though this is not coded into the behavior) it will thus head towards Keen horizontally. The Foot and Foot smoke both have no behavior, just sitting around.

Behaviors:
$10800770RL #Head toward Keen

Patch: Keen 4
#Inchworm behavior
%patch $31D1A $10800770RL
#Head toward Keen
%patch $31D38 $10800770RL
#Head toward Keen
#Invisible Foot behavior
%patch $31D56 $00000000L
#Nothing
#Foot behavior
%patch $31D74 $00000000L
#Nothing
#Foot smoke behavior
%patch $31CA2 $00000000L
#Nothing
%patch $31CC0 $00000000L
#Nothing
%patch $31CDE $00000000L
#Nothing
%patch $31CFC $00000000L
#Nothing


Behavior Code and seeking Keen

This is the complete behavior code for the Inchworm. it is very simple, change the Inchworm's horizontal direction to always head towards Keen. It is one of the simplest behaviors in the game.

Inchworms are Keen-seeking. It is possible to make them run away from Keen by reversing the values in the patch below. Setting both values to 0 means the Inchworms will ignore Keen (Move back and forth) while making them both +\-1 will mean they always head in one direction across the screen.

Patch: Keen 4
#Inchworm behavior code
%patch $10F70 $55 $8B $EC $56 $8B $76 $06 $8B $44 $0A $8B $1E $A7D6W $3B $47 $0A $76 $08 $C7 $44 $0E $FFFFW $5E $5D $CB $C7 $44 $0E $0001W $5E $5D $CB


Speed and Jump Height

Neither the Foot or foot smoke move. Inchworms use animation movement, meaning they move a number of pixels each time it animates. (Thus both the animation speed and amount contribute to the Inchworm's speed, see sprite animations.)

Patch: Keen 4
#Inchworms
%patch $31D16 $0080W $0000W
#Speed 1
%patch $31D34 $0080W $0000W
#Speed 2
#Foot smoke
%patch $31C9E $0000W $0000W
#Speed 1
%patch $31CBC $0000W $0000W
#Speed 2
%patch $31CDA $0000W $0000W
#Speed 3
%patch $31CF8 $0000W $0000W
#Speed 4
#Invisible Foot
%patch $31D52 $0000W $0000W
#Foot
%patch $31D70 $0000W $0000W


Sprite Collision

The Inchworm collision is one of the more complex in Keen 4, both in terms of how it interacts with other sprites and what it does. The Inchworm will look for sprite type 16 only (Nothing else affects them.) and when it is touching 11 others of this type it will turn into a Foot, produce four Foot smoke sprites and erase all sprites of type 16 from the level. This boils down to it appearing that 12 Inchworms form a Foot in a puff of smoke and sound.


Collision values

The following are the collision values that refer to the actual collision referenced below. Only the Inchworm really uses a collision.

The Foot also has a collision, one that specifically does nothing. This is possibly a relic of later deleted code.

Patch: Keen 4 collision values
#Inchworms
%patch $31D1E $10800793RL
#Inchworm 1
%patch $31D3C $10800793RL
#Inchworm 2
#Invisible Foot
%patch $31D5A $00000000L
#No collision
#Foot
%patch $31D78 $108008D9RL
#Foot
#Foot smoke
%patch $31CA6 $00000000L
#No collision (Top smoke puff)
%patch $31CC4 $00000000L
#No collision (Left smoke puff)
%patch $31CE2 $00000000L
#No collision (Right smoke puff)
%patch $31D00 $00000000L
#No collision (Bottom smoke puff)


Collision code

The following is the entire code for the default Inchworm collision. The first line has what type the Inchworms look for and the jump condition, the third line the number of worms needed, the fourth line a jump condition and the sound played when the Foot appears.

The fifth line has the action the colliding worm switches to (It becomes a Foot.) and the sprite type it changes to (It changes to type 17, Foot.) Following is the creation of the four smoke puffs in this order, upper, left, right, lower. By default these are arranged in a diamond shape.

Each Foot puff requires three variables; the h\v location, the foreground type and the action to start with. For positioning $05 means +ve and $2D -ve, $0A horizontal and $0C vertical. First is the position, then foreground, then action.

If this appears too complex, many of the individual patches affecting it appear elsewhere on this page, such as the action section.

Patch: Keen 4
#Default Inchworm collision
%patch $10F93 $55 $8B $EC $56 $57 $8B $76 $06 $8B $5E $08 $83 $3F $10 $74 $03
#Respond only to sprite type $10
$E9 $012FW $8B $44 $3E $3B $06 $48 $A5 $74 $0B $A1 $48 $A5 $89 $44 $3E $C7 $44 $40 $0000W $FF $44 $40 $8B $44 $40 $3D $000AW
#Number needed (11 others)
$74 $03 $E9 $010DW $B8 $002DW $50 $9A $187409F1RL $83 $C4
#Play sound $2D
$02 $81 $6C $0C $0500W $C7 $04 $0011W $B8 $2EF4W $50 $56 $9A
#Turn worm into Foot
$09DC120ARL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $44 $0A $2D $0080W $8B $1E $D8 $A7 $89 $47 $0A
#Up smoke
$8B $44 $0C $05 $0100W $89 $47 $0C $C7 $47 $20 $0003W $B8 $2E22W $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $44 $0A $05 $0100W $8B $1E $D8
#Left smoke
$A7 $89 $47 $0A $8B $44 $0C $05 $0180W $89 $47 $0C $C7 $47 $20 $0003W $B8 $2E22W $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $44 $0A $05 $0280W
%patch $11064 $8B $1E $D8 $A7 $89 $47 $0A $8B $44 $0C $05 $0100W $89 $47
#Right smoke
$0C $C7 $47 $20 $0003W $B8 $2E22W $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $44 $0A $8B $1E $D8 $A7 $89 $47 $0A $8B $44 $0C $2D $0080W $89
#Down smoke
$47 $0C $C7 $47 $20 $0003W $B8 $2E22W $50 $53 $9A $09DC118CRL $83 $C4 $04 $8B $1E $A7D6W $8B $7F $48 $EB $11 $83 $3D $10
#Remove sprites of type $10
$75 $09 $57 $9A $06BD1E8BRL $83 $C4 $02 $8B $7D $48 $0B $FF $75 $EB $5F $5E $5D $CB


Don't produce smoke

This is the Inchworm collision with the Foot smoke removed, this makes it simpler to patch and see how it works.

Patch: Keen 4
#Inchworm collision without Foot smoke
%patch $10F93 $55 $8B $EC $56 $57 $8B $76 $06 $8B $5E $08 $83 $3F $10 $74 $03
#Respond only to sprite type $10
$E9 $012FW $8B $44 $3E $3B $06 $48 $A5 $74 $0B $A1 $48 $A5 $89 $44 $3E $C7 $44 $40 $0000W $FF $44 $40 $8B $44 $40 $3D $000AW
#Number needed (11 others)
$74 $03 $E9 $010D $B8 $002DW $50 $9A $187409F1RL $83 $C4
#Play sound $2D
$02 $81 $6C $0C $0500W $C7 $04 $0011W $B8 $2EF4W $50 $56 $9A
#Turn worm into Foot
$09DC120ARL $83 $C4 $04 $8B $1E $A7D6W $8B $7F $48 $EB $11 $83 $3D $10 $75 $09 $57 $9A $06BD1E8BRL $83 $C4 $02 $8B $7D
#Remove sprites of type $10
$48 $0B $FF $75 $EB $5F $5E $5D $CB


Animations

The Foot and Inchworms are inextricably linked, they both share the same cache for example. The Foot produced from Inchworms is temporarily invisible, but quickly reverts to the same Foot as one placed in-level. The 'Inchworm Foot' uses the value -1 for its sprite when produced, this erases its previous sprite, which is an Inchworm and makes the Foot invisible for a time. (While the smoke appears around it.)

The Foot and the Inchworm also independently cache the clouds of smoke used by the Smirky when teleporting, used by the Inchworms when transforming into the Foot. (For the Foot then this is not actually necessary.)

Patch: Keen 4
#Cache
%patch $306EC $014DW
#Inchworm\Foot Cache start
%patch $30738 $0151W
#Inchworm\Foot cache end
#Cache Smirky clouds - Inchworm
%patch $EAA1 $015EW
#Cloud Cache start
%patch $EAB6 $0151W
#Cloud cache end
#Inchworms
%patch $31D0A $014FW $014DW
#Inchworm 1
%patch $31D14 $001EW
#Animation speed
%patch $31D28 $0150W $014EW
#Inchworm 2
%patch $31D32 $001EW
#Animation speed
#Foot smoke
%patch $31C92 $015EW $015EW
#Foot smoke 1
%patch $31C9C $000CW
#Animation speed
%patch $31CB0 $015FW $015FW
#Foot smoke 2
%patch $31CBA $000CW
#Animation speed
%patch $31CCE $0160W $0160W
#Foot smoke 3
%patch $31CD8 $000CW
#Animation speed
%patch $31CEC $0161W $0161W
#Foot smoke 4
%patch $31CF6 $000CW
#Animation speed
#Inchworm foot (Invisible!)
%patch $31D46 $FFFFW $FFFFW
#Foot (Erase previous (Inchworm) sprite)
%patch $31D50 $0030W
#Pause before foot appears


Sounds

The only notable sound relating to Inchworms is that played when 12 Inchworms make a Foot.

Patch: Keen 4
#Sound
%patch $10FC9 $2D
#Foot formed sound
#Don't make Foot formed sound:
%patch $10FC8 $EB $0A


Sprite positioning

The most important positioning patches are the locations of the foot smoke produced when Inchworms collide. As mentioned in the collision section, $05 is +ve, $2D -ve, $0A horizontal, $0C vertical. For example the foot appears five tiles up vertically when formed. The Inchworm itself however has its position set at 0,0 which means that it can't be patched (easily).

Patch: Keen 4
#Foot
%patch $10FD6 $0C $0500W
#Vertical location
#Foot smoke
%patch $10FF8 $0A $2D $0080W
#Upper puff h
%patch $11005 $0C $05 $0180W
#v
%patch $1102C $0A $05 $0100W
#Left puff h
%patch $11039 $0C $05 $0180W
#v
%patch $11060 $0A $05 $0280W
#Right puff h
%patch $1106D $0C $05 $0100W
#v
%patch $1109E $0C $2D $0080W
#Lower puff v (No h value.)


Inchworm Vertical Position Patch

This patch allows a modder to alter the Inchworm's vertical position, useful when the sprite's height is changed. As a side effect it removes the ability of the modder to alter the Inchworm's foreground variable (See section below.) and trying to use both patches will cause a crash. The blue value is the vertical position, here set at '4 pixels down'

There are several caveats to this patch; firstly it is only directly useful when all the Inchworm's sprites are changed in height by the same amount; that is the 'up' Inch sprites are 4 pixels taller than the 'down' ones. It is probably much easier for a modder to edit the SPRITES.TXT (ModKeen) or LIST.TXT (Keengraph) files.

Patch: Keen 4 Inchworm Vertical Position Patch
#Alter Inchworm v position
%patch $10ECD $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $05 $0040W $89 $47 $0C $90 $90


Clipping and foreground

The Inchworm's foreground variable is set when it is spawned (At level start) the foot smoke's are set when they are formed.

Patch: Keen 4
#Foreground
%patch $10ED0 $0002W
#Inchworm
%patch $1100F $0003W
#Foot smoke 1
%patch $11043 $0003W
#Foot smoke 2
%patch $11077 $0003W
#Foot smoke 3
%patch $110A8 $0003W
#Foot smoke 4


Probability and randomness

The only thing random about Inchworms is what direction they face when they are spawned. This has little effect by default since the Inchworm will immediately face Keen.

Patch: Keen 4
#Spawn left or right frequency
%patch $10EEA $80


Sprite-tile interaction

There are two different sprite-tile interactions used here, the first is used by Inchworms and allows them to move back and forth and turn at the edge of platforms. The second is 'sit', where a sprite ignores all tiles.

Patch: Keen 4
#Inchworms
%patch $31D22 $09DC1795RL
#Walk back and forth
%patch $31D40 $09DC1795RL
#Walk back and forth
#Inchworm foot
%patch $31D5E $09DC176ERL
#Sit
#Foot smoke
%patch $31CAA $09DC176ERL
#Sit
%patch $31CC8 $09DC176ERL
#Sit
%patch $31CE6 $09DC176ERL
#Sit
%patch $31D04 $09DC176ERL
#Sit


Action type

All Inchworm actions use type 0; this gives them jerky, 'Inchy' movement. Making this type 1 makes them move smoothly.

Patch: Keen 4
#Inchworms
%patch $31D0E $0000W
#Inchworm 1
%patch $31D2C $0000W
#Inchworm 2
#Foot
%patch $31D4A $0000W
#Inchworm foot
#Foot smoke
%patch $31C96 $0000W
#Foot smoke 1
%patch $31CB4 $0000W
#Foot smoke 2
%patch $31CD2 $0000W
#Foot smoke 3
%patch $31CF0 $0000W
#Foot smoke 4


Deprotect and stick to ground

Only the Inchworms use the stick-to-ground values, since they must move up and down slopes.

Patch: Keen 4
#Inchworms
%patch $31D10 $0000W $0001W
#Inchworm 1 (Crawls)
%patch $31D2E $0000W $0001W
#Inchworm 2 (Crawls)
#Inchworm foot
%patch $31D4C $0000W $0000W
#Appearing foot
#Only Inchworms need to change v to crawl, all the rest don't
%patch $31C98 $0000W $0000W
#Foot appearing cloud 1
%patch $31CB6 $0000W $0000W
#Foot appearing cloud 2
%patch $31CD4 $0000W $0000W
#Foot appearing cloud 3
%patch $31CF2 $0000W $0000W
#Foot appearing cloud 4


Sprite spawn code

In the initiation code notice the Foot\Inchworm cache being set ($C7 $06 $CB59W $0001W.) Notice the additional caching of the Smirky's smoke clouds starting with $015EW and ending with $0161W. This is for if\when the foot needs to be formed.

Patch: Keen 4
#Location of initiation code
%patch $EE99 $01CDW
#Inchworm (At $EABD)
#Inchworm Initiation code
%patch $EABD $FF $76 $FC $57 $9A $108006B2RL $83 $C4 $04 $C7 $06 $CB59W $0001W $BE $015EW $EB $0F $B8 $3A $2A $8A $16 $EC $7A $8E $C0
#Also cache Smirky clouds, start...
$26 $08 $94 $00 $00 $46 $81 $FE $0161W $76 $EB $E9 $0311W
#End
#Inchworm spawn code
%patch $10EB2 $55 $8B $EC $33 $C0 $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0010W $C7 $47 $02 $0001W $C7 $47 $20 $0002W $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $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 $2E9AW $50 $9A $09DC118CRL $83 $C4 $04 $9A $1D02002ARL $BB $0020W $99 $F7 $FB $8B $1E $D8 $A7 $89 $47 $1A $5D $CB