Patch:Keen mooning
This page contains patches that relate to Keen mooning in Keen 4 and the circumstances under which he does so. The page is divided into two sections, the first deals with what triggers Keen's mooning, including the 'moon tile'; the second section deals with Keen's mooning sprites, their properties, actions and suchlike. Related patches can be found in Patch:Keen (Keen 4), notably those relating to Keen's other bored sequences since those patches can affect his mooning sequence.
While Keen cannot moon in Keen 5 the mooning variable is still in the code. As such this page has a final section dealing with the mooning variable there.
When Keen moons
This section contains patches relating to what triggers the mooning sequence. By default this occurs when Keen stands in (not on) a tile with a special 'moon property' long enough to display his second bored sequence (Facing the player and shrugging.) However instead of doing this Keen will moon the player.
This can only happen once by default, further attempts will simply play the second bored sequence unless the player dies.
Keen never moons
This patch completely disables mooning. This shouldn't be required if the moon tile property isn't used in a mod.
Keen never moons
#Keen never moons
%patch $BC27 $EB
The mooning variable
The game keeps track of whether Keen can moon via a 'mooning variable'; there are four situations in which is is directly referenced. The first situation is when Keen is bored. If the mooning variable is 1 Keen will moon and set the mooning value to 2. The second situation is when Keen dies; the value is set to 0. The third situation is when Keen steps on a normal tile; if the value is 1 it is set to 0. Finally if Keen steps in a moon tile, if the mooning variable is 0 it will be set to 1.
The variable works as follows: Keen can only moon when the mooning variable is 1. This can only happen if Keen is standing in a mooning tile. If Keen stands in a mooning tile then walks onto a normal tile the mooning value is set to 0, meaning he will not moon on normal tiles.
Once Keen has mooned and the mooning variable is 2, neither standing on a mooning tile or normal tile will change the mooning variable, meaning he can't moon again.
If Keen moons, but then dies, he can stand on a mooning tile again and moon. (Winning or quitting the level also seems to reset mooning.) See also Patch:Game stats and Patch:Jump conditions to make sense of these patches.
Several patches that use these checks follow. They can be combined if desired to make more complex triggers for Keen's mooning.
Mooning variable references
#If mooning variable = 1, moon, set to 2
%patch $BC24 {$CAB5W} [$01] {$75} $0E $C7 $06 {$CAB5W} [$0002W]
#On death set mooning variable to 0
%patch $CC0E $C7 $06 {$CAB5W} [$0000W]
#If touching normal tile with moon variable = 1, set it to 0
%patch $D0F6 {$CAB5W} [$01] {$75} $06 $C7 $06 {$CAB5W} [$0000W]
#If touching a moon tile with moon variable = 0, set it to 1
%patch $D1FA {$CAB5W} [$00] {$75} $1F $C7 $06 {$CAB5W} [$0001W]
Keen can moon more than once
By default Keen can only moon once. This can be patched, and Keen can moon an indefinite number of times. This works by removing the code that changes the moon variable to 2.
Keen can moon as often as he wants
#Keen can moon as often as he wants
%patch $BC29 $EB $04
Dying won't let Keen moon again or stops him mooning
There are two patches in this section. The first patch stops dying from resetting Keen's mooning variable, meaning that if Keen has mooned once in a level, dying will not allow him to repeat it. The second patch makes dying itself set Keen's mooning variable to 2, meaning that if he dies even once in a level he cannot moon in it. This can be used to make mooning even more difficult to activate.
Dying won't let Keen moon again
#Dying won't let Keen moon again
%patch $CC0E $EB $04
Dying stops Keen mooning
#Dying stops Keen mooning
%patch $CC0E $C7 $06 {$CAB5W} [$0002W]
Moon tiles act as triggers
This patch stops Keen's mooning variable being reset to 0 if he steps off a moon tile without mooning. This means that if Keen has stood on a moon tile then he can moon anywhere in the level, if he hasn't died, by waiting. This allows the moon tile to act as a 'trigger'; if Keen has stood on it his behavior will change.
Moon tiles act as triggers
#Moon tiles act as triggers
%patch $D0F4 $EB $0B
Moon tiles win the level
This patch makes touching a moon tile win the level. It does this by changing the game stat so that the level state is set to 2 (Win level) if Keen touches a moon tile with a moon variable of 0. Combined with the above patches this can make an alternate exit to the level available only in certain circumstances.
Moon tiles win the level
#Moon tiles win the level
%patch $D1FA {$CAB5W} [$00] {$75} $1F $C7 $06 {$7A70W} [$0002W]
Moon tiles activate jump cheat
This patch is similar to the above in that it alters a game stat, this time to activate the jump cheat. It can also be made to turn the cheat off.
Moon tiles activate jump cheat
#Moon tiles activate jump cheat
%patch $D1FA {$CAB5W} [$00] {$75} $1F $C7 $06 {$C62BW} [$0001W]
Mooning Keen's sprite
This section deals with the properties of Keen's mooning sprite, its behavior, actions and suchlike. Patches in this section do not alter how Keen starts mooning, but rather what happens when he does or what happens afterwards. The mooning sequence consists of three actions (Using two animations.) that involve Keen mooning the player.
Sprite Actions
Keen's mooning sequence consists of three consecutive actions. The sequence is started in Keen's bored code, as detailed above. It ends with Keen returning to standing. For a complete list of Keen's actions see Patch:Keen (Keen 4)#Sprite_Actions.
Actions: $0A7CW #Keen moons 1 $0A9AW #Keen moons 2 $0AB8W #Keen moons 3
Keen 4
#Start mooning
%patch $BC32 [$0A7CW]
#Mooning sequence
%patch $2F908 [$0A9AW]
%patch $2F926 [$0AB8W]
%patch $2F944 [$098CW]
Sprite Behavior
Keen has too many possible behaviors to list here. However they can be found by clicking this section's title. Mooning Keen uses the same behavior as standing Keen, meaning he waits for arrow\jump\shoot keys to be pressed. This also means that mooning can be interrupted at any time and anything Keen can do while standing he can do while mooning. Replacing the behavior with $00000000L will make mooning uninterruptable. (The player will lose control of Keen.)
Mooning Keen behaviors
#Mooning sequence
%patch $2F8FC $0B800395RL
%patch $2F91A $0B800395RL
%patch $2F938 $0B800395RL
Sprite Collision
Keen uses the same sprite collision while mooning as he does while standing. This allows him to interact with things such as point sprites in his usual manner.
Keen 4
#Keen mooning
%patch $2F900 $0B8014A9RL
%patch $2F91E $0B8014A9RL
%patch $2F93C $0B8014A9RL
Speed
Mooning Keen is still by default, not using any motion.
Animation motion
#Mooning sequence
%patch $2F8F8 [$0000W $0000W]
%patch $2F916 [$0000W $0000W]
%patch $2F934 [$0000W $0000W]
Animations
Two sprite bitmaps are used in three frames. Notice that these frames are not cached with the normal frames; a special 'caching sprite' must be present in the level to activate mooning Keen's cache. Failure to put such a sprite in the level will cause the game to crash with an uncached sprite error.
Alternatively, if the animations are patched to not be the default images but instead be normal player frames then the cache can be abandoned entirely.
Mooning Keen animations
#Cache
%patch $30716 [$0207W] #Mooning Keen Cache start
%patch $30760 [$0208W] #Mooning Keen cache end
#Mooning sequence
%patch $2F8EC $0207W $0207W
%patch $2F8F6 $0014W #Animation speed
%patch $2F90A $0208W $0208W
%patch $2F914 $005AW #Mooning time
%patch $2F928 $0207W $0207W
%patch $2F932 $0014W #Animation speed
Sprite-tile interaction
Keen uses his default tile interaction while mooning. This means he acts as if he's standing.
Keen 4
#Keen mooning
%patch $2F904 $0B801AA2RL
%patch $2F922 $0B801AA2RL
%patch $2F940 $0B801AA2RL
Action type
Keen's mooning action is type 3, allowing him to respond instantly to keypresses.
Mooning Keen action type
#Mooning sequence
%patch $2F8F0 $0003W
%patch $2F90E $0003W
%patch $2F92C $0003W
Deprotect and stick to ground
Keen uses the 'stick to ground' variable so he can moon on slopes and other such tiles.
Keen 4
#Mooning sequence
%patch $2F8F2 [$0000W $0001W]
%patch $2F910 [$0000W $0001W]
%patch $2F92E [$0000W $0001W]
Sprite spawn code
Keen mooning does not have a spawn code of its own, being part of the player sprite. However the animations used by mooning Keen are not cached with his normal ones. This means a special 'blank' sprite must be placed in levels where mooning occurs for the sole purpose of activating this cache. In the initiation code notice the mooning cache being set ($C7 $06 $CB81W $0001W.)
The mooning activation sprite itself then vanishes from the level as it is not needed.
Keen 4
#Location of initiation code
%patch $EF19 [$04E5W] #Mooning Keen (At $EDD5)
#Mooning Keen initiation code
%patch $EDD5 $C7 $06 $CB81W $0001W $EB $20
The mooning variable in other games
While Keen cannot moon by default in Keen 5 or 6 the mooning variable is still in the game's tile code. (However Keen himself lacks any code to make use of the variable.) This variable can therefore be utilized for other purposes.
Keen 5 mooning variable references
#On death set mooning variable to 0
%patch $C023 $C7 $06 {$C17BW} [$0000W]
#If touching normal tile with moon variable = 1, set it to 0
%patch $C409 {$C17BW} [$01] {$75} $06 $C7 $06 {$C17BW} [$0000W]
#If touching a moon tile with moon variable = 0, set it to 1
%patch $C50D {$C17BW} [$00] {$75} $1F $C7 $06 {$C17BW} [$0001W]
Keen 6 mooning variable references
#If touching a moon tile with moon variable = 0, set it to 1
%patch $C2F4 {$CC1BW} [$00] {$75} $1F $C7 $06 {$CC1BW} [$0001W]