Patch:Mad Mushroom

From KeenWiki
Jump to navigation Jump to search

This page covers patches relating to the Mad Mushrooms in Keen 4. The mushrooms are found in many levels and spend their time bounding up and down.


Sprite Type

Mushrooms use sprite type 9 which is used only by the Mushroom and doesn't affect anything else.

Keen 4

#Mushroom sprite type
%patch $FED9  $09


Sprite Actions

Mushrooms have only two actions, their purpose is to bounce up and down and act as a lethal obstacle for Keen, animating in an endless loop.

Actions:
$20E4W #Mushroom 1
$2102W #Mushroom 2

Keen 4

#Mushroom placed in-level
%patch $FF05  {$20E4W} #Mushroom

#Mushroom actions
%patch $30F70 {$2102W} #Mushroom 2
%patch $30F8E {$20E4W} #Mushroom 1


Sprite Behavior

The Mushroom's behavior is quite simple, it turns to face Keen.

This behavior doesn't change the Mushroom's action, meaning any other sprite, and several sprites at once can use it with no problems. Patches that affect this behavior are found in the seeking section below.

Behaviors:
$0FA80493RL #Mad Mushroom

Keen 4

#Mushroom
%patch $30F64 {$0FA80493RL} #Mad Mushroom
%patch $30F82 {$0FA80493RL} #Mad Mushroom


Behavior code and seeking Keen

This is the complete behavior code for the Mushroom seeking Keen. The two xxxxW values are +-1 and make the Mushroom turn to face Keen depending on whether he is right or left of it. Reversing these makes it always face away from Keen. Replacing the brown $73 with $EB will make the Mushroom only ever face one way.

Keen 4

#Mushroom seek Keen
%patch $FF13  $55 $8B $EC $56 $8B $76 $06 $8B $1E $A7D6W  $8B $47 $0A $3B $44
              $0A {$73 $07} $C7 $44 $0E [$FFFFW]  $EB $05 $C7 $44 $0E [$0001W]  $56
              $9A $09DC1315RL     $83 $C4 $02 $5E $5D $CB


Speed and Jump Height

Mushrooms have no animation motion, relying entirely on their tile collision for their jump heights. The collision works as follows. The Mushroom bounces up when it hits a floor tile. Every jump is counted. If the number of jumps is less than x, a 'small' jump occurs. If the number of jumps is larger than x, then a 'high' jump occurs and the jump counter is set back to zero. The Mushroom stops if it hits a ceiling tile, though by making this value positive (Move down) the Mushroom can be made to actively bounce downwards from ceilings.

These patches will thus interfere with the tile collision patches below.

Mad mushroom jump height

%patch $FFBB [$FFD8W] #Small
%patch $FF9C [$FFBCW] #High
%patch $FF7C [$0000W] #Bounce down from ceiling

Animation motion

#Mushroom
%patch $30F60 [$0000W] [$0000W]
%patch $30F7E [$0000W] [$0000W]


Sprite Collision

Collision values

The Mushroom uses its own special collision. It will stop Keen's shots (Type 3) and kill Keen if he touches it. This collision can thus be used by multiple sprites at once, like the Mushroom's behavior.

Keen 4 collision values

#Mushroom
%patch $30F68 $0FA804BERL #Mad Mushroom
%patch $30F86 $0FA804BERL #Mad Mushroom


Collision code

Default

The default code has two checks.The first checks for sprite type 3 (Keen's shot) and if this is not found, jumps 13 bytes. The second checks for type 2 (Keen) and if this is not found jumps five bytes. (See Patch:Jump conditions.

The two $9A $xxxxxxxxRL segments turn the colliding sprite into a smashed shot and kill Keen respectively. Replacing them with $90 $90 $90 $90 $90 will stop one or both effects.

Keen 4

#Mushroom collision
%patch $FF3E  $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $C7 $4C $83 $3C
              [$03] {$75} $0D $56 $9A $0D8F0D43RL     $83 $C4 $02 $5F $5E $5D $CB
              $83 $3C [$02] {$75} $05 $9A $0B8013E9RL     $5F $5E $5D $CB


Smaller collision

The following collision is the most efficient use of the code. It is two bytes smaller than the default but does the same thing.

Keen 4

#More efficient Mushroom collision
%patch $FF3E  $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $C7 $4C $83 $3C
              [$03] {$75} $0B $56 $9A $0D8F0D43RL     $83 $C4 $02 $EB $0A $83 $3C
              [$02] {$75} $05 $9A $0B8013E9RL     $5F $5E $5D $CB


Don't kill Keen (Only stop bullets)

This collision is basically a 'stop Keen's shot' collision, Keen can touch the mushroom without being hurt.

Keen 4

#More efficient Mushroom collision
%patch $FF3E  $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $C7 $4C $83 $3C
              [$03] {$75} $09 $56 $9A $0D8F0D43RL     $83 $C4 $02 $5F $5E $5D $CB


Animations

Mushrooms have two animation frames (Four animations) and animate endlessly between them using their animation speed.

Keen 4

#Cache
%patch $306E8 $0145W #Mushroom Cache start
%patch $30732 $0148W #Mushroom cache end

#Mushrooms
%patch $30F54 $0145W $0147W
%patch $30F5E $0008W        #Animation speed
%patch $30F72 $0146W $0148W
%patch $30F7C $0008W        #Animation speed


Sprite positioning

The Mushroom is spawned one tile above where it is placed in-level. This is unnecessary as it does not need to walk along the ground.

Keen 4

#Spawn height:
%patch $FEF5  $FF00W #1 tile up


Sounds

The Mad Mushroom makes two distinct sounds, one for a high bounce and one for a low bounce. Both sounds can be blocked.

Keen 4

#Sounds
%patch $FF9F  $10 #Mad Mushroom high bounce
%patch $FFAD  $1C #Mad Mushroom low bounce

#Don't make sounds:
%patch $FF9E  $EB $0A #Mad Mushroom high bounce
%patch $FFAC  $EB $0A #Mad Mushroom low bounce


Clipping and foreground

The Mushroom's foreground variable is set when it is spawned. It appears behind everything.

Keen 4

#Foreground
%patch $FEE3  [$0000W] #Mad Mushroom


Give Mushroom adjustable clipping

The Mushroom does not have any clipping code by default, using a standard clipping set in the sprite creation code. However it is possible to give the mushroom clipping via overwriting other bits of its code. The following patch inserts a clipping option, at the expense of removing the Mushroom's initial vertical direction. (If the Mushroom is not affected by gravity anymore this can cause notable effects.)

If problems do occur, changing the location of the patch to $FEFA will overwrite its horizontal direction instead, and $FEE0 will overwrite the foreground variable.

Keen 4

#Add adjustable clipping to Mushroom, overwrite v=1
%patch $FEFF $C7 $47 $06 [$0001W]


Sprite-tile interaction

The Mad Mushroom's sprite-tile interaction is what makes it bounce. Patches relating to its jump height are found here. This doesn't alter the sprite's action, so multiple sprites can use it without any problems.

Keen 4

#Mushrooms
%patch $30F6C $0FA804ECRL #Bouncing
%patch $30F8A $0FA804ECRL #Bouncing


Number of low\high bounces

Every 1 in x bounces of the Mushroom's will be high. This is the first value. After this it will 'reset' to the second value. By default every 3rd jump is high, resetting to 0. (A pattern of 0,1,2,3,4 0,1,2,3,4...) If the reset value is not 0, then the first few jumps of the Mushroom will be slightly different.

Keen 4

#Number of low\high bounces
%patch $FF90 [$0003W] #Xth jump is tall
%patch $FF97 [$0000W] #Reset value


Mushroom always jumps high

This patch makes the Mushroom have only one kind of jump height instead of 2.

Keen 4

#Mushroom always jumps high
%patch $FF92 $90 $90


Mushrooms only bounce high when Keen is right of them

This unusual patch makes Mushrooms jump high only when Keen is right of them on the map. This can be used to make an enemy whose behavior changes when you pass under it.

Keen 4

# Mushrooms only bounce high when Keen is right of them
%patch $FF8E $0E $3D $01


Tile collision code

As noted above all of a Mushroom's movement and the sounds it makes are due to its tile collision code. This patch will thus interfere with sound and movement patches if placed after them in a patch file.

The first two blue values are inconsequential. (They stop the Mushroom moving when it hits the ground.) The third value is the number of small bounces needed before a big bounce is taken. (By default every third bounce is big.) If the jump is big, the jump counter is set to zero (The fourth blue value.), the bounce height is set to $FFBCW and sound $10 is played.

Otherwise sound $1C is played, the bounce height is set to $FFD8W (The small jump.)

This can be manipulated in a number of ways. Firstly the jump heights and sounds can be manipulated, this is quite basic. Secondly the jump counter can be altered; if it is not reset to zero then the frequency of big jumps will increase. (For example resetting it to 1 will mean the mushroom has two small jumps, a big jump, then alternating small and big jumps.)

Keen 4

#Mushroom tile collision code
%patch $FF6C  $55 $8B $EC $56 $8B $76 $06 $83 $7C $3A $00 $74 $05 $C7 $44 $18
              [$0000W]  $83 $7C $36 $00 $74 $39 $C7 $44 $18 [$0000W]  $FF $44 $3E #Stop moving when hitting the ground
              $8B $44 $3E $3D [$0003W]  $75 $18 $C7 $44 $3E [$0000W]  $C7 $44 $18 #Number of small bounces\reset bounce counter to 0
              [$FFBCW]  $B8 [$0010W]  $50 $9A $187409F1RL     $83 $C4 $02 $EB $11 #Big jump, play sound $10
              $B8 [$001CW]  $50 $9A $187409F1RL     $83 $C4 $02 $C7 $44 $18     #Play sound $1C
          [$FFD8W]  $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A #Small jump
              $8B $C6 $05 $46 $00 $50 $9A $16541641RL     $83 $C4 $0C $5E $5D
              $CB


Action type

The Mushroom uses type 3, useful since it must animate and fall at the same time.

Keen 4

#Mushrooms
%patch $30F58 [$0003W] #Mushroom
%patch $30F76 [$0003W] #Mushroom


Deprotect and stick to ground

The mushroom has values of 0 for both of these parameters. It does not need to walk on the ground.

Keen 4

#Mushrooms
%patch $30F5A [$0000W $0000W]
%patch $30F78 [$0000W $0000W]


Sprite spawn code

In the initiation code notice the Mushroom cache being set ($C7 $06 $53 $CB $0001W.)

In the spawning code the last blue highlighted value is the sprite action the sprite uses as it proceeds to act in-level. $C7 $02 $xxxxW sets the sprite activity, $C7 $07 $xxxxW sets the sprite type, $C7 $20 $xxxxW sets the foreground value. Finally $D3 $E0 $05 $xxxx is how far down (Or more usually up) the sprite is spawned from where it is placed. This is necessary for sprites that walk on the ground as they can only be placed in the level at multiples of 16 pixels high while their actual height can be anything. (This is odd since the Mushroom doesn't need to walk on the ground, it bounces.)

The Mushroom always starts the level moving down and facing right. It seeks Keen however and will start off facing in his direction. $C7 $47 $10 $xxxxW is the vertical direction the sprite starts moving in, either $0001W (Facing down), $FFFFW (Facing up) or $0000W (Neither, never used.) $C7 $47 $0E $xxxxW is the horizontal direction.

A special thing to note is $C7 $02 $0001W which sets the Mushroom's sprite activity to 1 which means it stops 'working' when offscreen.

Keen 4

#Location of initiation code
%patch $EEAD [$030FW] #Mushroom (At $EBFF)

#Mad Mushroom Initiation code
%patch $EBFF $FF $76 $FC $57 $9A {$0FA80445RL}     $83 $C4 $04 $C7 $06 $53 $CB
             $0001W  $E9 $01E9W

#Mad Mushroom spawning code
%patch $FEC5  $55 $8B $EC $33 $C0 $50 $9A $06BD1E11RL     $83 $C4 $02 $8B $1E
              $D8 $A7 $C7 $07 [$0009W]  $C7 $47 $02 [$0001W]  $C7 $47 $20 [$0000W] 
              $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $05
              [$FF0FW]  $89 $47 $0C $C7 $47 $0E [$0001W]  $C7 $47 $10 [$0001W]  $B8
              [$20E4W]  $50 $53 $9A $09DC118CRL     $83 $C4 $04 $5D $CB