Patch:Sprite collision

From KeenWiki
Jump to navigation Jump to search

This page is a tutorial page on patching sprite collision. It contains information on what sprite collision is, how to patch it, and a list of the possible types for all Keen games. A sprite's collision is the pointer to the code the game calls whenever a sprite contacts the hitbox of another. (Both sprites involved will thus call their own collision code.) As such it is used extensively, especially in the Keen Dreams and Galaxy games where it is an integral part of galaxy actions. An integral part of sprite collision is the sprite type. This is related to Patch:Sprite strength


Pointers

Patching the sprite collision pointer is simple enough, it is a single two or four-byte patch. In Vorticons each sprite has only one value, set when the sprite is spawned. In Dreams\Galaxy each sprite action has its own pointer.

Vorticons patches are thus much more simple than Galaxy ones, in Vorticons each sprite has only one collision, usually relating to its death. In Galaxy simply changing a sprite's death can require a dozen patches, though as such it's much more versatile.

As a side note, in Vorticons the sprite behavior and sprite collision are closely related and can substitute for each other.

Keen 1

#Make a Yorp turn into a dead Garg when shot:
%patch $18D9 $1BCEW #Create shot Garg

Keen 4

#Arachnut cannot be shot when stunned
%patch $31274 $09DC1752RL #Stunned Arachnut action-do nothing


Following is a list of all the possible default values used by the games. It is now possible for a modder to create their own collision code at an arbitrary point in the executable and thus use non-default values, though this can be quite difficult to accomplish.


Values in games

Galaxy values are complex and it is advised Patch:Executable segments be consulted. Vorticons values are given here, these can also be found at Patch:Sprite behavior as noted above.


Keen 1:
$1A68W #Yorp collision
$1BCEW #Garg collision
$1D6EW #Vorticon collision
$1E94W #Butler Bot collision (Shots hit, keeps going)
$2045W #Tank Bot collision (Shots hit, keeps going)
$22A6W #Icecube collision
$22BBW #Chain collision (Make falling block)
$3360W #Do nothing
$47E8W #Sit and vanish (Zap\zot)
$4849W #Zap against not-Keen sprites (Keen's shot)
$4A00W #Tank bot's shot
Keen 2:
$3F8CW #Vorticon collision
$4093W #Vortikid collision
$4283W #Elite collision
$4507W #Scrub collision
$4677W #Robot collision (Shots hit it, keeps going)
$4716W #Tantalus ray collision
$61A2W #Do nothing
$775FW #Bullet collision
Keen 3:
$42D0W #Vorticon collision
$43D9W #Vortikid collision
$46C6W #Vortimom's shot collision
$470CW #Vortimom collision
$4898W #Meep collision
$49CDW #Vortninja collision
$4B7EW #Foob collision
$4E19W #Vanish, kill six to destroy MM arms (Purple spark)
$4EBEW #Vanish, remove most sprites, MM destroyed exit level, win if level 16 (Heart)
$6A00W #Do nothing
$7E6BW #Keen's shot collision
$8013W #Unknown, used by some zap\zots
Keen 4:
$00000000L     Nothing
$09DC1752RL    Misc kill: Kill Keen
$0B8014A9RL    Normal Keen
$0B801632RL    Keen with shifting screen
$0E8F1061RL    Swimming Keen
$0FA803EARL    Poison slug: Kill Keen or be one of two stunned slugs
$0FA804BERL    Mad Mushroom: Stop bullets, kill Keen
$0FA80627RL    Egg: spawn bird and shell if shot or touched by Keen
$0FA80840RL    Bird: Spawn stunned bird if shot, kill Keen if touched
$0FA8087ARL    Stunned Bird: Spawn stunned bird if shot
$0FA80B1CRL    Arachnut: Spawn stunned Arachnut if shot, kill Keen
$0FA80B48RL    Stunned Arachnut: Spawn stunned Arachnut if shot
$0FA80C57RL    Flying Skypest: Kill Keen, reverse motion if shot
$0FA80CB0RL    Grounded Skypest: Spawn squished Skypest if Keen pogos on it
$1080015DRL    Wormouth looking around: Unknown behavior
$1080017CRL    Wormouth biting: Kill Keen, spawn stunned Wormouth if shot
$1080037DRL    Sleeping Cloud: Spawn moving cloud if Keen touches
$10800530RL    Berkeloid: Kill Keen, stop bullets
$10800793RL    Inchworm: 12 make a foot
$108008D9RL    Foot: Take Keen to foot on map (Actually does nothing?!)
$10800938RL    Bounder: Spawn stunned bounder (with jump) if shot
$10800BFDRL    Lick: Spawn stunned Lick if shot
$10800C23RL    Lick flaming: Kill Keen, spawn stunned Lick if shot
$11A20279RL    Smirky: steal point tiles and sprites, spawn stunned Smirky if shot
$11A20559RL    Sneaking Mimrock: Spawn stunned Mimrock if shot
$11A2059FRL    Pouncing Mimrock: Kill Keen, spawn stunned Mimrock if shot
$11A209B0RL    Dopefish: Eat Schoolfish, swimkill Keen
$11A20D86RL    Mine: Kill Keen and produce exploded Mine
$11A21010RL    Wetsuit: Give Keen Wetsuit, end level
Keen 5-INCOMPLETE
$00000000L     Nothing
$090B1799RL    Deadly
$0AAF1597RL    Keen stand
$0AAF167FRL    Keen sit
$0F92149DRL    Volte Face
$0F921689RL    Enemy shot
$1102015CRL    Sparky
$11020615RL    Ampton
$1102085ARL    Slicestar
$11020A7CRL    Shelley walk
$11C4043ERL    Shikadi mine
$11C40456RL    Shikadi mine fragments (Destroys Q.E.D!)
$11C40A0DRL    Robo Red move (And shoot when shot at)
$11C40D61RL    Kill and block shots
$11C40AE6RL    Robo Red's shot
$11C40F32RL    Shikadi Master
$11C41173RL    Master's shots
$11C41403RL    Shikadi
$11C4174DRL    Shocksund
$11C4193BRL    Shocksund's shot
$11C41D16RL    Korath
Keen 6:
$00000000L     Nothing
$08F417EERL    Kill Keen
$0AA2144ARL    Keen: Keen's normal interaction
$0AA2154CRL    Keen: When screen is moving
$0EFC002DRL    Stand-on-able
$0EFC0006RL    Push Keen
$0EFC0574RL    Grabbiter
$0EFC0720RL    Rocket waiting for Keen
$0EFC082ERL    Rocket flying
$0EFC0BC4RL    Rocket unknown
$0EFC0E46RL    Satellite
$0EFC1053RL    Special items and Molly
$0EFC1902RL    Bloog
$0EFC1A37RL    Blooguard
$0EFC1C2DRL    Blooglet
$10CC019ARL    Nospike
$10CC07A3RL    Pink shot
$10CC08E5RL    Orbatrix float
$10CC0A41RL    Orbatrix bouncing
$10CC0ACCRL    Bip
$10CC0DFDRL    Bipship
$10CC0F38RL    Flect
$11CF00DDRL    Fleex
$11CF0306RL    Bobba (Immortal, deadly, shots smash against)
$11CF05E3RL    Sleeping Babobba
$11CF05B7RL    Babobba
$11CF086CRL    Ceilick
Keen Dreams:
$05E806C7RL    Flower Power and Boobus Bombs
$05E817FCRL    Keen
$07C5036ERL    Doors


Creating New Collisions

It is possible, from studying existing collisions, to create new, novel, ones. These can either overwrite an existing collision, or be placed somewhere else in the executable.

In the first case all that needs to be done is the writing of custom collision code. As an example the patch below (based on Patch:Egg code causes a sprite to vanish when it touches either Keen or Keen's shot. It is located where the old Egg collision was, so any sprite using the Egg collision uses it instead.

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
              [$0000W]  $50 $56 $9A $09DC120ARL     $83 $C4 $04 $5F $5E $5D $CB

This patch frees up $112 bytes of space, large enough to place another collision. Free space like this may be used to store novel collisions, leaving the default collisions free to be used. In this case the patcher will also need to write a custom pointer to this new code. In Keen Vorticons this is simple enough, the pointer is just the address of the code, new code at $ABCD is pointed to thusly:

Keen Vorticons Collision pointer

%patch $1234 $ABCDW

In Keen Galaxy things are more complex; as noted above pointers are 8 bytes long. (See Patch:Executable segments.) However there is a neat shortcut that makes creating new pointers a deal simpler; the original value for the Egg collision is $0FA80627, created when the executable was compiled, its value is in the form [Segment address] + [code offset] An pointer that points to the same code can be created by taking the collision code and adding '000' after the fourth character. (Here giving us the value $100A0007RL Thus code at $ABCDE is given a pointer of $ABCD000ERL:

Keen Galaxy Collision pointer

%patch $30FA4 $0FA80627RL #Egg-original
%patch $30FA4 $100A0007RL #Egg-new

Warning: This can cause problems due to the way code is called. If your new collision calls code nearby (Usually within the +-$1000) then the game can get confused and crash. A simple way to test if the code call is causing problems is to replace the $9A $xxxxxxxxRL string with $90 $90 $90 $90 $90. If this is the problem, a 'proper' pointer should be created.


Custom Collision Codes

This section includes collision codes that do not occur in the game by default or have been adapted from default collisions and thus may be used to make novel sprite collisions. Each collision can only be used for one episode of Keen, so it is worth paying attention to what episode it was written for.

Each of these collisions replaces the boss cheat and thus the first line of every patch will be the cheat disabling patch. (The line contains the string $EB $5C.) This is not strictly necessary since a good patcher can replace an existing collision or find alternate space, but all the patches in this section are set up this way for convenience.


Keen 1

All the example custom collisions used here use the $0AF2W patch space. This makes them incompatible with any other patches using this space unless they are modified. As noted above a sprite will use these collisions if given he collision pointer $0AF2W.


Vorticon type death

This is the complete collision code for a 'Vorticon type' collision. A sprite using this will cause the border to flash as it dies and can respond to Keen's and the Tank Robot's shots. The first two blue values are the sprite types the sprite responds to, each followed by a jump condition in brown. The next blue value is the sound played when the sprite dies normally followed by fourth that stops the sprite animating, the fifth is the number of frames to use in the stunned animation and the sixth is the sprite animation to use. The seventh and eighth are the shot sprite's behavior and sprite collision. The remaining blue values serve an unknown function. The last brown value calls the border flashing code; replace it with $90 $90 $90 to disable border flashing when the sprite dies.

To customize the collision it may pay to see Patch:Vorticons Sprite Parameters and maybe Patch:Shot sprites.

Vorticon-type collision

#Vorticon-type collision (78 bytes)
%patch $1D6E $55 $8B $EC $56 $57 $8B $76 $04 $8B $5E $06 $83 $3F [$0A] {$74} $05
             $83 $3F [$0B] {$75} $40 $8B $44 $24 $FF $4C $24 $0B $C0 $75 $36 $B8
             [$0027W]  $50 $E8 $A15FW  $44 $44 $C7 $44 $2A [$0000W]  $C7 $44 $2C
             [$0006W]  $C7 $44 $28 [$0052W]  $C7 $44 $34 [$3360W]  $C7 $44 $32 [$489DW]
                 {$E8 $0BCCW}  $8B $F8 $C7 $45 $08 [$0005W] $C7 $45 $22 [$4A45W]
             $C7 $45 $0A [$0000W] $5F $5E $5D $C3


Give an item, play sound and vanish

This collision causes the sprite that uses it to give an item such as the pogo or a keycard. when touched or shot. In the example here it reacts to Keen only; changing the $01 on the first line to $0A makes it react to his shot only.

When successfully hit several things happen. Firstly its type is set to 0, making it vanish immediately after. Next its collision is set to 'nothing' ($3360W) as a precaution against overreacting. Sound $22 is played (The 'get card' sound.) Finally variable $AAA0W (Number of red keycards) is increased by 1.

Replacing $E8 $B3E1W with $90 $90 $90 will remove the sound. What is given is also easily changed.

Keen 1

#Card collision, if Keen give red card, play sound, vanish
%patch $0AF2 $55 $8B $EC $56 $57 $8B $76 $04 $8B $7E $06 $83 $3D [$01] {$75} $16
             $C7 $04 [$0000W]  $C7 $44 $34 {$3360W}  $B8 [$0020W]  $50 $E8 $B3E1W
             $44 $44 $FF $06 {$AAA0W}  $5F $5E $5D $C3


When shot produce an item or another enemy

This is not a traditional collision as such but a modification of the shot sprite code. It does however have a similar patch structure and is explained on the linked page.


Keen 4

The collisions for Keen 4 can be tested by giving a sprite the collision value of $06BD0E6DRL.


Kill Keen

This collision will kill Keen when a sprite of some property touches another sprite. This is in fact the 'deadly' collision used by any invincible sprite that also harms Keen. (So altering the code here will affect multiple sprites. Thus it is better to copy this code somewhere else when patching it.)

The only things patchable here are the type checked for ($02) and jump condition as well as the code called. By default the code checks if a sprite is Keen, if so, it executes 'kill Keen', otherwise it skips this code. It is possible for Keen to die without touching the sprite involved, if the check type and conditions are changed.

Custom Keen 4 collision

#Custom collision: Kill Keen
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $C6 $4C $83 $3D
             [$02] {$75} $05 $9A $0B8013E9RL     $5F $5E $5D $CB


Kill Keen and block shots

This collision is used by multiple sprites in Keen 4 such as the Mad Mushroom. It blocks Keen's shots but doesn't stun and is dangerous to Keen. The first line checks for Keen's shot type and the second for Keen. If a shot is detected the 'smash shot' code is run; if Keen is detected then the 'kill Keen' code is run.

Custom Keen 4 collision

#Custom collision: Kill Keen and block shots sprite collision
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $C7 $4C $83 $3C  #Check for Keen's shot (Type 3)
             [$03] {$75} $0D $56 $9A $0D8F0D43RL     $83 $C4 $02 $5F $5E $5D $CB
             $83 $3C [$02] {$75} $05 $9A $0B8013E9RL     $5F $5E $5D $CB          #Check for Keen, kill


Change when touched

This collision causes a sprite to change if something touches it. In this case its action changes to nothing and it vanishes whenever Keen (and Keen alone) touches it. Tweaking this allows a sprite's clipping or animation or direction to change on contact.

Custom Keen 4 collision

#Custom collision: Change when touched sprite collision
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $05
             $C7 $44 $1C [$0000W]  $5F $5E $5D $CB


Spawn another sprite when shot

This collision causes the affected sprite to produce a second sprite when Keen's shot hits it. Rather than spawning the 'shot hit' sprite a sprite of the modder's choosing will be created. (Here the 'raindrop got' sprite.) This can be done as many times as the sprite is shot, allowing the sprite to act as a 'reserve' of sprites. It is also possible to change some of the properties of the sprite produced. (The two properties set here are of no consequence.)

This will not work with sprites that are not Keen's shot. The location here replaces the egg's collision.

Custom Keen 4 collision

#Custom collision: Spawn another sprite when shot
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $C6 $4C $83 $3D
             [$03] {$75} $16 $C7 $04 [$0001W]  $C7 $44 $02 [$0003W]  $B8 [$1F46W]  $50
             $56 $9A $09DC120ARL     $83 $C4 $04     $5F $5E $5D $CB


Deadly, become another sprite when shot

This is a combination of the above two collisions. A sprite using this will be deadly to Keen, but also be shootable, becoming another sprite when shot. This is what a lot of enemies in Keen use. Here the sprite's action changes to a burst raindrop.

This collision reacts to Keen by running the 'kill Keen' code and to Keen's shots by removing the shot and becoming another sprite. The first and second blue values are what sprite type to react to ($02 is Keen, $03 is his shot.) The first and third brown values (Both $75) are the jump conditions, in this case react ONLY to that sprite type and nothing else. The first brown $9A string is the 'kill Keen' code, the second is the 'remove shot' code.

This patch also allows two (sprite parameters) to be changed along with the sprite's action. In this example the clipping and horizontal speed are set to 1 and 0 respectively.

Custom Keen 4 collision

#Custom collision: Kill Keen And Become Another Sprite When Shot
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $09
             {$9A $0B8013E9RL}     $5F $5E $5D $CB $83 $3D [$03] {$75} $18 $C7 $44
             $16 [$0000W]  $C7 $44 $06 [$0001W]  $B8 [$1F46W]  $50 $57 $56 {$9A $09DC1695RL}
                         $83 $C4 $06 $5F $5E $5D $CB


Run Oracle Janitor windows when touched or shot

This collision will play the Oracle Janitor windows when the sprite is touched or shot (Depending on the value of the first blue variable.) and the sprite will then vanish (To prevent an infinite loop of windows; changing the $0000W value to another sprite action can be done, as long as it does not use the same collision.)

Custom Keen 4 collision

#Custom collision: Run Oracle Janitor windows when touched or shot
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $0F
             $C7 $44 $1C [$0000W]  $9A $0E8F07D9RL     $9A $16540D59RL     $5F
             $5E $8B $E5 $5D $CB


Save a Council Member when touched, stun if shot

This collision will run the saved council member code if Keen touches the sprite, that is the windows will appear, a member will be saved and the level exited. (Or the Oracle Janitor saved in the Pyramid of the Forbidden level.) and the game will be won if eight members have been saved.

If the sprite is shot, it will stun.

Custom Keen 4 collision

#Custom collision: Save a Council Member when touched, stun if shot
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $0A
             $C7 $06 $70 $7A [$0003W]  $5F $5E $5D $CB $83 $3D [$03] {$75} $18 $C7 $44
             $16 [$0000W]  $C7 $44 $06 [$0001W]  $B8 [$3674W]  $50 $57 $56 $9A $09DC1695RL
                         $83 $C4 $06 $5F $5E $5D $CB


If shot or touched vanish and give points

This collision makes a sprite shootable (But it will not stop Keen's shot.) When shot it will vanish into a raindrop splash and give the player 3000 points. If the $03 in the first line is changed to $02 it will vanish when Keen touches it. The amount of points given can also be altered. This patch affects the Poison Slug.

Custom Keen 4 collision

#Custom collision: When shot splash and give 3000 points
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$03] {$75} $11 #Check for Keen's shot (Type 3)
             $B8 [$0BB8W]  $50 $9A $06BD1EF2RL $83 $C4 $02 $C7 $44 $1C [$1F46W]  #Change action to rainsplash, give 3000
             $5F $5E $5D $CB


Can be 'picked up' by the player if they do not have it

This collision reacts to any sprite (Note: not just the player!) with a certain action if the player doesn't have something. The first line checks for a variable such as difficulty level or ammo while the second line checks the colliding sprite's action. If both conditions are met the sprite turns into a raindrop splash, plays a 'got' sound and increases a variable.

As set up here the sprite will react to Keen looking up if he doesn't have a wetsuit. It will then increase his wetsuit counter by 1 so that he cannot pick up any more of these sprites.

If the stat that is altered is not the same as the one looked for then any number of sprites may be acquired. It is also possible to set a different limit such as 9 or 20 sprites by changing the first condition. It is possible for a range of sprite actions to trigger the sprite by changing the second condition. It is even possible to make a custom sprite action for acquiring these kinds of sprites.

Custom Keen 4 collision

#Custom collision: can be 'picked up' by the player if they lack a Wetsuit
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $3E {$7A5CW}  [$00]
             {$75} $1C $81 $7C {$1C} [$0C02W]  {$75} $15 $C7 $45 $1C {$1F46W}  $B8 [$0016W]
                 $50 $9A $187409F1RL     $83 $C4 $02 $FF $06 {$7A5CW}  $5F $5E
             $5D $CB


Shooting sprite makes it face the shot

This collision causes a sprite using it to face the direction it was shot (Even if the player has moved.) It is also deadly. The lethality can be removed by simply removing the $83 $3C $02 $75 $05 $9A $0B8013E9RL sequence. (This checks for Keen's sprite type and if found runs the 'kill player' code.)

On the second line Keen's shot type is checked for. If found Keen's shot sprite's horizontal direction is checked. (This is variable $0E.) The shot sprite then changes its horizontal direction to match. (Vertically moving shots will not change its horizontal direction in this patch.) Finally the 'destroy Keen's shot' code is run in the last line.

To change this from horizontal to vertical direction the four $0Es should be changed to $10.

Custom Keen 4 collision

#Custom collision: Shooting sprite makes it face the shot
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $3C [$02] {$75} $05
             $9A $0B8013E9RL     $83 $3C [$03] {$75} $21 $83 $7C {$0E} [$01] {$75} $07
             $C7 $45 $0E [$0001W]  $EB $0B $83 $7C {$0E} [$FF] {$75} $07 $C7 $45 $0E
             [$FFFFW]  $56 $9A $0D8F0D43RL     $83 $C4 $02 $5F $5E $5D $CB


Shooting a sprite makes it face the shot and change action

This patch is nearly identical to the previous patch except that it also changes the sprite's action. This can be very useful since it can be set up so a still sprite will move in the direction of the shot only after being shot, or may stop moving when shot or do something such as attack the player when shot. It is also possible to change the sprite variable altered so that it is not the action that changes.

The patch and highlighted values are the same as for the above patch with one addition; $C7 $45 $1C $1F46W changes the sprite's action, in this case to a raindrop splash. (This should be changed when incorporating the patch into a mod.)

After this patch is an example usage that can be run in a clean copy of Keen 4. It makes the Poison Slug into a still sprite that will only move when Keen shoots it.

Custom Keen 4 collision

#Custom collision: Shooting a sprite makes it face the shot and change action
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $3C [$02] {$75} $05
             $9A $0B8013E9RL     $83 $3C [$03] {$75} $26 $83 $7C {$0E} [$01] {$75} $07
             $C7 $45 $0E [$0001W]  $EB $0B $83 $7C {$0E} [$FF] {$75} $07 $C7 $45 $0E
             [$FFFFW]  $C7 $45 $1C [$1F46W]  $56 $9A $0D8F0D43RL     $83 $C4 $02
             $5F $5E $5D $CB

Custom Keen 4 collision example

#Custom collision: Shooting a sprite makes it face the shot and change action
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $3C [$02] {$75} $05
             $9A $0B8013E9RL     $83 $3C [$03] {$75} $26 $83 $7C {$0E} [$01] {$75} $07
             $C7 $45 $0E [$0001W]  $EB $0B $83 $7C {$0E} [$FF] {$75} $07 $C7 $45 $0E
             [$FFFFW]  $C7 $45 $1C [$2030W]  $56 $9A $0D8F0D43RL     $83 $C4 $02
             $5F $5E $5D $CB

#Slug uses new collision
%patch $30E96 $0FA80C57RL
%patch $30EB4 $0FA80C57RL

#Normal slug 1 doesn't move (Sits still), slug 2 moves much more
%patch $30E8E $0000W $0000W #Speed 1
%patch $30EAC $00A0W $0000W #Actual movement speed when shot

#Normal slug 1 doesn't go to normal slug 2 by itself
%patch $30E9E $2012W


Bounce off Keen's head

This collision causes the sprite to bounce upwards (if it is using some sort of 'move through the air' behavior.) when Keen touches it. The result is that it will bounce on Keen's head if he moves up to and touches the sprite. The exact height of the bounce is given by the blue variable $40, larger numbers are higher bounces up to $7F, the highest possible bounce. Anything larger than this is treated as a negative number, making the sprite move downwards.

The [tt]$18[/tt] identifies the sprite's vertical speed; changing this to [tt]$16[/tt] will cause its horizontal speed to be affected instead.

Custom Keen 4 collision

#Custom collision: Bounce on Keen's head 
%patch $7A3B $EB $5C
%patch $7A3D 55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $09
              $8B $04 $89 $44 $44 $83 $6C {$18} $40 $5F $5E $5D $CB<


Keen 5

The collisions for Keen 5 can be tested by giving a sprite the collision value of $06B90E68RL. All custom collisions given here disable the Boss cheat, this is the first line of each patch, %patch $79F6 $EB $5C.


Kill Keen and block shots

This collision is used by multiple sprites in Keen 5 such as the Robo Red. It blocks Keen's shots but doesn't stun and is dangerous to Keen. The first line checks for Keen's shot type and the second for Keen. If a shot is detected the 'smash shot' code is run; if Keen is detected then the 'kill Keen' code is run.

Custom Keen 5 collision

#Custom collision: Kill Keen and block shots sprite collision
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $56 $8B $76 $08 $83 $3C [$03] {$75} $0C $56 $9A $0CCB10B3RL #Check for Keen's shot (Type 3)
                     $83 $C4 $02 $5E $5D $CB $83 $3C [$02] {$75} $05 $9A $0AAF1517RL #Check for Keen, kill
                     $5E $5D $CB


Destroyed when pogoed on, block shots

This collision reacts not to sprite types but to sprite actions. The first two lines react to two specific actions, those of Keen pogoing. In this it is similar to the Skypest in Keen 4. When triggered in this way the sprite's action changes to a custom action and sound $21 is played. (The same sound the Little Ampton makes when shot.

On the third line a range of actions is checked for; in this case the four actions of Keen's shots. (This is done with a different set of jump conditions that exclude actions less than one value and grater than another.) When triggered the sprite transforms the colliding sprite into Keen's smashed shot. This allows this collision to destroy multiple types of enemy. (And even all enemies except Keen is correctly set up.)

See also Patch:Galaxy Sprite Parameters for the meaning of the $1C bytes.

Custom Keen 5 collision

#Custom collision: Destroyed when pogoed on, block shots
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $81 $7C {$1C} [$1008W]
             {$74} $07 $81 $7C {$1C} [$1026W]  {$75} $13 $C7 $47 {$1C} [$012EW]  $B8 [$0021W]
                  $50 $9A $196E09EFRL     $83 $C4 $02 $EB $0D $81 $7C {$1C} [$1502W]
                 {$72} $10 $81 $7C {$1C} [$155CW]  {$77} $09 $56 $9A $0CCB10B3RL     
                 $83 $C4 $02 $5F $5E $5D $CB


Deadly, become another sprite when shot

This collision is for a sprite that is both deadly to the player and can be shot. A sprite using this will be deadly to Keen, but also be shootable, becoming another sprite when shot. This is what a lot of enemies in Keen use. Here the sprite's action changes to the vitalin got sprite.

This collision reacts to Keen by running the 'kill Keen' code and to Keen's shots by removing the shot and becoming another sprite. The first and second blue values are what sprite type to react to ($02 is Keen, $03 is his shot.) The first and third brown values (Both $75) are the jump conditions, in this case react ONLY to that sprite type and nothing else. The first brown $9A string is the 'kill Keen' code, the second is the 'remove shot' code.

This patch also allows two (sprite parameters) to be changed along with the sprite's action. In this example the clipping and horizontal speed are set to 1 and 0 respectively.

Custom Keen 5 collision

#Custom collision: Kill Keen And Become Another Sprite When Shot
%patch $7A3B $EB $5C
%patch $7A3D $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $09
             {$9A $0B8013E9RL}     $5F $5E $5D $CB $83 $3D [$03] {$75} $18 $C7 $44
             $16 [$0000W]  $C7 $44 $06 [$0001W]  $B8 [$19DCW]  $50 $57 $56 {$9A $090B16CDRL}
                         $83 $C4 $06 $5F $5E $5D $CB


Deadly, takes multiple hits to stun

This collision is for a sprite that is both deadly to the player and can be shot, requiring multiple shots to stun and flashing each time it is shot. (It responds to both Keen and Keen's shot types.) To use this collision a sprite must have a strength; set when it is spawned.

On the first line a check for Keen is made, if Keen-type is found then the 'kill Keen' code is run at the start of line two. Also on line two is the check for Keen's shot type. If it is not found the following code is skipped.

At the end of line 3 a check is made to see if the sprite's strength (Parameter 40) is zero. If so then the Sprite's X and Y motion are set to 0 and its action to 'stunned Shikadi'. Otherwise the Shikadi's 'flash time' is set to 2 and flash set to 1 (This makes the Shikadi flash when shot.) This also removes 1 from the Shikadi's strength.

Custom Keen 5 collision

#Custom collision: Deadly, takes hits to stun
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $05
             $9A $0AAF1517RL     $83 $3D [$03] {$75} $34 $FF $4C {$40 $75} $1C $C7
             $44 $16 [$0000W]  $C7 $44 $18 [$0000W]  $B8 {$155CW}  $50 $57 $56 $9A
             $090B16CDRL     $83 $C4 $06 $5F $5E $5D $CB $C7 $44 $42 $0002W
             $C7 $44 $04 $0001W  $57 $9A $0CCB10B3RL     $83 $C4 $02 $5F $5E
             $5D $CB


Stun Keen

This collision stuns Keen, that is, temporarily transforms him into an immobile state that he eventually recovers from. On the first line a check is made for God mode; if it is enabled Keen cannot be stunned. Keen's stunned action is the first blue variable. On the second line a sound is played, here $17, the death sound. On the fourth line Keen's vertical and horizontal speeds are set in that order. Here he moves up and right.

Next is Keen's stunned action code. It uses sprite image $8C, the same as one of his death animations, he recovers from stunning in $0190W ticks to $0888W, the standing action. Finally the last line of the patch allows Keen to die while stunned. Removing this makes him immortal when stunned.

Custom Keen 5 collision

#Custom collision: Stun Keen
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $83 $3E {$BC91W}  [$00] {$75} $2A $B8 [$0B94W]  $50 $FF
             $36 $3E $9E $9A $090B1242RL     $83 $C4 $04 $B8 [$0017W]  $50 #Stun sound
             $9A $196E09EFRL     $83 $C4 $02 $8B $1E $3E $9E $C7 $47 $18
             [$FFD8W]  $C7 $47 $16 [$0010W]  $5D $CB			 #Stunned Keen speeds

#Keen stunned action =$0B94W
%patch $30ED4 $008CW $008CW $0003W $0000W $0000W $0190W $0000W $0000W
              $090B1710RL   $0AAF1597RL   $090B17B5RL   $0888W

#Keen can die while stunned
%patch $C021 $90 $90


Block Keen on the map

This collision causes the sprite to not let Keen pass upwards (Or with tweaking, downwards.) on the map level. When Keen attempts to move up past the sprite a sound plays and he becomes Waving Map Keen, which stops him moving. A side effect is that his scorebox is blanked. This is an unavoidable side-effect.

On the first line the sprite checks whether the up key ($9E38W $FF) is being pressed. (The down key is $9E38W $01.) If it is the rest of the code is run. (As a side-effect of this any other sprite can trigger this if Keen is moving up. However the map level usually lacks any other sprites.)

On the second line Keen's action is chaned to Waving Map Keen which stops him moving past the sprite. Then sound $0D is played.

This also works in normal levels (Though the action Keen is changed to should be something such as bored Keen or falling Keen.) but is not advised.

The second patch is identical except on line 1 there is an additional check for Keen's V card. This means that Keen can get past the block if he has a V card. (See also Patch:Game stats.)

The third patch is identical to the second except it blocks Keen moving rightwards and also includes a 'debug' that sets the 'rightkey' to 0. This sort of debug is useful if the collision causes the effect to appear multiple times per collision.

Custom Keen 5 collision

#Custom collision: Block Keen moving up on the map
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $56 $8B $76 $08 $83 $3E {$9E38W}  [$FF] {$75} $11 $C7 $44
             $1C [$13B6W]  $B8 [$000DW]  $50 $9A $196E09EFRL     $83 $C4 $02 $5E
             $5D $CB

Custom Keen 5 collision

#Custom collision: Block Keen moving up on the map if he doesn't have V card
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $56 $8B $76 $08 $83 $3E {$6F5AW}  [$01] {$74} $17 $83 $3E {$9E38W}
                 [$FF] {$75} $11 $C7 $44 $1C [$13B6W]  $B8 [$000DW]  $50 $9A $196E09EFRL
                     $83 $C4 $02 $5E $5D $CB

Custom Keen 5 collision

#Custom collision: Block Keen moving right on the map if he doesn't have V card
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $56 $8B $76 $08 $83 $3E {$6F5AW}  [$01] {$74} $1E $83 $3E
             {$9E36W}  [$01] {$75} $17 $C7 $44 $1C [$13B6W]  $B8 [$000DW]  $50 $9A
         $196E09EFRL     $83 $C4 $02 $C7 $06 {$9E36W}  [$0000W]  $5E $5D $CB


Map block brings up Fuse window

This patch is identical to the third patch in the above section except that in addition to blocking Keen it also brings up the Fuse window (and clears it from the screen afterwards.) A side effect of this is that the player's scorebox is 'blanked'. This makes the blocker act much like the 'can't swim' tiles in Keen 4.

Custom Keen 5 collision

#Custom collision: Block Keen moving right on the map if he doesn't have V card, bring up window
%patch $79F6 $EB $5C
%patch $79F8 $55 $8B $EC $56 $8B $76 $08 $83 $3E {$6F5AW}  [$01] {$74} $29 $83 $3E
             {$9E36W}  [$01] {$75} $22 $C7 $44 $1C [$13B6W]  $B8 [$000EW]  $50 $9A
         $196E09EFRL     $83 $C4 $02 $9A $0ED50AF4RL     $C7 $06 {$6F70W}
         [$0006W]  $C7 $06 {$9E36W}  [$0000W]  $5E $5D $CB


Keen 6

The collisions for Keen 5 can be tested by giving a sprite the collision value of $069A0E31RL. All custom collisions given here disable the Boss cheat, this is the first line of each patch, %patch $77CF $EB $5C.


Any sprite triggers an action change and sound

This collision is for a sprite that is to be triggered by any other sort of sprite touching it. (Such as a high explosive.) When any other sprite of any kind at all touches it it will change its action and play sound $37.

Here the action changed to is the first Viva got action that works in all levels. Likely a modder will want to change this.

Custom Keen 6 collision

#Custom collision: Any sprite triggers an action change and sound
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $8B $76 $06 $C7 $44 $1C [$1A00W] $B8 [$0037W]  $50
             $9A $183B09F1RL     $83 $C4 $02 $5E $5D $CB


Kill Keen and block shots

This collision is for a sprite that is lethal to Keen blocks his shots. It is thus immortal. It is also rather simple; on the first line Keen is checked for, if found the 'kill the player' code is run. On the second line Keen's shot is checked for and, if found, the 'destroy shot' code is run.

Custom Keen 6 collision

#Custom collision: Kill Keen and block shots
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $83 $3C [$02] {$75} $07
             $9A $0AA213CARL     $EB $0E $83 $3C [$03] {$75} $09 $56 $9A $0CA60EC2RL
                     $83 $C4 $02 $5F $5E $5D $CB


Kill Keen and stun

This collision is for a sprite that is lethal to Keen but can be turned into another sprite when shot. It does not have any 'hit points' (One hit kills.)It is rather simple; on the first line Keen is checked for, if found the 'kill the player' code is run. On the second line Keen's shot is checked for and, if found, the sprite's action changes and the 'destroy shot' code is run.

Here the action changed to is the first Viva got action that works in all levels. Likely a modder will want to change this.

Custom Keen 6 collision

#Custom collision: Kill Keen and stun
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $8B $76 $08 $83 $3C [$02] {$75} $08 $9A $0AA213CARL
                 $5E $5D $CB $83 $3C [$03] {$75} $10 $B8 [$1A00W]  $50 $56 $FF $76
             $06 $9A $08F41722RL     $83 $C4 $06 $5E $5D $CB


Kill Keen take multiple shots to stun

This collision is identical to the above collision except it allows a sprite to take multiple hits before they stun. (The sprite's strength must be set in its spawning code however.) The check at the end of line 2 checks the sprite's strength and the code on lines 4-5 is the 'hit flash' code.

Custom Keen 6 collision

#Custom collision: Kill Keen, multiple shots to stun
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $05
              $9A $0AA213CARL     $83 $3D [$03] {$75} $2A $FF $4C [$40] {$75} $12 $B8
              [$1A00W]  $50 $57 $56 $9A $08F41722RL     $83 $C4 $06 $5F $5E $5D
              $CB $C7 $44 $3E [$0002W]  $C7 $44 $04 [$0001W]  $57 $9A $0CA60EC2RL
                  $83 $C4 $02 $5F $5E $5D $CB


Give Keen points on contact and vanish

There are several versions of this patch which make the sprite a de-facto item. The first simply gives 10'000 points and changes its action to that of the Viva got. This makes it appear to vanish when touched.

The second is identical but plays a sound as well. Changing the properties of the changed action can make it very much like the item got sprite that appears when normal items are touched.

Custom Keen 6 collision

#Custom collision: Give Keen 10'000 points and vanish
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $02 $75 $11 #Check for Keen (Type 2)
             $B8 [$2710W]  $50 $9A $069A1F06RL $83 $C4 $02 $C7 $44 $1C {$1A00W}  #Change action to vivagot, give 10000
             $5F $5E $5D $CB

Custom Keen 6 collision

#Custom collision: Give Keen 10'000 points and vanish, play sound
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D $02 $75 $1D #Check for Keen (Type 2)
             $B8 [$2710W]  $50 $9A $069A1F06RL $83 $C4 $02 $C7 $44 $1C {$1A00W}  #Change action to vivagot, give 10000
             $B8 [$0008W]  $50 $9A $183B09F1RL $83 $C4 $02 $5F $5E $5D $CB     #Play sound


Give the Sandwich, Rope or Passcard show window and vanish

These three, nearly identical, patches do similar things. When Keen touches them they display the relevant map item window give the relevant map item and then vanish. A simple tweak can make it so these patches work when the item is shot instead.

On the first line Keen's type is checked for and if found the sprite changes to a Viva got action (which makes it appear to vanish.) and calls the appropriate item window code. The item window code itself gives the item, plays the appropriate sound and so on.

There are three slightly different patches, one for each item.

Custom Keen 6 collision

#Custom collision: Give the Sandwich with window and vanish
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $0F
             $C7 $44 $1C [$1A00W]  $9A $0E4209FCRL     $9A $16080E88RL $5F $5E
             $5D $CB

Custom Keen 6 collision

#Custom collision: Give the Rope and grappling hook with window and vanish
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $0F
             $C7 $44 $1C [$1A00W]  $9A $0E420A8ARL     $9A $16080E88RL $5F $5E
             $5D $CB

Custom Keen 6 collision

#Custom collision: Give the Passcard with window and vanish
%patch $77CF $EB $5C
%patch $77D1 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $0F
             $C7 $44 $1C [$1A00W]  $9A $0E420B18RL     $9A $16080E88RL $5F $5E
             $5D $CB