From KeenWiki
Jump to: navigation, search

This page covers patches relating to the Blue Bird Eggs in Keen 4. The eggs appear in several levels and are notable in that when they are shot or touched by Keen they become Blue Birds.

Patches relating to the bird are found on its page, patches relating to the hatching of a bird from an egg are found here. See also Patch:Blue Bird

A lot of patches on this page can be found in the Egg collision section below, and modifying the collision may well cause the game to crash if patches from other sections are used as well. Pay careful attention when modifying collision to see what patches it affects.

Sprite Type

Eggs use sprite type 8 which is used only by the egg and doesn't affect anything else. When an egg is smashed (See sprite collision.) it produces five new sprites. One is a bird and is given the bird property, the others are given the 'misc' property. By default all sprite properties don't affect anything.

Patch: Keen 4
#Egg sprite type
%patch $FFF1 $08
#Egg spawn sprite types
%patch $100CF $01
#Large eggshell
%patch $100F5 $1B
%patch $10153 $01
#Left moving shell fragment
%patch $1018F $01
#Right moving shell fragment
%patch $101CB $01
#Up moving shell fragment

Sprite Actions

Eggs have only one action, their purpose is to sit and wait for something to touch them. All the sprites spawned from the egg on hatching also have only one action (Except the bird, which doesn't relate too strongly to the egg and is thus not listed here.) The value $0000W means that there is no 'next action' for the sprite involved, if they did not use action type value $02 they would disappear.

Eggs can be placed in the level. Five sprites are created when the egg hatches (See sprite collision.), one of which can become a Blue Bird.

$2120W #Egg
$213EW #Big shell
$215CW #Left shell fragment
$217AW #Right shell fragment
$2198W #Up shell fragment
$21B6W #Blue Bird

Patch: Keen 4
#Egg placed in-level
%patch $1001D $2120W
#Egg actions
%patch $30FAC $0000W
#Sprites spawned from egg
%patch $100D7 $213EW
#Big shell
%patch $10171 $215CW
#Left shell fragment
%patch $101AD $217AW
#Right shell fragment
%patch $101E9 $2198W
#Up shell fragment
%patch $10135 $21B6W
#Blue Bird
#What sprites do next
%patch $30FCA $0000W
#Nothing (Big shell)
%patch $30FE8 $0000W
#Nothing (Left shell)
%patch $31006 $0000W
#Nothing (Right shell)
%patch $31024 $0000W
#Nothing (Up shell)
%patch $10135 $21F2W
#Waiting Blue Bird (Blue Bird)

Sprite Behavior

The Egg's behavior is quite simple, it does nothing. The shell fragments produced during hatching use the 'shot sprite' behavior to move through the air. The newly hatched bird does nothing too.

$09DC16C9RL #Shot sprite

Patch: Keen 4
%patch $30FA0 $00000000L
#Do nothing
#Spawned from egg
%patch $30FBE $00000000L
#Do nothing (Big shell)
%patch $30FDC $09DC16C9RL
#Shot sprite (Left shell)
%patch $30FFA $09DC16C9RL
#Shot sprite (Right shell)
%patch $31018 $09DC16C9RL
#Shot sprite (Up shell)
%patch $31036 $00000000L
#Do nothing (Hatched bird)

Eggs hatch immediately

This patch makes the Egg's collision its behavior instead, meaning eggs will hatch as soon as they appear onscreen. It uses the EGAGRAPH skip so is incompatible with other patches that use it.

Patch: Keen 4
#Rewire egg to explode
%patch $3CE5 $90 $90
#EGAGRAPH check skipped
#Behavior = $037D0526RL target $100CD
%patch $3CF6 $55 $8B $EC $83 $EC $02 $56 $8B $76 $06 $E9 $C3CAW
#Eggs use new behavior
%patch $30FA0 $037D0526RL

Speed and Jump Height

Neither the egg or large shell move. They also have no animation movement. The movement of the small shell fragments is governed by the falling sprite behavior outlined above. Both their horizontal and vertical speed are set on hatching. (Though the upwards fragment has its horizontal speed set as zero.) These can be considered akin to 'jumps' The hatched bird has an animation movement speed of $0080W, the same as the Blue Bird's walking speed.

Patch: Animation motion
%patch $30F9C $0000W $0000W
#Egg spawn
%patch $30FBA $0000W $0000W
#Big shell
%patch $30FD8 $0000W $0000W
#Left shell
%patch $30FF6 $0000W $0000W
#Right shell
%patch $31014 $0000W $0000W
#Up shell
%patch $31032 $0080W $0000W
#Hatched bird

Patch: Shell fragment motion
%patch $10169 $FFE4W 
#Left speed (Left shell)
%patch $1016E $FFD8W
#Up speed (Left shell)
%patch $101A5 $001CW
#Right speed (Right shell)
%patch $101AA $FFD8W
#Up speed (Right shell)
%patch $101E1 $0000W
#Horizontal speed (Up shell)
%patch $101E6 $FFC8W
#Up speed (Up shell)

Sprite Collision

The Egg collision is one of the more complex in Keen 4, in terms of what it does. The Egg will respond when Keen or Keen's shot collide with it. If Keen's shot type hits it, the sprite will be removed. When the Egg hatches it produces five sprites, a large piece of shell that doesn't move, the small pieces of shell that fly through the air in different directions, and a Bird that eventually transforms into a Blue Bird.

Collision values

The egg used the egg collision code below. The hatched bird uses the Stunned Blue Bird collision (as expected, it can be considered stunned in a way.) Aside from this nothing else bothers colliding.

Patch: Keen 4 collision values
%patch $30FA4 $0FA80627RL
#Shell fragments
%patch $30FC2 $00000000L
#No collision (Big shell)
%patch $30FE0 $00000000L
#No collision (Left shell)
%patch $30FFE $00000000L
#No collision (Right shell)
%patch $3101C $00000000L
#No collision (Up shell)
%patch $3103A $0FA8087ARL
#Stunned Blue Bird (Hatched bird)

Collision code

A lot of patches on this page can be found in the collision below, and modifying the collision may well cause the game to crash if patches from other sections are used as well.

There are several collisions posted here, the default, and various simplified versions that take up less space and may be used in different situations.


This is the normal Egg collision, it produces five sprites, Big shell, Bird and three flying fragments.

The first two lines control what the egg reacts with, type Keen and type Keen's shot ($02 and $03) In the first case if the type is Keen's shot 8 bytes are jumped (This jumps the 'is this Keen?' code.) In the second line type Keen is looked for, if the sprite is Keen type then a jump over a jump to the end of the code ($0136W) is made.

This leaves only sprites of type 2&3. A third check is then made for type Keen's Shot, if the type is not Keens Shot then a jump of 9 bytes is made (This is the 'remove shot' code, thus only type 3 sprites are destroyed on collision with the Egg.) This is an inefficient way of doing things.

After all this the big shell fragment is created, lines 2-4 hold its code (Up to $83 $C4 $02), four variables are set, the sprite type ($0001W), an unknown ($0003W), the sprite action and a second unknown variable ($0001W)

Lines 5-11 contain code to produce the bird. (Again to $83 $C4 $02 in line 11) This code is more complex, three variables are set, sprite type ($001BW), unknown ($0001W), sprite displacement ($0080W, how far up the bird is created, since the bird is half a tile taller than the egg, it must be moved up 8 pixels to avoid being buried in the ground.) This is followed by a check of Keen's horizontal position, if it is less than or equal ($73) to the Egg's, the bird will face left, otherwise it will face right (That is, it will try and face Keen when hatched, see Patch:Jump conditions) It's vertical direction is set to down ($0001W), followed by the sprite action and an unknown variable.

The left, right and up shells all follow almost exactly the same pattern, 6 variables are set, sprite type ($0001W), unknown ($0003W), the horizontal and vertical speeds, sprite action and the unknown variable ($0001W) After this the code ends.

Patch: Keen 4
#Egg collision
%patch $100A7 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $03 $74 $08 $83 $3D $02 $74 $03 $E9 $0136W $83 $3D $03 $75 $09 $57 $9A $0D8F0D43RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $02 $0003W $B8
#Make large shell
$213EW $50 $56 $9A $09DC120ARL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $001BW
#Make Bird
$C7 $47 $02 $0001W $8B $44 $0A $89 $47 $0A $8B $44 $0C $2D $0080W
%patch $10108 $89 $47 $0C $8B $44 $0A $8B $1E $D6 $A7 $3B $47 $0A $73 $0B $8B $1E $D8 $A7 $C7 $47 $0E $0001W $EB $09 $8B $1E $D8 $A7 $C7 $47 $0E $FFFFW $8B $1E $D8 $A7 $C7 $47 $10 $0001W $B8 $21B6W $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0001W $C7 $47
#Make left shell
$02 $0003W $8B $44 $0A $89 $47 $0A $8B $44 $0C $89 $47 $0C $C7 $47 $16 $FFE4W $C7 $47 $18 $FFD8W $B8 $215CW $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0001W $C7 $47 $02 $0003W $8B
#Make right shell
$44 $0A $89 $47 $0A $8B $44 $0C $89 $47 $0C $C7 $47 $16 $001CW $C7 $47 $18 $FFD8W $B8 $217AW $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0001W $C7 $47 $02 $0003W $8B $44 $0A $89 $47
#Make up shell
$0A $8B $44 $0C $89 $47 $0C $C7 $47 $16 $0000W $C7 $47 $18 $FFC8W $B8 $2198W $50 $53 $9A $09DC118CRL $83 $C4 $04 $5F $5E $5D $CB

Egg without up fragment

This is the Egg collision without the up shell fragment. That is, it produces only four sprites when it hatches. It will be noticed that the code is 4 lines shorter and that the value $00136 has been changed to $00FAW (Made $3C smaller, this is important or the game will crash.) It is slightly more complicated to remove another shell fragment from the code, but it involves little more than repeating the changes seen here.

Patch: Keen 4
#Egg collision without up shell
%patch $100A7 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $03 $74 $08 $83 $3D $02 $74 $03 $E9 $00FAW $83 $3D $03 $75 $09 $57 $9A $0D8F0D43RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $02 $0003W $B8
#Make large shell
$213EW $50 $56 $9A $09DC120ARL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $001BW
#Make Bird
$C7 $47 $02 $0001W $8B $44 $0A $89 $47 $0A $8B $44 $0C $2D $0080W
%patch $10108 $89 $47 $0C $8B $44 $0A $8B $1E $D6 $A7 $3B $47 $0A $73 $0B $8B $1E $D8 $A7 $C7 $47 $0E $0001W $EB $09 $8B $1E $D8 $A7 $C7 $47 $0E $FFFFW $8B $1E $D8 $A7 $C7 $47 $10 $0001W $B8 $21B6W $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0001W $C7 $47
#Make left shell
$02 $0003W $8B $44 $0A $89 $47 $0A $8B $44 $0C $89 $47 $0C $C7 $47 $16 $FFE4W $C7 $47 $18 $FFD8W $B8 $215CW $50 $53 $9A $09DC118CRL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0001W $C7 $47 $02 $0003W $8B
#Make right shell
$44 $0A $89 $47 $0A $8B $44 $0C $89 $47 $0C $C7 $47 $16 $001CW $C7 $47 $18 $FFD8W $B8 $217AW $50 $53 $9A $09DC118CRL $83 $C4 $04 $5F $5E $5D $CB

Egg without small shell fragments

This is the Egg collision without any of the shell fragments. That is, it produces only two sprites when it hatches. It will be noticed that the code is 12 lines shorter and that the value $00136 has been changed to $0082W (Made $B4 smaller.)

Patch: Keen 4
#Egg collision without shell fragments
%patch $100A7 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $03 $74 $08 $83 $3D $02 $74 $03 $E9 $0082W $83 $3D $03 $75 $09 $57 $9A $0D8F0D43RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $02 $0003W $B8
#Make large shell
$213EW $50 $56 $9A $09DC120ARL $83 $C4 $04 $B8 $0001W $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $001BW
#Make Bird
$C7 $47 $02 $0001W $8B $44 $0A $89 $47 $0A $8B $44 $0C $2D $0080W
%patch $10108 $89 $47 $0C $8B $44 $0A $8B $1E $D6 $A7 $3B $47 $0A $73 $0B $8B $1E $D8 $A7 $C7 $47 $0E $0001W $EB $09 $8B $1E $D8 $A7 $C7 $47 $0E $FFFFW $8B $1E $D8 $A7 $C7 $47 $10 $0001W $B8 $21B6W $50 $53 $9A $09DC118CRL $83 $C4 $04 $5F $5E $5D $CB

Egg just produces big shell

Here the egg simply changes into a piece of shell when hatching. This is in effect a sprite transformation which can be useful in many situation. The bird code has been totally removed. The value $00136 has been changed to $0024W (Made $112 smaller.)

Patch: Keen 4
#Egg collision only produces shell
%patch $100A7 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $03 $74 $08 $83 $3D $02 $74 $03 $E9 $0024W $83 $3D $03 $75 $09 $57 $9A $0D8F0D43RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $02 $0003W $B8
#Make large shell
$213EW $50 $56 $9A $09DC120ARL $83 $C4 $04 $5F $5E $5D $CB

Egg doesn't remove shot

This code removes the 'destroy sprite' code and check making the code $0E bytes shorter. What this means is that Keen's shot will pass straight through the egg, hatching it. This can be combined with any of the patches above, as long as the $E9 $xxxxW value is made $0E smaller. Here it is combined with the 'shell only' patch above.

Patch: Keen 4
#Egg collision doesn't stop bullets
%patch $100A7 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $03 $74 $08 $83 $3D $02 $74 $03 $E9 $0016W $C7 $04 $0001W $C7 $44 $02 $0003W
#Make large shell
$B8 $213EW $50 $56 $9A $09DC120ARL $83 $C4 $04 $5F $5E $5D $CB

An alternative is to leave the code as it is and replace the string $9A $0D8F0D43RL with $90. This avoids having to alter the 'end jump' value.

Patch: Keen 4
#Egg collision doesn't stop bullets, alternate version
%patch $100A7 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $03 $74 $08 $83 $3D $02 $74 $03 $E9 $0024W $83 $3D $03 $75 $09 $57 $90 $90 $90 $90 $90 $83 $C4 $02 $C7 $04 $0001W $C7 $44 $02 $0003W $B8
#Make large shell
$213EW $50 $56 $9A $09DC120ARL $83 $C4 $04 $5F $5E $5D $CB

Egg can hatch multiple times

This code allows Keen to shoot the egg as many times as he wants, each time it will 'hatch', producing shell and a flying (Not hatched!) Blue Bird. If Keen touches the Egg it will hatch normally. This code can be combined with any of the above code except the 'don't stop bullet' code. (They are incompatible, the bullet will be stopped when the below code is included.)

A side effect is that the shot will vanish instead of smashing. Notice that this code replaces the three byte string $8B $76 $06 in the above patches with $90 $90 $90.

Patch: Keen 4
%patch $100A7 $55 $8B $EC $56 $57 $90 $90 $90


There is little to say about Egg animations except that they are separate from Blue Bird ones. This means that the game will crash if an Egg is hatched in a level with an Egg but no Blue Bird (The hatched bird will be to blame.) Notice also the 'animation speed' values are not really useful for anything but the hatched bird due to the action type used. (In theory the Egg's time is how quickly it will hatch and the shells' times are how long before they vanish, but this doesn't work out in-game.)

The hatched bird's animation speed is how long it will wait before going after Keen, this may matter a lot.

Patch: Keen 4
%patch $30718 $016AW
#Egg Cache start
%patch $30762 $016EW
#Egg cache end
%patch $30F90 $016AW $016AW %patch $30F9A $0008W
#Animation speed
%patch $30FAE $016BW $016BW
#Big shell
%patch $30FB8 $7530W
#Animation speed
%patch $30FCC $016CW $016CW
#Left shell
%patch $30FD6 $0000W
#Animation speed
%patch $30FEA $016DW $016DW
#Right shell
%patch $30FF4 $0000W
#Animation speed
%patch $31008 $016EW $016EW
#Up shell
%patch $31012 $0000W
#Animation speed
%patch $31026 $0173W $016FW
#Hatched bird
%patch $31030 $0078W
#Animation speed

Sprite positioning

The most important positioning patches is the location of the hatched bird produced when Eggs collide. Here $05 is +ve, $2D -ve, $0A horizontal, $0C vertical. By default the hatched bird appears half a tile (8 pixels) higher than the Egg from which it hatched.

Eggs themselves are spawned 7 pixels higher than where they are placed in-level, to make their bottom level with the ground. Changing the egg sprite height will require changing this as well as the bird spawn height.

Patch: Keen 4
#Vertical location of egg
%patch $1000D $FF8F $7 pixels up
#Vertical location of hatched bird
%patch $10104 $0C $2D $0080W

Clipping and foreground

The Egg's foreground variable is set when it is spawned.

Patch: Keen 4
%patch $FFFB $0002W

Sprite-tile interaction

There are two different sprite-tile interactions used here, the first is used by the Egg and large piece of shell, it is the 'sit' value and basically ignores all tiles.. The second is 'fall', sprites using it will fall until they hit solid tiles. This is used by everything else, including the hatched bird. (So if it is spawned too high it will quickly fall and land.)

Patch: Keen 4
%patch $30FA8 $09DC176ERL
#Egg (Sit)
%patch $30FC6 $09DC176ERL
#Large shell (Sit)
%patch $30FE4 $0FA8097FRL
#Left shell (Fall)
%patch $31002 $0FA8097FRL
#Right shell (Fall)
%patch $31020 $0FA8097FRL
#Up shell (Fall)
%patch $3103E $0FA808A1RL
#Hatched Bird (Fall)

Action type

Notable here is that the Egg, bird and big shell use type 0 while the shell fragments use type 2 (Used for stunned sprites normally.)

Patch: Keen 4
%patch $30F94 $0002W
#Egg spawn
%patch $30FB2 $0000W
#Big bit of broken shell
%patch $30FD0 $0002W
#Left shell
%patch $30FEE $0002W
#Right shell
%patch $3100C $0002W
#Up shell
%patch $3102A $0000W
#Hatched bird

Deprotect and stick to ground

Most sprites here have both values as zero, as expected (The egg has a stick to ground value of 1 even though it doesn't move.) The Bird sticks to the ground, as expected since it must walk upon it.

Patch: Keen 4
%patch $30F96 $0000W $0001W
#Egg spawn
%patch $30FB4 $0000W $0000W
#Large shell
%patch $30FD2 $0000W $0000W
#Left shell
%patch $30FF0 $0000W $0000W
#Right shell
%patch $3100E $0000W $0000W
#Up shell
%patch $3102C $0000W $0001W
#Hatched bird

Sprite spawn code

In the initiation code notice the Egg cache being set ($C7 $06 $CB83W $0001W.) Notice however that a second cache,t he Bird's cache is also set in $C7 $06 $CB5FW $0001W. This is because the Egg and Bird are linked. If the Egg and Bird are decoupled then this second cache is not needed.

The last blue highlighted value is the sprite action the egg 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 up the egg is spawned from where it is placed, in this case it makes the bottom of the egg level with the ground.

$C7 $47 $0E $xxxxW is the horizontal direction the sprite starts moving in, either $0001W (Facing right), $FFFFW (Facing left) or $0000W (Neither, never used.) $C7 $47 $10 $xxxxW is the vertical direction and works similarly. Eggs are spawned moving down and right for no particular reason.

Patch: Keen 4
#Location of initiation code
%patch $EE9D $0211W
#Egg (At $EB01)
#Egg Initiation code
%patch $EB01 $FF $76 $FC $57 $9A $0FA8055DRL $83 $C4 $04 $C7 $06 $CB5FW $0001W $C7 $06 $CB83W $0001W $E9 $02E1W
#Egg spawn code
%patch $FFDD $55 $8B $EC $33 $C0 $50 $9A $06BD1E11RL $83 $C4 $02 $8B $1E $D8 $A7 $C7 $07 $0008W $C7 $47 $02 $0001W $C7 $47 $20 $0002W $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $05 $FF8FW $89 $47 $0C $C7 $47 $0E $0001W $C7 $47 $10 $0001W $B8 $2120W $50 $53 $9A $09DC118CRL $83 $C4 $04 $5D $CB