Patch:Keen walking (Dreams)

From KeenWiki
Jump to navigation Jump to search

This page contains patches that relate to the player walking and under what conditions the player starts and stops doing so. This page also covers patches relating to Keen standing still as these are closely related. It does not cover patches relating to Keen being bored, mooning or other actions where he doesn't move.

Other patches relating to Keen can be found under Keen (Keen 4), Keen (Keen 5), Keen (Keen 6) and Keen (Keen Dreams). Patches for Keen's walking in Vorticons and Galaxy have their own pages.


Sprite Actions

Keen is spawned standing when he first starts a level. While standing he continues to stand as long as nothing else happens. When arrow keys are pressed, standing Keen will start walking. If he attempts to walk into a wall he will be set to standing.

Keen's walk cycle is four actions long, when the arrow keys are no longer pressed he will revert to standing.

Keen will revert to his standing action under a wide variety of circumstances since it is the most basic thing he can do. There are no less than five situations where this happens. The first is when Keen walks into solid walls; this stops him moving entirely. The second and third situations happen in his standing\walking code and make him stand if no keys are pressed. The fourth situation is when he stop looking down. The fifth is when Keen lands on the ground after falling through the air.

Keen will also automatically return to his standing action after performing certain other actions. No less than four of these occur after Keen's various bored sequences. Another two occur after Keen has thrown a Flower Power while standing on the ground. Finally there are two situations after Keen has jumped/fallen. (These aren't in fact used as the above mentioned 'land on ground' code overrides them.)

Actions:
$0ED8W #Keen stand
$1388W #Keen walk 1
$13A6W #Keen walk 2
$13C4W #Keen walk 3
$13E2W #Keen walk 4

Keen Dreams

#Spawn Keen -standing
%patch $6BB5  [$0ED8W]

#Keen standing Keen keeps standing
%patch $24964 [$0ED8W]

#Start walking when arrows pressed
%patch $6CB6  [$1388W]

#Keen's walk loop
%patch $24E14 [$13A6W]
%patch $24E32 [$13C4W]
%patch $24E50 [$13E2W]
%patch $24E6E [$1388W]

#Keen goes to standing when walking against walls
%patch $7A39  [$0ED8W]

#Keen goes to standing when no keys are pressed
%patch $6D62  [$0ED8W]

#Keen goes to standing before keys are pressed
%patch $6DA0  [$0ED8W]

#Keen stop looking down when key not pressed
%patch $6F21  [$0ED8W]

#Keen stand after landing on ground
%patch $7B78  [$0ED8W]

#Keen returns to standing after...
%patch $24982 [$0ED8W] #...being bored once
%patch $249FA [$0ED8W] #...being bored twice
%patch $24AAE [$0ED8W] #...being bored thrice
%patch $24B44 [$0ED8W] #...waking up from napping
%patch $24EE6 [$0ED8W] #...shooting l\r
%patch $24F40 [$0ED8W] #...shooting up
%patch $24F9A [$0ED8W] #...jumping vertically
%patch $24FF4 [$0ED8W] #...jumping horizontally


Sprite Behavior

Walking Keen only uses one behavior when walking, with an additional behavior when standing. The standing behavior is also used by many other actions where Keen does not move, such as his bored sequence.

Behaviors:
$05E80EF9RL #Keen still
$05E811A6RL #Keen walking

Keen Dreams

#Keen standing behavior
%patch $24958 $05E80EF9RL

#Keen walk behaviors
%patch $24E08 $05E811A6RL
%patch $24E26 $05E811A6RL
%patch $24E44 $05E811A6RL
%patch $24E62 $05E811A6RL


Standing behavior code

This is the complete code for Keen's standing behavior, used by many actions where the player stands still. It is divided up into several sections. The very first section checks for all possible player inputs, arrow keys, jump and shoot. If any of these keys are being pressed the game runs code to make Keen do stuff. (This is 'ground reactions' and involves things like starting to walk or shoot.) Interestingly it changes Keen's action to 'stand' right before it does this.

The remaining sections deal with Keen being bored. The second section points to a list of code to go to depending on Keen's 'boredom count'. (The list is 5+1 actions long.) Each section is broadly the same, a 'boredom timer' is checked, and if it is higher than a certain value, Keen's action is changed to one of his boredom actions, and he timer is reset.

Note that times are not cumulative; the second boredom timer is not the total time since no key has been pressed, but rather the time since the last boredom action started. It should be noted that the timer is not reset in the final action as there are no more bored actions after it. It should also be noted that one action sequence occurs twice in the full boredom sequence.

Keen Dreams

#Keen standing behavior
%patch $6D79 $55 $8B $EC $56 $8B $76 $06 $83 $3E $7022W  $08 $75 $0E $83 $3E
             $7016W  $00 $75 $07 $83 $3E $7018W  $00 $74 $17 $33 $C0 $89 $44
             $40 $89 $44 $3E $C7 $44 $1E [$0ED8W]  $56 $0E $E8 $FEF8W  $44 $44
             $E9 $00A4W
                         $8B $44 $36 $25 [$FFF8W]  $3D [$0018W]  $74 $0A $8B $44
             $3E $03 $06 $D4 $BD $89 $44 $3E $8B $5C $40 $83 $FB [$05] $76 $03
             $E9 $0084W  $D1 $E3 $2E $FF $A7 [$0FD4W]
                                                     $81 $7C $3E [$00C8W]  {$7E}
             $76 $FF $44 $40 $C7 $44 $1E [$0EF6W]  $C7 $44 $3E [$0000W]  $EB $67
             $81 $7C $3E [$012CW]  {$7E} $60 $FF $44 $40 $C7 $44 $1E [$0F8CW]  $C7
             $44 $3E [$0000W]  $EB $51
                                     $81 $7C $3E [$02BCW]  {$7E} $4A $FF $44 $40
             $C7 $44 $1E [$0F14W]  $C7 $44 $3E [$0000W]  $EB $3B
                                                             $81 $7C $3E [$0190W]
                 {$7E} $34 $FF $44 $40 $C7 $44 $1E [$0EF6W]  $C7 $44 $3E [$0000W]
             $EB $25
                     $81 $7C $3E [$02BCW]  {$7E} $1E $FF $44 $40 $C7 $44 $1E [$0F14W]
                 $C7 $44 $3E [$0000W]  $EB $0F
                                              $81 $7C $3E [$0190W]  {$7E} $08 $FF
             $44 $40 $C7 $44 $1E [$1040W]  $5E $5D $CB

#Boredom actions list
%patch $6E54 [$0F53W]
             [$0F69W]
             [$0F7FW]
             [$0F95W]
             [$0FABW]
             [$0FC1W]


Walking behavior code

This is the complete code for Keen's walking behavior. On the first line the game checks inputs ('Ground reactions'), this will make him do various things like start or stop walking. This in fact duplicates most of the code that follows, elsewhere.

After this comes code to check if Keen can jump, it checks a few variables including the 'already jumping' variable, and if all is clear sound $02 will play, Keen's upwards speed will be set to $FFD8W and his jump timer to $10. Finally his action will be set to the first frame of his jumping sequence.

The next section checks if Keen can throw a Flower Power horizontally, it is considerably simpler than his jumping check, only changing his action and the 'already throwing' variable.

Finally, on the last line, a list is checked. This gives Keen's running speeds on various slopes. (And thus applies only if Keen is still running and not doing anything else.) This is explained more fully in the speed section below.

Keen Dreams

#Keen walking behavior
%patch $7026 $55 $8B $EC $4C $4C $56 $8B $76 $06 $83 $3E $701EW  $00 $75 $0A #Check inputs
             $56 $0E $E8 $FC64W  $44 $44 $E9 $008DW  $A1 $701EW  $89 $44 $0E
             $83 $3E $7020W  $00 $74 $0B $56 $0E $E8 $FB74W  $44 $44 $0B $C0 #Check to jump
             $75 $75 $83 $3E $7016W  $00 $74 $3C $83 $3E $8EDAW  $00 $75 $35
             $B8 [$0002W]  $50 $9A $10BB1282RL     $44 $44 $8B $44 $0E $B1 $04
             $D3 $E0 $89 $44 $16 $C7 $44 $18 [$FFD8W]  $C7 $44 $12 $0000W  $C7
             $44 $14 $0000W  $C7 $06 $8EDAW  $0001W  $C7 $06 $8EE4W  [$0010W]
             $C7 $44 $1E [$152CW]  $83 $3E $7018W  $00 $74 $14 $83 $3E $8EDCW
             $00 $75 $0D $C7 $44 $1E [$1400W]  $C7 $06 $8EDCW  $0001W  $EB $17 #Check to Throw
             $8B $5C $36 $81 $E3 $0007W  $D1 $E3 $8B $87 [$1694W]  $F7 $2E $D4 #Speed list
             $BD $89 $46 $FE $01 $44 $12 $5E $8B $E5 $5D $CB


Ground reactions

When Keen is 'on the ground' (Standing, walking, most of his bored sequence, etc.) his behaviors point to a shared segment of code that handles keypresses. This avoids requiring a large segment of code for every separate behavior. It handles everything Keen can do while on the ground; shooting, jumping, pogoing and looking up\down.

This is the complete code for Keen's input handling when he is on the ground (Standing or walking). The first section checks to see if a left or right arrow is being pressed. If it is Keen is sent into his first walking action.

The second section does a similar thing with dropping down from one-way-up ledges; the key is checked then 'is Keen jumping already?' If Keen can jump then sound $02 is played, Keen's horizontal speed is set to 0 and his vertical speed to $FFD8W (upwards). Keen is given a 'jump duration' of $10 and his action is changed to his first falling action.

The third section deals with alt being pressed. First the key is checked, then the 'is Keen shooting already?' variable. If he is then the game skips to the next section. If he isn't then the game sets this to 1. Then Keen's vertical direction is checked; if Keen is looking up (Vertical direction is -1) he goes to the 'shoot up' action. Otherwise he goes to the 'shoot horizontally' action.

Section 5 deals with Keen looking up or down. First his looking direction is checked, whether it is +-1. If it is neither the code jumps to Keen's standing action. This will cause any behavior calling this code to make Keen go to standing if he's doing nothing else.

Otherwise looking up is run first; Keen's sprite is sent to some checking code, if this returns anything but zero the remaining code is skipped. Otherwise the game sets Keen's action to 'look up'.

After this is looking down; it sends Keen's sprite to a check and, if this returns anything but zero, changes his action to 'look down'.

Keen Dreams

#Keen Ground Input code
%patch $6C9F $55 $8B $EC $56 $8B $76 $06 $83 $3E $701EW  $00 $74 $24 $A1 $701EW
                 $89 $44 $0E $C7 $44 $1E [$1388W]  $8B $44 $0E $F7 $2E $94 $13
             $F7 $2E $D4 $BD $89 $44 $12 $56 $9A $05E811A6RL     $44 $44 $E9
             $00A5W
                     $83 $3E $7016W  $00 $74 $39 $83 $3E $8EDAW  $00 $75 $32
             $B8 [$0002W]  $50 $9A $10BB1282RL     $44 $44 $C7 $44 $16 $0000W 
             $C7 $44 $18 [$FFD8W]  $C7 $44 $12 $0000W  $C7 $44 $14 $0000W  $C7
             $06 $8EE4W  [$0010W]  $C7 $44 $1E [$14D2W]  $C7 $06 $8EDAW  $0001W
             $EB $65
                     $83 $3E $7018W  $00 $74 $22 $83 $3E $8EDCW  $00 $75 $1B
             $83 $3E $7020W  $FF $75 $07 $C7 $44 $1E [$1478W]  $EB $05 $C7 $44
             $1E [$1400W]  $C7 $06 $8EDCW  $0001W  $EB $3C
                                                         $A1 $7020W  $3D [$FFFFW]
                 $74 $0B $0B $C0 $74 $19 $3D [$0001W]  $74 $1B $EB $29 $56 $0E
             $E8 $FE74W  $44 $44 $0B $C0 $75 $1E $C7 $44 $1E [$1130W]  $EB $17
             $C7 $44 $1E [$0ED8W]  $EB $10 $56 $0E $E8 $FE5BW  $44 $44 $0B $C0
             $75 $05 $C7 $44 $1E [$114EW]  $5E $5D $CB


Speed

Keen has a constant animation speed when running that depends both on the values listed here and how fast he animates. Keen has no horizontal speed when standing still, but does attempt to move down; when combined with his animation speed and 'stick to ground' type this causes him to fall down when there is no longer any solid ground beneath him. (Other actions such as looking up will not respond to gravity so readily.)

Keen also slows down or speeds up going up and down slopes respectively; the speed changes are stored in a list accessed by the walking behavior. The values in the list are for Keen moving right, when Keen moves left the value is reversed. (So for example when walking right over a Top->bottom tile Keen's speed is increased by 8 as this is downhill. When walking left, or uphill, his speed is slowed by 8.)

Keen Dreams

#Keen standing speed
%patch $24954 [$0000W $0010W]

#Keen running speeds
%patch $24E04 [$0018W $0000W]
%patch $24E22 [$0018W $0000W]
%patch $24E40 [$0018W $0000W]
%patch $24E5E [$0018W $0000W]

#Modifier list location
%patch $70C1 [$1694W]

#Walking speed modifiers
%patch $25104 [$0000W] #No ground        (Don't affect speed)
              [$0000W] #Walking on flat  (Don't affect speed)
              [$0004W] #Top -> middle    (Increase by 4)
              [$0004W] #Middle -> bottom (Increase by 4)
              [$0008W] #Top -> bottom    (Increase by 8)
              [$FFFCW] #Bottom -> middle (Decrease by 4)
              [$FFFCW] #Middle -> top    (Decrease by 4)
              [$FFF8W] #Bottom -> top    (Decrease by 8)
              [$FFF8W] #???              (Decrease by 8)
              [$0000W] #???              (Don't affect speed)
              [$0008W] #???              (Increase by 8)


Sprite Collision

Keen really has only one sprite collision and this is used in most of his actions. Naturally this includes both standing and walking. The actual collision is explained and dissected on Keen's Keen Dreams page.

Keen Dreams

#Keen standing
%patch $2495C $05E817FCRL

#Keen walking
%patch $24E0C $05E817FCRL
%patch $24E2A $05E817FCRL
%patch $24E48 $05E817FCRL
%patch $24E66 $05E817FCRL


Animations

Keen's walking sequence consists of four actions. These behave pretty simply using eight total animations animating every 6 ticks. Keen's standing sequence is a single action whose 'animation' speed controls how quickly Keen responds to outside influences. (By default it's 4, faster tan most visible game changes.)

Keen Dreams

#Keen standing animations
%patch $24948 $0050W $0048W
%patch $24952 $0004W

#Keen walking animations
%patch $24DF8 $0051W $0049W
%patch $24E02 $0006W
%patch $24E16 $0052W $004AW
%patch $24E20 $0006W
%patch $24E34 $0053W $004BW
%patch $24E3E $0006W
%patch $24E52 $0054W $004CW
%patch $24E5C $0006W


Sounds

There are several sounds related to Keen walking or standing. The first is when Keen jumps while standing. The same sound plays when Keen jumps while walking. Another is when Keen is standing and the ground vanishes beneath him. This seems quite obtuse, but since Keen goes to standing after he shoots (Even when in the air) this sound actually plays many times when Keen throws a Flower Power. (It just isn't heard.)

Unlike in Keen Galaxy, Keen doesn't make noise when he walks.

Keen Dreams

%patch $6CE0 $02     #Keen jump while standing sound
%patch $6CDF $EB $09 #Don't play Keen jump while standing sound

%patch $7067 $02     #Keen jump while walking sound
%patch $7066 $EB $09 #Don't play Keen jump while walking sound

%patch $7970 $19     #Keen standing drops down sound
%patch $796F $EB $09 #Don't play Keen standing drops down sound


Keen makes noise while walking

This patch alters things so that Keen makes sounds while walking, at least in levels. (Walking on the map is different.) It works by creating space by merging Keen's walking and standing tile collisions to an extent. Some other patches on this page are incompatible with it since it slightly rearranges things. (Mostly those involving Keen walking against walls.)

Two sounds are played in a 1-2-1-2 rhythm depending on a timer that is reset to zero after sound two plays. The timing between the two sounds is $0010W and $0020W here and the sounds used are $02 and $03. These parameters will probably need to be tweaked for the best sounding walk.

Keen Dreams

#Keen makes a sound when he walks
%patch $7A17 $EB $4E $83 $7C $38 $00 $75 $06 $83 $7C $3C $00 $74 $1B $C7 $44
             $1A $0000W  $C7 $44 $1E $0ED8W  $A1 $0ED8W  $83 $7C $0E $01 $75
             $03 $A1 $0EDAW  $89 $44 $20 $EB $27 $FF $06 $0368W  $B8 [$0003W]
             $81 $3E $0368W  [$0010W]  $74 $10 $81 $3E $0368W  [$0020W]  $7C $10
             $33 $C0 $A3 $0368W  $B8 [$0002W]  $50 $9A $10BB1282RL     $44 $44
             $E9 $FF45W


Sprite-tile interaction

Keen has two interactions, one while standing and one while walking. Keen's standing interaction deals with him landing on flat ground and being moved by conveyor belts.

Keen Dreams

#Keen stand
%patch $24960 $05E81AE2RL

#Keen walking
%patch $24E10 $05E81B50RL
%patch $24E2E $05E81B50RL
%patch $24E4C $05E81B50RL
%patch $24E6A $05E81B50RL


Standing interaction code

This is the complete code for Keen's standing tile interaction. In Keen Dreams the first line checks whether Keen is standing on solid ground. If not the falling sequence is activated. Sound $19 plays, Keen changes to the falling action ($1568W). After this Keen's jump variable is set to 0, preventing him from jumping while falling. It should be noted that, for various reasons, this code is run quite often after Keen completes things like throwing a Flower Power.

After this is some unknown code. The last two lines draw Keen's sprite on the screen.

Keen's standing tile interaction

#Keen standing tile collision
%patch $7962 $55 $8B $EC $56 $8B $76 $06 $83 $7C $36 $00 $75 $31 $B8 [$0019W]
             $50 $9A $10BB1282RL     $44 $44 $8B $44 $0E $D1 $E0 $D1 $E0 $D1
             $E0 $89 $44 $16 $B8 [$1568W]  $50 $56 $9A $07C50255RL     $83 $C4
             $04 $C7 $44 $40 $0001W  $C7 $06 $8EE4W  [$0000W]  $EB $0F $8B $44
             $36 $25 $FFF8W  $3D $0008W  $75 $04 $0E $E8 $FCA1W  $B8 $0001W 
             $50 $33 $C0 $50 $FF $74 $20 $FF $74 $0C $FF $74 $0A $8B $C6 $05
             $46 $00 $50 $9A $0E450DC5RL     $83 $C4 $0C $5E $5D $CB


Walking interaction code

This is the complete code for Keen's standing tile interaction. In Keen Dreams the first line checks whether Keen is standing on solid ground. If not the falling sequence is activated. Keen's vertical speed is set to 0 and he changes to the falling action ($1568.) After this Keen's jump variable is set to 0, preventing him from jumping while falling. Oddly enough no falling sound is played, even though this happens in Keen's standing tile code.

Next checks are made for Keen walking into walls. This is handled oddly; the game first checks if Keen is walking into a left or right wall with a value of 2, if he is then the remaining code is skipped. Only then the code checks to see if Keen is touching a left or right wall of value 1. (Or not 0 in this case.)

This means there should be solid walls Keen can run against in Keen Dreams, though these are never used in the game itself.

Assuming Keen is walking into a wall the game sets his action timer to 0 and his action to 'standing'. It then checks whether he is facing left or right, and loads the appropriate animation from Keen's standing action. (Left is the action value, right is the action value plus two.) The result of this is to instantly turn him into standing with no delay.

The last two lines draw Keen's sprite on the screen.

Keen's standing tile interaction

#Keen walking tile interaction
%patch $79D0 $55 $8B $EC $56 $8B $76 $06 $83 $7C $36 $00 $75 $2B $8B $44 $0E
             $D1 $E0 $D1 $E0 $D1 $E0 $89 $44 $16 $C7 $44 $18 [$0000W]  $B8 [$1568W]
                 $50 $56 $9A $07C50255RL     $83 $C4 $04 $C7 $44 $40 $0001W
             $C7 $06 $8EE4W  [$0000W]  $EB $11 $8B $44 $36 $25 $FFF8W  $3D $0008W
                 $75 $06 $0E $E8 $FC39W  $EB $33 $83 $7C $38 $02 $74 $2D $83
             $7C $3C $02 $74 $27 $83 $7C $38 $00 $75 $06 $83 $7C $3C $00 $74
             $1B $C7 $44 $1A [$0000W]  $C7 $44 $1E [$0ED8W]  $83 $7C {$0E} [$01] $75
             $05 $A1 [$0EDAW]  $EB $03 $A1 [$0ED8W]  $89 $44 $20 $B8 $0001W  $50
             $33 $C0 $50 $FF $74 $20 $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46
             $00 $50 $9A $0E450DC5RL     $83 $C4 $0C $5E $5D $CB


Action type

Keen's standing action must animate as well as react quickly so is type 3. When walking Keen additionally needs to move smoothly, using type 4 actions.

Sprite action types

#Keen standing
%patch $2494C [$0003W]

#Keen walking
%patch $24DFC [$0004W]
%patch $24E1A [$0004W]
%patch $24E38 [$0004W]
%patch $24E56 [$0004W]


Deprotect and stick to ground

Keen needs to stick to the ground while standing and walking and thus uses a value of 1 for this variable in its walking actions. Interestingly his walking actions deprotect their animation, probably due to their need to cut short their animation should Keen start doing other things while walking.

Sprite deprotect, stick

#Keen standing
%patch $2494E [$0000W $0001W]

#Keen walking
%patch $24DFE [$0001W $0001W]
%patch $24E1C [$0001W $0001W]
%patch $24E3A [$0001W $0001W]
%patch $24E58 [$0001W $0001W]