Patch:Keen Flipping Switches

From KeenWiki
Jump to: navigation, search

This page contains patches relating to Keen flipping switches in Keen 4 and Keen 5. That is, such things as the sprites used, the speeds and sounds. It does not cover patches relating to bridges and switches themselves or the tiles used. These can be found at Patch:Bridges and switches. This page 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.

Keen can also flip switches in Keen 6. However he uses another mechanism by default (Jumping on switches). Keen Vorticons involves both light and bridge switches, but these too don't involve Keen's sprite behavior or unique actions. As such, patches relating to them can be found on their respective page.


Sprite Actions

The switch flipping sequence consists of two actions, one preparing to flip and one that flips before returning to normal.Before he flips a switch he needs to adjust his position. This actin is also sued when placing keygems and entering doors. As such it is best not messed with.


Keen 4

Keen's switch flipping can be difficult to understand. On initially looking up in front of a switch tile Keen starts his 'adjust position' action. This lines him up with the switch tile so he can properly animate it and get the switch co-ordinates. This action has no standard next action, it continues until something like a switch tile or keygem holder instructs it what to do next. A switch tile sends Keen into the flip switch sequence.

The flipping sequence has two actions, starting and finishing. When finished Keen is returned to his standing action. The second action is in fact shared with Keen finishing placing keygems.

Actions:
$098CW #Keen standing
$0DE2W #Keen starts flicking switches
$0E00W #Keen finishes flicking switches\placing gems
$0E3CW #Keen adjust position

Patch: Keen 4
#Move into position with switch
%patch $B994 $0E3CW
#Adjust position sequence (Do nothing)
%patch $2FCC8 $0000W
#Start flipping the switch tile
%patch $B99B $0DE2W
#Flipping sequence
%patch $2FC6E $0E00W %patch $2FC8C $098CW


Keen 5

Actions:
$0888W #Keen standing
$0C66W #Keen starts flicking switches
$0C84W #Keen finishes flicking switches
$0CC0W #Keen adjust position

Patch: Keen 5
#Move into position with switch
%patch $AC7D $0CC0W
#Adjust position sequence (Do nothing)
%patch $3101C $0000W
#Start flipping the switch tile
%patch $AC84 $0C66W
#Flipping sequence
%patch $30FC2 $0C84W %patch $30FE0 $0808W


Sprite Behavior

There is only one behavior relating solely to Keen flipping switches, it is used by the first flipping action. The second action has no behavior and acts as a 'pauser' to lengthen the sequence. The position adjusting action has its own complex behavior that determines what action it goes to next.

Patch: Keen 4 behaviors
#Adjust position
%patch $2FCBC $0B8007D8RL
#Flicking sequence
%patch $2FC62 $0B8008B9RL %patch $2FC80 $00000000L

Patch: Keen 5 behaviors
#Adjust position
%patch $31010 $0AAF08ADRL
#Flicking sequence
%patch $30FB6 $0AAF09BARL %patch $30FD4 $00000000L


Behavior code

This is the complete code for Keen flipping switches. The first part of the code reads the switches infoplane value behind the switch. Next up the switch tile itself is animated, followed by the switch sound. After this the code splits in two, one section for bridge switches, another for platform switches.

Patch: Keen 4 behaviors
#Keen flip switches behavior =0B8008B9RL
%patch $C0B9 $55 $8B $EC $83 $EC $16 $56 $57 $8B $5E $06 $8B $5F $2E $D1 $E3 $8B $87 $25 $C9 $D1 $E8 $5E8BW $06 $03 $47 $34 $89 $46 $F2 $8B $5E $F2 $D1 $E3 $8E $06 $E9 $26A7W $8B $07 $89 $46 $FC $8B $5E $FC $8E $06 $A1 $C8 $26 $8A $87 $42 $39 $98 $8B $56 $FC $03 $D0 $89 $56 $FA $8B $5E $F2 $D1 $E3 $8E $06 $EB $A7 $26 $8B $07 $89 $46 $F8 $B1 $08 $D3 $E8 $4689W $F6 $8B $46 $F8 $25 $FF $00 $89 $46 $F4 $8B $5E $FC $8E $06 $A1 $C8 $26 $8A $87 $A6 $44 $B4 $00 $89 $46 $FE $B8 $0001W $50 $50 $8B $5E $06 $FF $77 $2E $FF $77
#Animate switch
$34 $50 $16 $8D $46 $FA $50 $9A $16540F28RL $83 $C4 $0E $B8
#Sound
$0015W $50 $9A $187409F1RL $83 $C4 $02 $83 $7E $FE $0F $74
#Bridge switch jump
$03 $E9 $00A4W $8B $7E $F4 $E9 $008BW $8B $DF $D1 $E3 $8B $87 $25 $C9 $D1 $E8 $E0D1W $8B $16 $E9 $8BA7W $5E $F6 $D1 $E3 $03 $C3 $52 $50 $3B $7E $F4 $74 $05 $B8 $0001W $EB $02 $33 $C0 $D1 $E0 $5A $2B $D0 $58 $89 $46 $F0 $89 $56 $EE $3B $7E $F4 $74 $05 $B8 $0001W $EB $02 $33 $C0 $8B $56 $F6 $2B $D0 $8B $F2 $EB $3E $C4 $5E $EE $26 $8B $07 $89 $46 $EC $83 $46 $EE $02 $8B $5E $EC $8E $06 $A1 $C8 $26 $8A $87 $42 $39 $88 $46 $EB $98 $0B $C0 $74 $23 $8A $46 $EB $98 $01 $46 $EC $B8 $0001W $50 $50 $57 $56 $50 $16 $8D $46 $EC $50 $9A $16540F28RL $83 $C4 $0E $46 $3B $36 $E4 $A7 $72 $BC $47 $8B $46 $F4 $05 $02 $00 $3B $C7 $76 $03 $E9 $FF68W $5F $5E $8B $E5 $5D $CB $8B $5E $F4 $D1 $E3 $8B $87 $25
#B switch
$C9 $D1 $E8 $E0D1W $8B $16 $EB $A7 $8B $5E $F6 $D1 $E3 $03 $C3 $89 $56 $F0 $89 $46 $EE $C4 $5E $EE $26 $8B $07 $89 $46 $EC $35 $001FW $26 $89 $07 $5F $5E $8B $E5 $5D $CB


Speed

Keen does not move while flipping switches, to do so would misalign him with the switch and cause the flip to fail. He does move when adjusting his position, but this is defined elsewhere and is best not altered.

Patch: Keen 4 action speeds
#Adjust position
%patch $2FCB8 $0000W $0000W
#Flipping switches
%patch $2FC5E $0000W $0000W %patch $2FC7C $0000W $0000W

Patch: Keen 5 action speeds
#Adjust position
%patch $3100C $0000W $0000W
#Flipping switches
%patch $30FB2 $0000W $0000W %patch $30FD0 $0000W $0000W


Sprite Collision

Keen uses no sprite collision when flipping switches. This means he cannot interact with point items and a few other things while doing so. It also makes him temporarily invincible.

Patch: Keen 4 sprite collisions
#Adjust position
%patch $2FCC0 $00000000L
#Flipping switches
%patch $2FC66 $00000000L %patch $2FC84 $00000000L

Patch: Keen 5 sprite collisions
#Adjust position
%patch $31014 $00000000L
#Flipping switches
%patch $30FBA $00000000L %patch $30FD8 $00000000L


Animations

Keen uses one animation when flipping switches the 'facing away from screen' animation. He also uses this when adjusting his position. That action has no animation timer as it must take as long as needed to align Keen with the right tiles.

Patch: Keen 4
#Adjust position
%patch $2FCAC $00C4W $00C4W %patch $2FCB6 $0000W
#Flicking switches
%patch $2FC52 $00C4W $00C4W %patch $2FC5C $0008W
#Pause before flip
%patch $2FC70 $00C4W $00C4W %patch $2FC7A $0008W
#Pause before done

Patch: Keen 5
#Adjust position
%patch $31000 $00AFW $00AFW %patch $3100A $0000W
#Flicking switches
%patch $30FA6 $00AFW $00AFW %patch $30FB0 $0008W
#Pause before flip
%patch $30FC4 $00AFW $00AFW %patch $30FCE $0008W
#Pause before done


Sprite-tile interaction

Keen uses the same tile collision as he does when standing or doing other 'normal' things. When adjusting his position he uses a general 'show sprite' interaction that is harder to disrupt,preventing him getting 'stuck' when aligning himself to switches.

Patch: Keen 4 tile collisions
#Adjust position
%patch $2FCC4 $09DC176ERL
#Flicking switches
%patch $2FC6A $0B801AA2RL %patch $2FC88 $0B801AA2RL

Patch: Keen 5 tile collisions
#Adjust position
%patch $31018 $090B17B5RL
#Flicking switches
%patch $30FBE $0AAF1AC6RL %patch $30FDC $0AAF1AC6RL


Action type

Keen's flipping actions are type 0, meaning their behaviors and movement are called only once during the action. This prevents 'multiple flipping' when Keen flips a switch. His adjust position action is type 2, allowing smooth movement and rapid checking for the right tiles.

Patch: Keen 4
#Adjust position
%patch $2FCB0 $0002W
#Flip switches
%patch $2FC56 $0000W %patch $2FC74 $0000W

Patch: Keen 5
#Adjust position
%patch $31004 $0002W
#Flip switches
%patch $30FAA $0000W %patch $30FC8 $0000W


Deprotect and stick to ground

Both of Keen's flipping actions use the 'stick to ground' variable, possibly as a precaution.

Patch: Keen 4
#Adjust position
%patch $2FCB2 $0000W $0000W
#Flip switches
%patch $2FC58 $0000W $0001W %patch $2FC76 $0000W $0001W

Patch: Keen 5
#Adjust position
%patch $31006 $0000W $0000W
#Flip switches
%patch $30FAC $0000W $0001W %patch $30FCA $0000W $0001W