Patch:Keen walking (Galaxy)

This page contains patches that relate to the player walking and under what conditions the player starts and stops doing so. It covers all the Galaxy episodes. Other patches relating to Keen can be found under Patch:Keen (Keen 4), Patch:Keen (Keen 5), and Patch:Keen (Keen 6). It also contains patches relating to Keen Dreams as the player there behaves nearly identically to in the Galaxy series.

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.

Keen can go to standing under a variety of circumstances and likewise can do a number of things while standing. These are not covered here but instead covered on the pages of the action involved. (For example becoming bored.) Keen is spawned standing when he first starts a level. While standing he continues to stand as long as nothing else happens.

If Keen is 'keyblocked' that is, two opposite keys like left and right are pressed at the same time, he will remain standing. If he attempts to walk into a wall he will also be set to standing.

Keen will start walking when the arrow keys are pressed and he is on the ground. This somehow leads to four walking starts related in an unknown manner. Keen's walk cycle is four actions long, when the arrow keys are no longer pressed he will revert to standing.

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.

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 handled elsewhere and involves things like starting to walk or shoot.)

The remaining sections deal with Keen being bored. The second section refers to one of the following sections depending on the value of Keen's bored sprite variable. The third section starts Keen's first bored behavior if enough time has passed. The fourth and fifth start Keen's mooning or bored behavior if enough time has passed (and if he's standing on a moon tile.)The last section sets Keen's final bored behavior, again if enough time has passed.

Walking behavior code

This is the complete code for Keen's walking behavior. It is divided up into several sections, some of unknown function. The very first section checks whether Keen is still walking, if not then his action is changed to standing.

The second and third sections are unknown, possibly involving Keen looking up and down. The fourth and fifth sections check to see if Keen is shooting, and if so his action is changed to shooting up or left\right respectively.

The sixth section deals with Keen jumping and pogoing while walking, it checks various keys and changes Keen's actions as expected. The remaining sections adjust Keen's walking by checking his walking actions and setting his Misc C variable.

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, with a delay of 4 ticks.

The second section deals with space 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.

The third section does a similar thing with jumping, 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 $12 and his action is changed to his first jumping action.

Section 4 is near identical but involving pogoing. (In fact it even plays the same sound, even though this will be overwritten by the actual pogo sound.) This time the 'pogo duration' is $18.

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 stops. 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 a variable is checked, if it too is zero Keen's sprite is sent to a second bit of code. If this returns anything but zero the code skips to the end, otherwise it 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 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, for unknown reasons.

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 rightover 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.)

Standing interaction code

This is the complete code for Keen's standing tile interaction. In Keen Galaxy the first line checks whether Keen is standing on solid ground. If not the falling sequence is activated. Sound $14 plays, Keen's vertical speed is set to 0 and he changes to the falling action ($11A2 in Keen 4, $1080W in Keen 5 and $101AW in Keen 6). After this Keen's jump variable is set to 0, preventing him from jumping while falling.

On line 5 the 'deadly and can't land on in God Mode' type is checked for in an unusual manner. If Keen contacts this type then the 'kill Keen' code is run.

Lines 6-9 deal with conveyor belts, these make Keen move left or right when he stands on them. The first check is for rightwards conveyors, top-flag $29. These increase Keen's horizontal speed and set his vertical speed to 0 as well as setting his 'bored time' ($3E) to 0 so he will not become bored on conveyors. Line 8 checks for leftwards conveyors doing the same thing, except changing Keen's horizontal speed by -8.

Walking interaction code

This is the complete code for Keen's standing tile interaction. In Keen Galaxy the first line checks whether Keen is standing on solid ground. If not the falling sequence is activated. Sound $14 plays, Keen's vertical speed is set to 0 and he changes to the falling action ($11A2 in Keen 4, $1080W in Keen 5 and $101AW in Keen 6). After this Keen's jump variable is set to 0, preventing him from jumping while falling.

On line 5 the 'deadly and can't land on in God Mode' type is checked for in an unusual manner. If Keen contacts this type then the 'kill Keen' code is run.

Lines 6-9 deal with conveyor belts, these make Keen move left or right when he stands on them. The first check is for rightwards conveyors, top-flag $29. These increase Keen's horizontal speed and set his vertical speed to 0. Line 8 checks for leftwards conveyors doing the same thing, except changing Keen's horizontal speed by -8.

On line 10 checks are made for Keen walking into walls. First the code checks to see if Keen is touching a left wall. If so, it then checks to see if he is moving left. If so then the next two checks are skipped to go to wall-blocking. Otherwise the game then checks to see if Keen is touching a right wall, and if so whether he's moving right. Together these checks see if Keen is trying to walk into walls. If so then his action timer is set to 0 (Stopping him animating.) and his action to 'standing' Keen's direction is then checked again and his left or right standing animation taken from game data and applied immediately to his current animation. (So he immediately goes to standing when hitting a wall.)