Patch:Keen jumping (Galaxy)
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. Those can be found at Patch:Gameplay (Keen Galaxy). 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).
- 1 Sprite Actions
- 2 Sprite Behavior
- 3 Speed and Jump Height
- 4 Sprite Collision
- 5 Animations
- 6 Sounds
- 7 Sprite-tile interaction
- 8 Action type
- 9 Deprotect and stick to ground
There are only two jumping actions and two related falling actions. Keen can start jumping in three situations; when standing still, when walking and when on a pole. These all lead to the first jumping action.
The jumping sequence is two actions long and ends with Keen going to the falling loop. The falling loop is two actions long and continues indefinitely until Keen hits the ground.
Keen can do things such as shoot or pogo while jumping, but these actions are covered on their own pages.
There are three situations in which Keen can trigger his jumping sequence, when standing still, walking or sitting 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 forever.
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.
Keen will go to falling when he walks off of solid ground or if he is standing on solid ground that then vanishes.
Finally Keen's jumping behavior has two 'falling exceptions'; his jumping actions will proceed to their next action not based on a timer but instead on his jumping speed. The exceptions are his falling actions which have their own pace and are excepted from this behavior.
Actions: $1166W #Keen jumping 1 $1184W #Keen jumping 2 $11A2W #Keen falling 1 $11C0W #Keen falling 2
|Patch: Keen 4|
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.
|Patch: Disable shooting while jumping|
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.
Behaviors: $0B800B5BRL #Jumping and falling
|Patch: Keen 4 behaviors|
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.
|Patch: Keen 4 jump\fall code|
Keen's jump speeds and heights are controlled in a complex way discussed below. The action speeds are not used.
|Patch: Keen 4 action speeds|
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.
|Patch: Keen 4 Jumping Physics|
|Patch: Keen 5 Jumping Physics|
|Patch: Keen 6 Jumping Physics|
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.
|Patch: Keen 5|
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.
|Patch: Keen 4 sprite collisions|
|Patch: Keen 5 sprite collisions|
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.
|Patch: Keen 4|
|Patch: Keen 5|
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.
|Patch: Keen 4 sounds|
|Patch: Keen 5 sounds|
|Patch: Keen 6 sounds|
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
|Patch: Keen 4 tile collisions|
|Patch: Keen 5 tile collisions|
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.
|Patch: Keen 4 falling Keen tile interactions|
|Patch: Keen 5 falling Keen tile interactions|
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.
|Patch: Keen 4|
Jumping and falling Keen does not need to use either of these variables.
|Patch: Keen 4|