Patch:Keen jumping (Galaxy)

From KeenWiki
(Redirected from Patch:Keen fall (Galaxy))
Jump to navigation Jump to search

This page contains patches relating to Keen jumping and falling in the Galaxy series of games. That is, such things as the sprites used, the speeds and sounds. It does not cover patches relating to gameplay such as those that make levels scroll or change keys. It is divided into sections relating to the various sprite properties the patches involved. Being fluent with various sprite patch pages will help when working with these patches.

Given that jumping and falling are closely related this page also deals with Keen's falling actions. Closely related both behavior and physics-wise is Patch:Keen pogoing (Galaxy). Keen's jumping in Keen Dreams is covered on the page Patch:Keen jumping (Dreams)


Sprite Actions

There are three situations in which Keen can trigger his jumping sequence; when standing still, when walking or when on poles. Each leads to the first action of his jumping sequence. This sequence is two actions long and ends with the first action of Keen's falling loop. Keen's falling loop is also two actions long and loops indefinitely until Keen hits the ground.

There are many situations that will make Keen go directly to his falling loop. The first is when [[Patch:Keen look}|looking down]] and pressing the jump key. The second is when he stops pogoing in midair. The third is when he is on a pole but level with the ground, whereupon he can simply 'walk' left or right off the pole. The fourth is when he moves down a pole off its bottom. The fifth is by letting go of a Patch:Ledges|ledge he is gripping.]] The sixth occurs when he is standing on ground that vanishes or a moving platform that he's pushed off of. Finally Keen can simply walk off an edge.

Keen's jumping\falling behavior is slightly unique; rather than make him animate in the usual fashion, it will switch him from jumping to falling if his vertical speed becomes positive. (Downwards.) To avoid the falling actions constantly triggering this, there are two 'jump exceptions', one for each falling action.

Finally, Keen can do things such as shoot or pogo while jumping, but these actions are covered on their own pages.


Keen 4

One notable thing about the player in Keen 4 is that when using his second sprite collision Keen can be disturbed by Platforms or Bounders; in both cases he will revert to his falling action. This happens in a variety of situations such as when on poles or being bored.

Actions:
$1166W #Keen jumping 1
$1184W #Keen jumping 2
$11A2W #Keen falling 1
$11C0W #Keen falling 2

Keen 4

#Keen start jumping while standing
%patch $BB01  [$1166W]

#Keen start jumping while walking
%patch $BF1D  [$1166W]

#Keen start jumping on a pole
%patch $C6BB  [$1166W]

#Jumping sequence
%patch $2FFF2 [$1184W]
%patch $30010 [$11A2W]

#Falling loop
%patch $3002E [$11C0W]
%patch $3004C [$11A2W]

#Fall when Keen...
%patch $BDDB  [$11A2W] #...jumps down from one-way up platforms
%patch $C628  [$11A2W] #...stops pogoing in midair
%patch $C762  [$11A2W] #...walks off a pole onto ground
%patch $C879  [$11A2W] #...falls off pole bottoms
%patch $C98A  [$11A2W] #...lets go of ledges
%patch $D2CD  [$11A2W] #...is standing on ground that vanishes
%patch $D38A  [$11A2W] #...walks off solid ground

#Fall when pushed by...
%patch $CE54  [$11A2W] #...Platforms
%patch $CE8C  [$11A2W] #...Bounders

#Jump-falling exceptions
%patch $C409  [$11A2W]
%patch $C410  [$11C0W]

#Keen go to falling after...
%patch $300A6 [$11A2W] #...shooting horizontally in air
%patch $30100 [$11A2W] #...shooting up in air
%patch $3015A [$11A2W] #...shooting down in air


Keen 5

Actions:
$1044W #Keen jumping 1
$1062W #Keen jumping 2
$1080W #Keen falling 1
$109EW #Keen falling 2

Keen 5

#Keen start jumping while standing
%patch $AEC9  [$1044W]

#Keen start jumping while walking
%patch $B2E2  [$1044W]

#Keen start jumping on a pole
%patch $BAD9  [$1044W]

#Jumping sequence
%patch $313A0 [$1062W]
%patch $313BE [$1080W]

#Falling loop
%patch $313DC [$109EW]
%patch $313FA [$1080W]

#Fall when Keen...
%patch $B1A0  [$1080W] #...jumps down from one-way up platforms
%patch $BA46  [$1080W] #...stops pogoing in midair
%patch $BB80  [$1080W] #...walks off a pole onto ground
%patch $BC97  [$1080W] #...falls off pole bottoms
%patch $BDA8  [$1080W] #...lets go of ledges
%patch $C5E1  [$1080W] #...stands on ground that vanishes
%patch $C69E  [$1080W] #...walks off edges

#Fall when pushed by...
%patch $C195  [$1080W] #...Platforms
%patch $C1C5  [$1080W] #...Amptons

#Jump-falling exceptions
%patch $B827  [$1080W]
%patch $B82E  [$109EW]

#Keen go to falling after...
%patch $31454 [$1080W] #...shooting horizontally in air
%patch $314AE [$1080W] #...shooting up in air
%patch $31508 [$1080W] #...shooting down in air


Keen 6

Actions:
$0FDEW #Keen jumping 1
$0FFCW #Keen jumping 2
$101AW #Keen falling 1
$1038W #Keen falling 2

Sprite actions

#Keen start jumping while standing
%patch $AD17  [$0FDEW]

#Keen start jumping while walking
%patch $B11E  [$0FDEW]

#Keen start jumping on a pole
%patch $B8BC  [$0FDEW]

#Jumping sequence
%patch $31D2A [$0FFCW]
%patch $31D48 [$101AW]

#Falling loop
%patch $31D66 [$1038W]
%patch $31D84 [$101AW]

#Fall when Keen...
%patch $AFDC  [$101AW] #...jumps down from one-way up platforms
%patch $B829  [$101AW] #...stops pogoing in midair
%patch $B963  [$101AW] #...walks off a pole onto ground
%patch $BA7A  [$101AW] #...falls off pole bottoms
%patch $BB8B  [$101AW] #...lets go of ledges
%patch $C3C7  [$101AW] #...is standing on ground that vanishes
%patch $C484  [$101AW] #...walks off solid ground

#Fall when pushed by...
%patch $BFA2  [$101AW] #...Platforms

#Jump-falling exceptions
%patch $B60A  [$101AW]
%patch $B611  [$1038W]

#Keen go to falling after...
%patch $31DDE [$101AW] #...shooting horizontally in air
%patch $31E38 [$101AW] #...shooting up in air
%patch $31E92 [$101AW] #...shooting down in air


Disable shooting while jumping

This patch stops Keen from shooting while jumping\falling. (See also Patch:Keen shooting (Galaxy).) Keen can still shoot while doing other things.

Disable shooting while jumping

#Disable shooting while jumping -Keen 4
%patch $C462 $EB


Sprite Behavior

There is only one behavior relating to Keen jumping which is also used when he is falling. It may best be considered a 'Keen in the air' behavior.

Keen 4 behaviors

#Jumping
%patch $2FFE6 $0B800B5BRL
%patch $30004 $0B800B5BRL

#Falling
%patch $30022 $0B800B5BRL
%patch $30040 $0B800B5BRL

Keen 5 behaviors

#Jumping
%patch $31394 $0AAF0C89RL
%patch $313B2 $0AAF0C89RL

#Falling
%patch $313D0 $0AAF0C89RL
%patch $313EE $0AAF0C89RL

Keen 6 behaviors

#Jumping
%patch $31D1E $0AA20B3CRL
%patch $31D3C $0AA20B3CRL

#Falling
%patch $31D5A $0AA20B3CRL
%patch $31D78 $0AA20B3CRL


Behavior code

This is the complete code for Keen jumping or falling. The first line checks to see if Keen is jumping. First Keen's jump timer is checked, if zero Keen's jump status is checked. If also zero Keen's jump speed (upwards) is set, his jump timer is set to $12 and his jump status set to 1.

On line 3 Keen's jump variable is checked. If not zero it is compared to the last keypress and Keen's horizontal position is changed, allowing him to move left or right. On line 6 Keen's jump timer is checked again, if not zero the current keypress is stored as the jump variable

On line 7 Keen's 'old jump status' is checked, if zero Keen's jump timer is set to 0. On line line 8 Keen's jump timer is checked, if zero Keen's next action is checked, if zero, as is the case with Keen's jumping (But not falling) actions then Keen's action is moved to the next in its sequence. This lets Keen progress through his jump sequence despite using type 2 actions.See action type section below.)

On line 9 the game checks Keen's jump cheat status, if enabled then a special jump subroutine is run, allowing Keen to fly through the air. Otherwise a simple falling subroutine is called. On line 11 the game checks if Keen is using either of his falling actions, if not Keen's actions are changed to the next in his cycle. The net result of this is that Keen's falling actions are exempt, animating at their own pace rather than relying on jump speed.

On line 13 Keen's horizontal direction is checked, if Keen is moving horizontally then his direction plus a jump height of $18 are used in jump code, otherwise a straight upwards jump occurs. (his code is only run when Keen starts jumping.) On line 15 Keen's 'touching floor' variable is checked, if $11 then Keen's vertical speed is set to 0. The reason for this is currently unknown.

On line 16 the code checks to see if the shooting key is being pressed, if so the code checks to see if Keen is already shooting, if not his shooting variable is set to 1. On line 18 his vertical aiming direction is checked, up and down shooting jump to the next section,otherwise his action is changed to upwards shooting. In the next two sections Keen's action is set to horizontal and downwards shooting respectively.

In the fourth section the same procedure occurs with respect to pogoing, a key check, an already pogoing check and setting the pogoing status to 1. keen's action is then set to pogoing in air and his jump timer set to 0 (he falls).

The final section checks Keen's vertical aim and if he is pressing up runs the 'grab poles' code that will let him grab a pole if one is available.

Keen 4 jump\fall code

#Keen jumping sprite behavior
%patch $C35B $55 $8B $EC $56 $8B $76 $06 $83 $3E {$C62BW}  [$00] {$74} $18 $83 $3E #Check jump
             {$C5C9W}  [$00] {$74} $11 $C7 $44 $18 [$FFD8W]  $C7 $06 {$CABBW}  [$0012W] #Set jump
             $C7 $06 {$C5C7W}  [$0001W]  $83 $3E {$CABBW}  [$00] {$74} $5D $A1 {$CABBW} #Check variable
             $3B $06 {$A54CW}  {$77} $12 $8B $44 $18 $F7 $2E {$CABBW}  $A3 {$C921W} #Move horizontal
             $C7 $06 {$CABBW}  [$0000W]  $EB $1B $8B $44 $18 $F7 $2E {$A54CW}  $A3
             {$C921W}  $83 $3E {$C62BW}  [$00] {$75} $0A $A1 {$CABBW}  $2B $06 {$A54CW} 
             $A3 {$CABBW}  $83 $3E {$C5C9W}  [$00] {$75} $06 $C7 $06 {$CABBW}  [$0000W] #Check old_jump
             $83 $3E {$CABBW}  [$00] {$75} $4B $8B $5C $1C $83 $7F $1C [$00] {$74} $42
             $8B $47 $1C $89 $44 $1C $EB $3A $EB $38 $83 $3E {$7A6CW}  [$01] {$75} #Jumpcheat check
             $0B $56 $9A $09DC1315RL     $83 $C4 $02 $EB $09 $56 $9A $09DC1296RL
%patch $C43B         $83 $C4 $02 $83 $7C {$18} [$00] {$7E} $17 $81 $7C $1C [$11A2W]
             {$74} $10 $81 $7C $1C [$11C0W]  {$74} $09 $8B $5C $1C $8B $47 $1C $89 #Check falling acts
             $44 $1C $83 $3E {$A7CEW}  [$00] {$74} $1B $A1 {$A7CEW}  $89 $44 $0E $B8
             [$0018W]  $50 $A1 {$A7CEW}  $D1 $E0 $50 $56 $9A $09DC13FERL     $83 #Jump height
             $C4 $06 $EB $09 $56 $9A $09DC158FRL     $83 $C4 $02 $83 $7C {$3A} #Check touch_floor
             [$11] {$75} $08 $33 $C0 $A3 {$C923W}  $89 $44 $16 $83 $3E {$C5C1W}  [$00] #Check shootkey
             {$74} $38 $83 $3E {$C5BFW}  [$00] {$75} $31 $C7 $06 {$C5BFW}  [$0001W]  $A1 #Check if shooting
             {$A7D0W}  $3D [$FFFFW]  {$74} $0B $0B $C0 {$74} $0F $3D [$0001W]  {$74} $12 #Check vertical aim, shoot up
             $EB $18 $C7 $44 $1C [$1238W]  $5E $5D $CB
                                                     $C7 $44 $1C [$11DEW]  $5E #Shoot horizontal
             $5D $CB
                     $C7 $44 $1C [$1292W]  $5E $5D $CB			     #Shoot down
                                                     $83 $3E {$C5C5W}  [$00] {$74} #Check Pogo key
             $1B $83 $3E {$C5C3W}  [$00] {$75} $14 $C7 $06 {$C5C3W}  [$0001W]  $C7 $44
             $1C [$112AW]  $C7 $06 {$CABBW}  [$0000W]  $5E $5D $CB
                                                             $83 $3E {$A7D0W} #Grab poles
             [$FF] {$75} $08 $56 $0E $E8 $F38FW  $83 $C4 $02 $5E $5D $CB


Speed and Jump Height

Keen's jump speeds and heights are controlled in a complex way discussed below. The action speeds are not used.

Keen 4 action speeds

#Jumping
%patch $2FFE2 [$0000W $0000W]
%patch $30000 [$0000W $0000W]

#Falling
%patch $3001E [$0000W $0000W]
%patch $3003C [$0000W $0000W]

Keen 5 action speeds

#Jumping
%patch $31390 [$0000W $0000W]
%patch $313AE [$0000W $0000W]

#Falling
%patch $313CC [$0000W $0000W]
%patch $313EA [$0000W $0000W]

Keen 6 action speeds

#Jumping
%patch $31D1A [$0000W $0000W]
%patch $31D38 [$0000W $0000W]

#Falling
%patch $31D56 [$0000W $0000W]
%patch $31D74 [$0000W $0000W]


Jump height

There are three situations where Keen can jump, when standing still, when walking and when on poles. In each situation there are two variables that control his jump height, speed and duration. Speed is how fast Keen jumps while duration is how long he can jump before he slows down and starts falling. Keen can thus be made to jump twice as high by doubling his speed or his duration. (Increasing duration looks more 'natural', fast jumps tend to look jerky.)

A more thorough discussion of this is given below.

Keen 4 Jumping Physics

#Jump from standstill
%patch $BAF0 [$FFD8W]				#Starting speed
%patch $BAFC [$0012W]				#Duration

#Jump from walking
%patch $BF0A [$FFD8W]				#Starting speed
%patch $BF18 [$0012W]				#Duration

#Jump from a pole
%patch $C6AB [$FFECW]				#Starting speed
%patch $C6B6 [$000AW]				#Duration

Keen 5 Jumping Physics

#Jump from standstill
%patch $AEB8 [$FFD8W]				#Starting speed
%patch $AEC4 [$0012W]				#Duration

#Jump from walking
%patch $B2CF [$FFD8W]				#Starting speed
%patch $B2DD [$0012W]				#Duration

#Jump from a pole
%patch $BAC9 [$FFECW]				#Starting speed
%patch $BAD4 [$000AW]				#Duration

Keen 6 Jumping Physics

#Jump from standstill
%patch $AD06 [$FFD8W]				#Starting speed
%patch $AD12 [$0012W]				#Duration

#Jump from walking
%patch $B10B [$FFD8W]				#Starting speed
%patch $B119 [$0012W]				#Duration

#Jump from a pole
%patch $B8AC [$FFECW]				#Starting speed
%patch $B8B7 [$000AW]				#Duration


Details

The duration can be considered a 'timer' that counts down. When it reaches zero Keen will experience gravity. However, if the jump or pogo button is released, then Keen will start to feel gravity even if the timer has not expired. The timer is measured in tics (70 Hz), so a timer of 70 means that Keen can jump upwards for 1 second before feeling gravity. The initial velocity is in map units per tic, which is 256ths of a tile per 70th of a second.

The jump can thus be divided into three 'phases'. The first, linear' phase is when Keens tarts jumping. He moves at a constant speed for a certain time and ignores gravity. The second, curve phase is when he starts to slow down and then fall. The third, fall, phase is exactly what it sounds like.

A jumps' total height can thus be roughly calculated as follows: H = -VT/16 + 1.09^-V where H is height in pixels, V is the velocity (Speed) and T is the time. (This is not totally accurate as the game implements gravity somewhat haphazardly.) As an example Keen's default jump has T=18 and V=40 giving total jump height of 18*40/16 + 1.09^40 = 720/16 + 31 = 45 + 31 = 76 pixels in height. This is about 4.75 tiles.

In practice Keen will jump slightly higher than this and it is best to fine tune jump heights by first setting the timer and then tweaking the speed.


Keen can jump as high as he wants

This patch allows Keen to jump as if he has the F10 J cheat on all the time. The F10 J cheat will still work, but will not change anything. The second line allows Keen to hit ceilings and not fall. Removing this line makes Keen act like the jump cheat in keen Dreams.

Keen 5

#Keen has no max jump height
%patch $C3B2 $EB $0A
%patch $D49D $EB $30 #And don't hit ceilings


Head bump speeds

These patches control what happens to Keen's vertical speed when he hits his head on ceilings. The first value is a 'downward push' that reduces Keen's vertical speed when he first hits a ceiling. If this is not enough to make him move downwards two other values set his speed to zero. The net effect of this is that if Keen hits his head on a ceiling he'll either stop in midair a moment or be knocked down slightly.

Keen 4

#Keen's vertical speed when hitting ceilings while jumping
%patch $D4B4 [$10]    #Downwards bump
%patch $D4BE [$0000W] #Halt 1
%patch $D4C7 [$0000W] #Halt 2

Keen 5

#Keen's vertical speed when hitting ceilings while jumping
%patch $C7C8 [$10]    #Downwards bump
%patch $C7D2 [$0000W] #Halt 1
%patch $C7DB [$0000W] #Halt 2

Keen 6

#Keen's vertical speed when hitting ceilings while jumping
%patch $C5C0 [$10]    #Downwards bump
%patch $C5CA [$0000W] #Halt 1
%patch $C5D3 [$0000W] #Halt 2


Fix repeated headbump glitch

This (mostly pointless) patch fixes a glitch that occurs when the player jumps up and into a sloped ceiling. This can cause Keen's head to bump repeatedly. This patch prevents this, which is barely noticeable. The first blue variable is the bump-head sound, the second Keen's downward push when hitting his head on slopes and the third his halted speed if this is not enough.

Fix repeated headbump glitch

#Fix repeated headbump glitch -Keen 4
%patch $D49F $83 $3E $CABBW  $00 $74 $0C $B8 [$000FW]  $50 $9A $187409F1RL    
             $83 $C4 $02 $83 $7C $3A $01 $7E $0A $83 $44 $18 [$10] $83 $7C $18
             $00 $7D $05 $C7 $44 $18 [$0000W]  $C7 $06 $CABBW  $0000W  $90 $90


Sprite Collision

Keen uses his primary sprite collision when jumping and falling. This is the one that allows him to interact with point items and sprites such as Princess Lindsey.

Keen 4 sprite collisions

#Keen jumping
%patch $32DEA $0B8014A9RL
%patch $32E08 $0B8014A9RL

#Keen falling
%patch $32E26 $0B8014A9RL
%patch $32E44 $0B8014A9RL

Keen 5 sprite collisions

#Keen jumping
%patch $31398 $0AAF1597RL
%patch $313B6 $0AAF1597RL

#Keen falling
%patch $313D4 $0AAF1597RL
%patch $313F2 $0AAF1597RL

Keen 6 sprite collisions

#Keen jumping
%patch $31D22 $0AA2144ARL
%patch $31D40 $0AA2144ARL

#Falling
%patch $31D5E $0AA2144ARL
%patch $31D7C $0AA2144ARL


Animations

Keen uses two animations when jumping and two different animations when falling. Note that Keen's jump animations do not animate in the usual way, being controlled by code, but his falling animations do. Note also that Keen's falling animations have two slightly different animation speeds.

Keen 4

#Jumping
%patch $2FFD6 $008FW $0087W
%patch $2FFE0 $0000W
%patch $2FFF4 $0090W $0088W
%patch $2FFFE $0000W

#Falling
%patch $30012 $0091W $0089W
%patch $3001C $0032W
%patch $30030 $0090W $0088W
%patch $3003A $0028W

Keen 5

#Jumping
%patch $31384 $0079W $0071W
%patch $3138E $0000W
%patch $313A2 $007AW $0072W
%patch $313AC $0000W

#Falling
%patch $313C0 $007BW $0073W
%patch $313CA $0032W
%patch $313DE $007AW $0072W
%patch $313E8 $0028W

Keen 6

#Jumping
%patch $31D0E $0041W $0039W
%patch $31D18 $0000W
%patch $31D2C $0042W $003AW
%patch $31D36 $0000W

#Falling
%patch $31D4A $0043W $003BW
%patch $31D54 $0032W
%patch $31D68 $0042W $003AW
%patch $31D72 $0028W


Sounds

There are a number of sounds associated with Keen jumping and falling. There are three jumping sounds, one for jumping when standing, one for jumping when walking and one for jumping off of poles.

There are also five falling sounds, the first is for when Keen 'falls out of levels'; it is not heard because Keen's death sound immediately overwrites it. The second sound is for when Keen is standing and the ground beneath him vanishes, letting him fall. The third sound is for when Keen walks off of flat ground. The final two sounds are for when Keen falls off of pole tops and bottoms.

A sound is made when Keen hits his head while jumping, as well as when falling Keen lands on ground or other support.

Keen 4 sounds

#Jump sounds
%patch $BADD $02 #Keen jumps straight up sound
%patch $BEF2 $02 #Keen jumps while walking sound
%patch $C690 $02 #Keen jump off pole sound

#Fall sounds
%patch $86EE $14     #Keen fall out of levels sound
%patch $D2B0 $14     #Keen fall when standing and ground vanishes sound
%patch $D36D $14     #Keen walks off of edges and falls sound
%patch $C76A $14     #Keen move l/r off a pole top sound
%patch $C86B $14     #Keen moves of pole end sound

#Head-hitting sound
%patch $D4A0 $0F     #Keen jumping hits head sound

#Landing sound
%patch $D557 $03     #Keen lands on ground sound

#Block sounds
%patch $BADC $EB $0A #Don't play Keen jumps straight up sound
%patch $BEF1 $EB $0A #Don't play Keen jumps while walking sound
%patch $C68F $EB $0A #Don't play Keen jump off pole sound
%patch $86ED $EB $0A #Don't play Keen fall out of levels sound
%patch $D2AF $EB $0A #Don't play Keen fall when standing and ground vanishes sound
%patch $D36C $EB $0A #Don't play Keen walks off of edges and falls sound
%patch $C769 $EB $0A #Don't play Keen move l/r off a pole top sound
%patch $C86A $EB $0A #Don't play Keen moves of pole end sound
%patch $D49F $EB $0A #Don't play Keen jumping hits head sound
%patch $D556 $EB $0A #Don't play Keen lands on ground sound

Keen 5 sounds

#Jump sounds
%patch $AEA5 $02 #Keen jumps straight up sound
%patch $B2B7 $02 #Keen jumps while walking sound
%patch $BAAE $02 #Keen jump off pole sound

#Fall sounds
%patch $866A $14     #Keen fall out of levels sound
%patch $C5C4 $14     #Keen fall when standing and ground vanishes sound
%patch $C681 $14     #Keen walks off of edges and falls sound
%patch $BB88 $14     #Keen move l/r off a pole top sound
%patch $BC89 $14     #Keen moves of pole end sound

#Head-hitting sound
%patch $C7B4 $0F     #Keen jumping hits head sound

#Landing sound
%patch $C87D $03     #Keen land on ground sound

#Block sounds
%patch $AEA4 $EB $0A #Don't play Keen jumps (straight up) sound
%patch $B2B6 $EB $0A #Don't play Keen jumps while walking sound
%patch $BAAD $EB $0A #Don't play Keen jump off pole sound
%patch $8669 $EB $0A #Don't play Keen fall out of levels sound
%patch $C5C3 $EB $0A #Don't play fall when standing and ground vanishes sound
%patch $C680 $EB $0A #Don't play Keen walks off of edges and falls sound
%patch $BB87 $EB $0A #Don't play Keen move l/r off a pole top sound
%patch $BC88 $EB $0A #Don't play Keen moves of pole end sound
%patch $C7B3 $EB $0A #Don't play Keen jumping hits head sound
%patch $C87C $EB $0A #Don't play Keen land on ground sound

Keen 6 sounds

#Jump sounds
%patch $ACF3 $02 #Keen jumps straight up sound
%patch $B0F3 $02 #Keen jumps while walking sound
%patch $B891 $02 #Keen jump off pole sound

#Fall sounds
%patch $8495 $14     #Keen fall out of levels sound
%patch $C3AA $14     #Keen fall when standing and ground vanishes sound
%patch $C467 $14     #Keen walks off of edges and falls sound
%patch $B96B $14     #Keen move l/r off a pole top sound
%patch $BA6C $14     #Keen moves of pole end sound

#Head-hitting sound
%patch $C5AC $0F     #Keen jumping hits head sound

#Landing sound
%patch $C676 $03     #Keen land on ground sound

#Block sounds
%patch $ACF2 $EB $0A #Don't play Keen jumps (straight up) sound
%patch $B0F2 $EB $0A #Don't play Keen jumps while walking sound
%patch $B890 $EB $0A #Don't play Keen jump off pole sound
%patch $8494 $EB $0A #Don't play Keen fall out of levels sound
%patch $C3A9 $EB $0A #Don't play Keen fall when standing and ground vanishes sound
%patch $C466 $EB $0A #Don't play Keen walks off of edges and falls sound
%patch $B96A $EB $0A #Don't play Keen move l/r off a pole top sound
%patch $BA6B $EB $0A #Don't play Keen moves of pole end sound
%patch $C5AB $EB $0A #Don't play Keen jumping hits head sound
%patch $C675 $EB $0A #Don't play Keen land on ground sound


Sprite-tile interaction

Keen uses a special 'Keen in air' tile collision when jumping and falling. This lets him hit his head on ceilings as well as land on solid ground. It is also used by his shooting in the air actions

Keen 4 tile collisions

#Jumping
%patch $2FFEE $0B801C48RL
%patch $3000C $0B801C48RL

#Falling
%patch $3002A $0B801C48RL
%patch $30048 $0B801C48RL

Keen 5 tile collisions

#Jumping
%patch $3139C $0AAF1C6CRL
%patch $313BA $0AAF1C6CRL

#Falling
%patch $313D8 $0AAF1C6CRL
%patch $313F6 $0AAF1C6CRL

Keen 6 tile collisions

#Jumping
%patch $31D26 $0AA21B22RL
%patch $31D44 $0AA21B22RL

#Falling
%patch $31D62 $0AA21B22RL
%patch $31D80 $0AA21B22RL


Interaction code

This is the complete tile interaction code for Keen jumping and falling, as well as several other 'in air' actions.. The first two lines check to see if Keen is touching a left or right wall while facing it. If he is then his horizontal speed is set to 0. (If he is not facing the wall there is no reason to stop him moving.)

At the end of line 3 ceilings are checked for. If a ceiling is present then the ceiling type 'pole going through' is checked for; this is something Keen can pogo past. These set Keen's horizontal speed is to 0 and his vertical direction and speed to $20 (downwards). 'Normal' ceilings check an unknown variable (probably related to whether Keen is moving upwards towards the ceiling.) and play sound $0F if it is not 0. Following this $10 is added to Keen's vertical speed, which is checked to see if it is still positive. In all cases Keen's vertical speed is then set to 0, along with some other variable.

Floors are checked for on line 9 and this is the most complex section of code. If found on line 10 Keen's x-speed per frame is set to 0. Another unknown check occurs and on line 11 a check for whether Keen is touching a platform. Both checks cause the rest of the code to be skipped if passed.

Floors are checked for on line 9. If found Keen's x-speed per frame is set to 0 on line 10. After this Keen's location is tweaked by -8 pixels and floor type is checked for. Type 8 is lethal to Keen, if found the 'kill Keen' code is run and everything else skipped. Type 19 (set when Keen is on Platform-type sprites)skips Keen's jump timer check, letting him do interesting jumping tricks with them. For 'normal floors' the game checks to see if Keen's jump timer is 0, if so, Keen's bored variables are set to 0.

On line 13 the code checks to see if Keen is trying to shoot in the air, if so his action changes to shooting on the ground. On line 14 an identical check is made for Keen shooting upwards in the air. On line 15 the game checks if Keen is moving left or right, if so his action changes to his first walking action, if not his standing action. Sound $3 is then played. In sum these actions make Keen land on the ground, smoothy continuing whatever action he was performing in the air.

The remaining code deals with grabbing ledges and mostly consists of a large number of checks to see if he can. The first check, on line 19, is to see if Keen is moving horizontally.

Keen 4 falling Keen tile interactions

#Keen 4 falling Keen tile interaction
%patch $D448 $55 $8B $EC $83 $EC $0A $56 $57 $8B $76 $06 $83 $7C $38 [$00] {$74}
             $06 $83 $7C {$0E} [$FF] {$74} $0C $83 $7C $3C [$00] {$74} $0B $83 $7C {$0E}
             [$01] {$75} $05 $C7 $44 $16 [$0000W]  $83 $7C $3A [$00] {$74} $59 $83 $7C
             $3A [$11] {$75} $1C $83 $6C $0C $20 $83 $6C $24 $20 $C7 $44 $16 [$0000W]
                 $8B $44 $34 $B1 $08 $D3 $E0 $2D [$0020W]  $89 $44 $0A $EB $37
             $83 $3E {$C62BW}  [$00] {$75} $30 $B8 [$000FW]  $50 $9A $187409F1RL   
             $83 $C4 $02 $83 $7C $3A [$01] {$7E} $13 $83 $44 $18 $10 $83 $7C $18
%patch $D4B8 [$00] {$7D} $0E $C7 $44 $18 [$0000W] $EB $07 $EB $05 $C7 $44 $18 [$0000W]
                 $C7 $06 {$CABBW}  [$0000W]  $83 $7C $36 [$00] {$75} $03 $E9 $0090W 
             $C7 $44 $14 [$0000W]  $8B $44 $36 $25 [$FFF8W]  $3D [$0008W]  {$75} $07
             $0E $E8 $F6FDW  $E9 $026FW  $83 $7C $36 [$19] {$75} $0A $83 $3E $CABBW
                 [$00] {$74} $03 $E9 $025FW  $33 $C0 $89 $44 {$40} $89 $44 {$3E} $81
             $7C $1C [$11DEW]  {$75} $0F $B8 [$0D6AW]  $50 $56 $9A $09DC120ARL   
             $83 $C4 $04 $EB $39 $81 $7C $1C [$1238W]  {$75} $0F $B8 [$0DA6W]  $50
%patch $D528 $56 $9A $09DC120ARL     $83 $C4 $04 $EB $23 $83 $3E {$A7CEW}  [$00]
             {$74} $0F $B8 [$1094W]  $50 $56 $9A $09DC120ARL     $83 $C4 $04 $EB
             $0D $B8 [$098CW]  $50 $56 $9A $09DC120ARL     $83 $C4 $04 $B8 [$0003W]
                 $50 $9A $187409F1RL     $83 $C4 $02 $E9 $01F9W  $E9 $01F6W 
             $83 $7C {$14} [$00] {$7F} $03 $E9 $01EDW  $8B $44 $24 $2B $44 $14 $89
             $46 $FA $8B $44 $24 $2D $40 $00 $25 $00 $FF $05 $40 $00 $89 $46
             $F8 $B1 $08 $D3 $E8 $8948W  $46 $F6 $8B $46 $FA $3B $46 $F8 $72
%patch $D598 $03 $E9 $01C2W  $8B $44 $24 $3B $46 $F8 $73 $03 $E9 $01B7W  $83
             $3E $CE $A7 $FF $74 $03 $E9 $00DCW  $8B $5E $F6 $D1 $E3 $8B $87
             $25 $C9 $D1 $E8 $E0D1W  $8B $16 $E9 $8BA7W  $5C $2C $D1 $E3 $03
             $C3 $89 $56 $FE $89 $46 $FC $83 $7C $38 $00 $74 $04 $83 $6E $FC
             $02 $C4 $5E $FC $26 $8B $3F $8E $06 $A1 $C8 $26 $8A $85 $16 $17
             $B4 $00 $0B $C0 $74 $03 $E9 $016DW  $26 $8A $85 $DE $2D $B4 $00
             $0B $C0 $74 $03 $E9 $015FW  $26 $8A $85 $B2 $0B $B4 $00 $0B $C0
%patch $D608 $74 $03 $E9 $0151W  $26 $8A $85 $7A $22 $B4 $00 $0B $C0 $74 $03
             $E9 $0143W  $A1 $E4 $A7 $D1 $E0 $8E $46 $FE $03 $D8 $26 $8B $1F
             $8E $06 $A1 $C8 $26 $80 $BF $16 $17 $00 $75 $03 $E9 $0127W  $A1
             $E4 $A7 $D1 $E0 $C4 $5E $FC $03 $D8 $26 $8B $1F $8E $06 $A1 $C8
             $26 $80 $BF $B2 $0B $00 $75 $03 $E9 $010BW  $C7 $44 $0E $FF $FF
             $C7 $44 $06 $00 $00 $8B $44 $0A $25 $00 $FF $05 $80 $00 $89 $44
             $0A $8B $46 $F8 $2D $40 $00 $89 $44 $0C $33 $C0 $89 $44 $14 $89
%patch $D678 $44 $18 $B8 $12ECW  $50 $56 $9A $09DC120ARL     $83 $C4 $04 $E9
             $00D4W  $E9 $00D1W  $83 $3E $CE $A7 $01 $74 $03 $E9 $00C7W  $8B
             $5E $F6 $D1 $E3 $8B $87 $25 $C9 $D1 $E8 $E0D1W  $8B $16 $E9 $8BA7W
                 $5C $30 $D1 $E3 $03 $C3 $89 $56 $FE $89 $46 $FC $83 $7C $3C
             $00 $74 $04 $83 $46 $FC $02 $C4 $5E $FC $26 $8B $3F $8E $06 $A1
             $C8 $26 $8A $85 $16 $17 $B4 $00 $0B $C0 $74 $03 $E9 $0087W  $26
             $8A $85 $DE $2D $B4 $00 $0B $C0 $75 $7C $26 $8A $85 $B2 $0B $B4
%patch $D6E8 $00 $0B $C0 $75 $71 $26 $8A $85 $7A $22 $B4 $00 $0B $C0 $75 $66
             $A1 $E4 $A7 $D1 $E0 $8E $46 $FE $03 $D8 $26 $8B $1F $8E $06 $A1
             $C8 $26 $80 $BF $DE $2D $00 $74 $4D $A1 $E4 $A7 $D1 $E0 $C4 $5E
             $FC $03 $D8 $26 $8B $1F $8E $06 $A1 $C8 $26 $80 $BF $B2 $0B $00
             $74 $34 $C7 $44 $0E $01 $00 $C7 $44 $06 $00 $00 $8B $44 $0A $25
             $00 $FF $05 $00 $01 $89 $44 $0A $8B $46 $F8 $2D $40 $00 $89 $44
             $0C $33 $C0 $89 $44 $14 $89 $44 $18 $B8 $12ECW  $50 $56 $9A
         $09DC120ARL     $83 $C4 $04 $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF
             $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16541641RL   
             $83 $C4 $0C $5F $5E $8B $E5 $5D $CB

Keen 5 falling Keen tile interactions

#Keen 5 falling Keen tile interaction
%patch $C75C $55 $8B $EC $83 $EC $0A $56 $57 $8B $76 $06 $83 $7C $38 [$00] {$74}
             $06 $83 $7C {$0E} [$FF] {$74} $0C $83 $7C $3C [$00] {$74} $0B $83 $7C {$0E}
             [$01] {$75} $05 $C7 $44 $16 [$0000W]  $83 $7C $3A [$00] {$74} $59 $83 $7C
             $3A  [$11] {$75} $1C $83 $6C $0C $20 $83 $6C $24 $20 $C7 $44 $16 [$0000W]
                 $8B $44 $34 $B1 $08 $D3 $E0 $2D [$0020W]  $89 $44 $0A $EB $37
             $83 $3E {$BC93W}  [$00] {$75} $30 $B8 [$000FW]  $50 $9A $196E09EFRL   
             $83 $C4 $02 $83 $7C $3A [$01] {$7E} $13 $83 $44 $18 $10 $83 $7C $18
%patch $C7CC [$00] {$7D} $0E $C7 $44 $18 [$0000W]  $EB $07 $EB $05 $C7 $44 $18 [$0000W]
                 $C7 $06 [$C181W]  [$0000W]  $83 $7C $36 [$00] {$75} $03 $E9 $00A2W 
             $C7 $44 $14 [$0000W]  $8B $44 $36 $25 [$FFF8W]  $3D [$0008W]  {$75} $07
             $0E $E8 $F807W  $E9 $0281W  $83 $7C $36 [$39] {$75} $0C $B8 [$0039W]
             $50 $9A $196E09EFRL     $83 $C4 $02 $83 $7C $36 [$19] {$75} $0A $83
             $3E {$C181W}  [$00] {$74} $03 $E9 $025FW  $33 $C0 $89 $44 $40 $89 $44
             $3E $81 $7C $1C [$10BCW]  {$75} $0F $B8 [$0BEEW]  $50 $56 $9A $090B1242RL
%patch $C83E         $83 $C4 $04 $EB $39 $81 $7C $1C [$1116W]  {$75} $0F $B8 [$0C2AW]
                 $50 $56 $9A $090B1242RL     $83 $C4 $04 $EB $23 $83 $3E {$9E36W}
                 [$00] {$74} $0F $B8 [$0F72W]  $50 $56 $9A $090B1242RL     $83 $C4
             $04 $EB $0D $B8 [$0888W]  $50 $56 $9A $090B1242RL     $83 $C4 $04
             $B8 [$0003W]  $50 $9A $196E09EFRL     $83 $C4 $02 $E9 $01F9W  $E9
             $01F6W  $83 $7C {$14} [$00] {$7F} $03 $E9 $01EDW  $8B $44 $24 $2B $44
             $14 $89 $46 $FA $8B $44 $24 $2D $40 $00 $25 $00 $FF $05 $40 $00
%patch $C8AC $89 $46 $F8 $B1 $08 $D3 $E8 $8948W  $46 $F6 $8B $46 $FA $3B $46
             $F8 $72 $03 $E9 $01C2W  $8B $44 $24 $3B $46 $F8 $73 $03 $E9 $01B7W
                 $83 $3E $36 $9E $FF $74 $03 $E9 $00DCW  $8B $5E $F6 $D1 $E3
             $8B $87 $87 $BF $D1 $E8 $E0D1W  $8B $16 $51 $9E $8B $5C $2C $D1
             $E3 $03 $C3 $89 $56 $FE $89 $46 $FC $83 $7C $38 $00 $74 $04 $83
             $6E $FC $02 $C4 $5E $FC $26 $8B $3F $8E $06 $61 $BF $26 $8A $85
             $EA $18 $B4 $00 $0B $C0 $74 $03 $E9 $016DW  $26 $8A $85 $FA $2F
%patch $C91C $B4 $00 $0B $C0 $74 $03 $E9 $015FW  $26 $8A $85 $62 $0D $B4 $00
             $0B $C0 $74 $03 $E9 $0151W  $26 $8A $85 $72 $24 $B4 $00 $0B $C0
             $74 $03 $E9 $0143W  $A1 $4C $9E $D1 $E0 $8E $46 $FE $03 $D8 $26
             $8B $1F $8E $06 $61 $BF $26 $80 $BF $EA $18 $00 $75 $03 $E9 $0127W
                 $A1 $4C $9E $D1 $E0 $C4 $5E $FC $03 $D8 $26 $8B $1F $8E $06
             $61 $BF $26 $80 $BF $62 $0D $00 $75 $03 $E9 $010BW  $C7 $44 $0E
             $FF $FF $C7 $44 $06 $0000W  $8B $44 $0A $25 $00 $FF $05 $80 $00
%patch $C98C $89 $44 $0A $8B $46 $F8 $2D $40 $00 $89 $44 $0C $33 $C0 $89 $44
             $14 $89 $44 $18 $B8 $11CAW  $50 $56 $9A $090B1242RL     $83 $C4
             $04 $E9 $00D4W  $E9 $00D1W  $83 $3E $36 $9E $01 $74 $03 $E9 $00C7W
                 $8B $5E $F6 $D1 $E3 $8B $87 $87 $BF $D1 $E8 $E0D1W  $8B $16
             $51 $9E $8B $5C $30 $D1 $E3 $03 $C3 $89 $56 $FE $89 $46 $FC $83
             $7C $3C $00 $74 $04 $83 $46 $FC $02 $C4 $5E $FC $26 $8B $3F $8E
             $06 $61 $BF $26 $8A $85 $EA $18 $B4 $00 $0B $C0 $74 $03 $E9 $0087W
%patch $C9FD     $26 $8A $85 $FA $2F $B4 $00 $0B $C0 $75 $7C $26 $8A $85 $62
             $0D $B4 $00 $0B $C0 $75 $71 $26 $8A $85 $72 $24 $B4 $00 $0B $C0
             $75 $66 $A1 $4C $9E $D1 $E0 $8E $46 $FE $03 $D8 $26 $8B $1F $8E
             $06 $61 $BF $26 $80 $BF $FA $2F $00 $74 $4D $A1 $4C $9E $D1 $E0
             $C4 $5E $FC $03 $D8 $26 $8B $1F $8E $06 $61 $BF $26 $80 $BF $62
             $0D $00 $74 $34 $C7 $44 $0E $01 $00 $C7 $44 $06 $0000W  $8B $44
             $0A $25 $00 $FF $05 $00 $01 $89 $44 $0A $8B $46 $F8 $2D $40 $00
             $89 $44 $0C $33 $C0 $89 $44 $14 $89 $44 $18 $B8 $11CAW  $50 $56
             $9A $090B1242RL     $83 $C4 $04 $FF $74 $20 $33 $C0 $50 $FF $74
             $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $174E163ERL
                     $83 $C4 $0C $5F $5E $8B $E5 $5D $CB


Action type

Keen's jumping actions are type 2, responding only to their own code and having no animation speed. His falling actions are type 3, which is similar but has its own animation speed.

Keen 4

#Keen jumping
%patch $2FFDA [$0002W]
%patch $2FFF8 [$0002W]

#Keen falling
%patch $30016 [$0003W]
%patch $30034 [$0003W]

Keen 5

#Keen jumping
%patch $31388 [$0002W]
%patch $313A6 [$0002W]

#Keen falling
%patch $313C4 [$0003W]
%patch $313E2 [$0003W]

Keen 6

#Keen jumping
%patch $31D12 [$0002W]
%patch $31D30 [$0002W]

#Falling
%patch $31D4E [$0003W]
%patch $31D6C [$0003W]


Deprotect and stick to ground

Jumping and falling Keen does not need to use either of these variables.

Keen 4

#Jumping
%patch $2FFDC [$0000W $0000W]
%patch $2FFFA [$0000W $0000W]

#Falling
%patch $30018 [$0000W $0000W]
%patch $30036 [$0000W $0000W]

Keen 5

#Jumping
%patch $3138A [$0000W $0000W]
%patch $313A8 [$0000W $0000W]

#Falling
%patch $313C6 [$0000W $0000W]
%patch $313E4 [$0000W $0000W]

Keen 6

#Jumping
%patch $31D14 [$0000W $0000W]
%patch $31D32 [$0000W $0000W]

#Falling
%patch $31D50 [$0000W $0000W]
%patch $31D6E [$0000W $0000W]