Patch:Berkeloid

This page covers patches relating to the Berkeloids in Keen 4. The Berkeloids appear in only one level, the Isle of Fire. They are known for throwing balls of fire that become taller when they hit the ground before vanishing.

Berkeloids use sprite type 14 which is used only by the Berkeloid and its flame and doesn't affect anything else. When an Berkeloid throws a flame, its sprite type must also be set. This doesn't have to be the same as the Berkeloid.

The Berkeloid has a large number of actions, for various reasons. The Berkeloid is spawned floating, and does so in a four frame cycle. While floating it can randomly begin the fireball sequence. Midway through the flaming sequence an airborne flame is created.

The airborne flame will remain the same until it lands, at which point it will turn into a landed flame. This will initially be big, but then grow smaller and eventually vanish.

The Berkeloid's behaviors are interesting. The floating Berkeloid has its own behavior where it can attack Keen. The attacking Berkeloid uses a generic 'float' behavior, except for when it is producing a fireball to throw at keen. Just before returning to floating it uses a 'start floating again' behavior to avoid floating bugs. The Berkeloid's flame uses a generic 'move through the air and hit the ground' behavior while airborne, and no behavior at all when it has landed.

Make flame code

This is the complete code for the Berkeloid producing a flame. On the second line the flame's activity is set to 3, ensuring it will stay active offscreen and not surprise the player. Its sprite type is set as $0E. On the third line the flame's vertical spawn position is set as half a tie (8 pixels or $0080W) down from the top of the Berkeloid and its vertical speed is set as -8 ($FFF8W or slightly upwards.)

On line 4 the game checks to see which way the Berkeloid is facing, if it is facing right then the flame's Vertical speed is set to 48 ($0030W), it is spawned 2 tiles right ($05 $0200W) of the Berkeloid's left edge and its horizontal direction is set to 1. Otherwise its speed is set to -48 ($FFD0W), it is spawned one tile left ($2D $0100W) of the Berkeloid's left edge and its horizontal direction is set to -1.

On the last lines the flame's action is set ($2CD8W) and the Berkeloid's Misc C variable is set to 1, important for its hovering above the ground code.

Berkeloids will randomly head towards Keen. If Keen is close enough they will also throw significantly more fireballs.

Patch: Keen seeking

#Randomly turn and head towards Keen

%patch $10C2D$FFFFW%patch $10C32$0001W

#V distance next to Keen to throw more fireballs:

%patch $10C6D$FF00W

#-1 tile

%patch $10C75$0100W

#+1 tile

Berkeloids ignore Keen

It is possible for the Berkeloids to ignore Keen when he is behind them, or ignore him completely. They will still throw the occasional fireball, but will not chase him. There are two patches, each independent for this.

Patch: Keen seeking

#Ignore Keen behind Berkeloids

%patch $10C1C $00

#Ignore Keen totally

%patch $10C32 $FFFFW

Berkeloids ignore gravity

This patch stops the Berkeloids responding to gravity; they will float across cliffs and cannot move down hills, instead floating into the air.

Patch: Berkeloids ignore gravity

#Berkeloids ignore gravity

%patch $10E7D $EB

Berkeloid's shots move horizontally

This patch makes the Berkeloid's shots move horizontally, like Keen's. They will also smash on walls. The first section alters the Berkeloid's shots actions; wiping its 'fall' behavior, changing the way it moves and giving it a horizontal speed. The second section alters its tile interaction so that it will smash on walls instead of sticking to them. Omitting it will cause the Berkeloid's shots to not be destroyed if they hit a wall, staying there indefinitely and possibly crashing the game.

Nearly all of the motion that affects Berkeloids is found in their behavior, the horizontal floating speed is determined in this way though. Berkeloid hovering is complex. They hover an average of 1 tile up, moving between a lower height of 8 pixels lower and an upper height of 0 pixels difference from this. (Matching the total hover range of 8 pixels.)

Flame's horizontal speeds depend on what direction it is fired (Either right or left.) the horizontal speed reduces to 0 when it hits a wall. Flames are given an upwards speed as well.

Patch: Animation motion

#Floating

%patch $31974$0008 $0000W

#Speed 1

%patch $31992$0008 $0000W

#Speed 2

%patch $319B0$0008 $0000W

#Speed 3

%patch $319CE$0008 $0000W

#Speed 4

#Tossing fire

%patch $319EC$0000W $0000W

#Speed 1

%patch $31A0A$0000W $0000W

#Speed 2

%patch $31A28$0000W $0000W

#Speed 3

%patch $31A46$0000W $0000W

#Speed 4

%patch $31A64$0000W $0000W

#Speed 5

%patch $31A82$0000W $0000W

#Speed 6 (Flame has been tossed)

%patch $31AA0$0000W $0000W

#Speed 7

%patch $31ABE$0000W $0000W

#Speed 8

%patch $31ADC$0000W $0000W

#Speed 9

%patch $31AFA$0000W $0000W

#Speed 10

%patch $31B18$0000W $0000W

#Speed 11

%patch $31B36$0000W $0000W

#Speed 12 (Go to floating)

#Flame while in air

%patch $31B54$0000W $0000W

#Speed 1

%patch $31B72$0000W $0000W

#Speed 2

#Flame landed on ground

%patch $31B90$0000W $0000W

#Speed 1 (Starts off 'tall')

%patch $31BAE$0000W $0000W

#Speed 2

%patch $31BCC$0000W $0000W

#Speed 3

%patch $31BEA$0000W $0000W

#Speed 4

%patch $31C08$0000W $0000W

#Speed 5

%patch $31C26$0000W $0000W

#Speed 6 (Shrinks)

%patch $31C44$0000W $0000W

#Speed 7

%patch $31C62$0000W $0000W

#Speed 8

%patch $31C80$0000W $0000W

#Speed 9 (Disappears)

Patch: Other speeds

#How much Berkeloids hover

%patch $10DE7$FF00W

#Float level (1 tile up)

%patch $10DEC$0008W

#Hover up/down range (8)

%patch $10DD4$0000W

#Min hover bound (0)

%patch $10DD9$FFF8W

#Max hover bound (-8)

#Berkeloid flame speeds:

%patch $10CDB$0030W

#Right

%patch $10CF4$FFD0W

#Left

%patch $10CD0$FFF8W

#Vertical (Up.)

%patch $10D74$0000W

#When hits walls (Fall down, don't bounce off)

Berkeloid doesn't float

This patch stops the Berkeloid floating, instead it will walk back and forth like most sprites.

The Berkeloid collision is simple, it blocks Keen's shots while also killing him.

Collision values

The Berkeloid uses its own special collision that blocks Keen's shots and kills him. The airborne flame uses a generic 'kill Keen' collision also used by other sprites.

Patch: Keen 4 collision values

#Walking

%patch $3197C $10800530RL

#Berkeloid

%patch $3199A $10800530RL

#Berkeloid

%patch $319B8 $10800530RL

#Berkeloid

%patch $319D6 $10800530RL

#Berkeloid

#Tossing flame

%patch $319F4 $10800530RL

#Berkeloid

%patch $31A12 $10800530RL

#Berkeloid

%patch $31A30 $10800530RL

#Berkeloid

%patch $31A4E $10800530RL

#Berkeloid

%patch $31A6C $10800530RL

#Berkeloid

%patch $31A8A $10800530RL

#Berkeloid

%patch $31AA8 $10800530RL

#Berkeloid

%patch $31AC6 $10800530RL

#Berkeloid

%patch $31AE4 $10800530RL

#Berkeloid

%patch $31B02 $10800530RL

#Berkeloid

%patch $31B20 $10800530RL

#Berkeloid

%patch $31B3E $10800530RL

#Berkeloid

#Flame in air

%patch $31B5C $09DC1752RL

#Misc kill

%patch $31B7A $09DC1752RL

#Misc kill

#Flame on ground (Collide like a Berkeloid)

%patch $31B98 $10800530RL

#Berkeloid

%patch $31BB6 $10800530RL

#Berkeloid

%patch $31BD4 $10800530RL

#Berkeloid

%patch $31BF2 $10800530RL

#Berkeloid

%patch $31C10 $10800530RL

#Berkeloid

%patch $31C2E $10800530RL

#Berkeloid

%patch $31C4C $10800530RL

#Berkeloid

%patch $31C6A $10800530RL

#Berkeloid

%patch $31C88 $10800530RL

#Berkeloid

Berkeloid doesn't harm Keen

The following patch stops the Berkeloid killing Keen on contact. (Its flames are still lethal and it will still block his shots.)

Patch: Berkeloid doesn't harm Keen

#Berkeloid doesn't harm Keen

%patch $10D42 $09

Berkeloid is stunnable

This patch changes the Berkeloid's collision code so that it kills Keen but can be shot. In this patch it merely vanishes after being shot, transforming into a raindrop splash, but a custom stunned action can easily be crated.

Collision code

This is the complete collision code for the Berkeloid. On the second line it checks for Keen's shots, if found the shot is smashed. On the third line it checks for Keen,if found the 'kill Keen' code is called.

There is little to say about the Berkeloid's animations except that the landed flame uses some of the same animations as the airborne flame and that the floating animation speed can also affect the floating horizontal speed.

The Berkeloid's foreground value is set on spawning at 2. This makes it appear in front of most sprites and foreground tiles (Excepting those set to be in front of all sprites.) This is useful since it must float close to many types of ground.

The floating Berkeloid has its own special collision allowing it to float up and down hills and not over edges. When throwing fire it uses a related collision that allows it to maintain floating while not moving. The airborne flame has a third collision that transforms it into a landed flame when it hits floors. (As well as allowing it to hit walls.) Finally the landed flame uses a generic 'sit' collision, ignoring most tiles.

Patch: Keen 4

#Berkeloid float

%patch $31980 $10800610RL

#Floating

%patch $3199E $10800610RL

#Floating

%patch $319BC $10800610RL

#Floating

%patch $319DA $10800610RL

#Floating

#Flame

%patch $319F8 $108005B5RL

#Ready to flame

%patch $31A16 $108005B5RL

#Flaming

%patch $31A34 $108005B5RL

#Flaming

%patch $31A52 $108005B5RL

#Flaming

%patch $31A70 $108005B5RL

#Flaming

%patch $31A8E $108005B5RL

#Flaming

%patch $31AAC $108005B5RL

#Flaming

%patch $31ACA $108005B5RL

#Flaming

%patch $31AE8 $108005B5RL

#Flaming

%patch $31B06 $108005B5RL

#Flaming

%patch $31B24 $108005B5RL

#Flaming

%patch $31B42 $108005B5RL

#Flaming

#Airborne flame

%patch $31B60 $1080055ERL

#Tossed flame

%patch $31B7E $1080055ERL

#Tossed flame

#Landed flame

%patch $31B9C $09DC176ERL

#Sit

%patch $31BBA $09DC176ERL

#Sit

%patch $31BD8 $09DC176ERL

#Sit

%patch $31BF6 $09DC176ERL

#Sit

%patch $31C14 $09DC176ERL

#Sit

%patch $31C32 $09DC176ERL

#Sit

%patch $31C50 $09DC176ERL

#Sit

%patch $31C6E $09DC176ERL

#Sit

%patch $31C8C $09DC176ERL

#Sit

Flame interaction code

This is the tile interaction code for the Berkeloid's flame. The first line checks if the tile is blocking right; if it is then the next check is skipped. The next check on line two checks if the tile is blocking left; if not the next segment of code is skipped. The next segment of code is thus run if the sprite is touching a tile that is blocking either right or left. (That is, a wall.) The code sets the sprite's horizontal speed to zero (So it falls straight down.) At the end of line two a third check is made to see if the tile is upwards blocking. If it is then sound $28 plays and the sprite's action changes to that of a landed flame (Both variables marked in blue.) This is the flame landing. The last three lines can be ignored; they simply draw the Berkeloid.

Tossing interaction code

This is the tile interaction code for the Berkeloid tossing a flame. It is also called by the Berkeloid's floating tile interaction, so anything affecting this will also have an effect on the floating Berkeloid. Notably this interaction code controls the Berkeloid's floating limits, such as how high up it floats and how much.

On the second line the Berkeloid's Misc Variable B is checked, if it is larger than 0 then it is reset to 0 and the hover direction is set to -8 ($FFF8W). Otherwise the same variable is checked again on line 3 and, if it is less than -256 ($FF00W) then it is set to -256 and the hover direction set to +8. Taken together this sets the minimum and maximum hover bounds (0 and -256) and also the hover rate (+/-8) the Berkeloid uses.

Float interaction code

This is the tile interaction code for the Berkeloid floating. On the first line the Berkeloid's horizontal movement direction is checked; if it is not moving right the next check is skipped. The next check is for right walls. If the Berkeloid has hit a right wall it turns left. On line 4 the same two checks occur, this time checking if the Berkeloid is moving left and, if so, whether it has hit a left wall in which case it turns right.

On line 7 the Berkeloid checks for floors; if absent then the Berkeloid will turn around. This code is complex and opaque. Note however that the code $56 $0E $E8 $FF09W $83 $C4 $02 at the end calls the Berkeloid's flaming code.

The Berkeloid uses type 0 for all its actions except when it is floating, which is type 1 to ensure smooth movement. Likewise falling flames are type 3, allowing smooth movement and instant reaction to hitting the ground.

There are three random events that affect the Berkeloid. The first is the chance of the Berkeloid spawning facing left, this is 50%. The second is the chance that the Berkeloid will randomly turn to face Keen and chase him, this is 12.5%. Finally there is the probability that the Berkeloid will throw fireballs at Keen, this is about 3% if Keen is far away, but 25% if Keen is close.

In the initiation code notice the Berkeloid cache being set ($C7 $06 $CB75W $0001W.) Also notice the three difficulties of Berkeloid that are possible.

In the spawning code the last blue highlighted value is the sprite action the Berkeloid uses as it proceeds to act in-level. $C7 $02 $xxxxW sets the sprite activity, $C7 $47 $06 $xxxxW sets the clipping,$C7 $07 $xxxxW sets the sprite type,$C7 $20 $xxxxW sets the foreground value., Finally $D3 $E0 $05 $xxxx is how far down (Or actually up) the Berkeloid is spawned from where it is placed. This is necessary because it 'walks' on the ground but can only be placed in the level at multiples of 16 pixels high while its actual sprite height can vary.

$C7 $47 $0E $xxxxW is the horizontal direction the Berkeloid 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. The Berkeloid has a probability check to determine which way it faces this is always 50:50 (Though it needn't be.) and the code responsible for this is $9A $1D02002ARL $3D $0080W