Patch:Sprite behavior

From KeenWiki
Jump to navigation Jump to search

This page is a tutorial page on patching sprite behaviors. It contains information on what sprite behavior is, how to patch it in all Keen games and all known values from Keen games.. A sprite's behaviors are segments of code that control how a sprite moves about and acts. They are controlled in-game by pointers to the code, so it is possible to create entirely new behaviors and make a sprite use them.


How behaviors work

In Keen 1-3 sprite behavior controls everything about the sprite including its interaction with tiles. Sprite collision is a special type of behavior activated when the sprite contacts another sprite. Sprite behaviors also have direct pointers to other behaviors in them which can make them hard to disentangle. As an example, the Yorp in Keen 1 has three behaviors, when shot, walking\jumping and looking for Keen; if a sprite is patched to use the walking Yorp behavior, it will look for Keen and in general stay behaving like a Yorp, since Yorp behaviors reference each other.

In Keen 1-3 behavior pointers are two byte patches giving the location of the behavior code start. (In the dumped code, NOT the unpatched executable.) Patches can also be divided into three sections, the spawn behavior, set when a sprite is first spawned in a level which determines all other behaviors, in-level behaviors that follow on from this and are how the sprite acts during the game and sprite collision which is only called when two sprites touch. As an example this is the default setup for the Yorps:

Behaviors:
$194FW Walk\jump
$19D3W Look for Keen
$1A68W Yorp collision

When spawned

%patch $18B4 {$194FW}

In level

%patch $1A22 {$194FW} #After looking for Keen
%patch $1980 {$19D3W} #Do this randomly when walking
%patch $1A58 {$19D3W} #After being stunned
%patch $4DA4 {$19D3W} #After being stunned offscreen

%patch $18D9 {$1A68W} #Yorp collision


As an example of the synonymy of behaviors and collisions, this patch makes the Yorp become a Garg when shot:

Keen 1

%patch $18D9 {$1B51W}


In Keen 4-6 and Dreams both tile and sprite collisions are separated from general behavior. Behaviors don't usually reference each other, but are mostly set in sprite actions which are themselves called by behaviors. Behavior pointers are four bytes long pointing to an offset in a segment in the executable which is more complex. It's also possible for a sprite to have NO behavior at all. The following is a patch from the Berkeloid's walking actions:

Keen 4

#Berkeloid walking:
%patch $31978 {$1080040BRL} #Berkeloid
%patch $31996 {$1080040BRL} #Berkeloid
%patch $319B4 {$1080040BRL} #Berkeloid
%patch $319D2 {$1080040BRL} #Berkeloid


Values in games

For Keen Vorticons the pointer is directly to the location in the patched executable (So the Yorp value of $1A68W points to code at $1A68 in the dumped executable.) Galaxy values are more complex and it is advised Patch:Executable segments be consulted.


Keen 1

#Keen 1
$194FW #Yorp Walk\jump
$19D3W #Yorp Look for Keen
$1B51W #Garg look for Keen, charge
$1AA8W #Garg walk
$1C0EW #Vorticon walk\jump
$1CC8W #Vorticon slide back and forth
$1D15W #Walk towards Keen?
$1DC7W #Butler Bot walk back and forth, turn at platform edges
$1E5EW #Butler Bot turn
$1F75W #Tank Bot sit and animate
$1F8FW #Tank Bot turn
$1EA9W #Tank Bot walk\shoot
$1FC1W #Tank Bot shoot
$2151W #Move then vanish (Icecube fragment)
$2192W #Icecube Move, smash on tiles
$3360W #Do nothing (Chain, dead sprites)
$3867W #Keen standing
$3B8BW #Keen jump
$3C99W #Keen fall
$3E12W #Keen shoot
$3EC8W #Keen start pogo
$4054W #Keen pogoing
$41F8W #Dead Keen
$47E8W #Sit then vanish (Zap\zot)
$4808W #Sit then vanish when touching stuff (Zap\zot)
$488EW #Dead sprite collision
$489DW #Jump then fall while animating (Shot sprites)


Keen 2

#Keen 2
$3E19W #Vorticon chase Keen\jump
$3EE6W #Vorticon slide back and forth
$3F33W #Vorticon walk towards Keen
$3FCCW #Vortikid run\jump
$404CW #Vortikid slide
$40CEW #Vorticon elite walk\jump\chase Keen
$41C2W #Elite shoot
$423CW #Elite just walk
$42C1W #Scrub walk on floors
$4345W #Scrub walk down walls
$43C9W #Scrub walk on ceilings
$444DW #Scrub walk up walls
$44D1W #Scrub fall to floor
$4539W #Robot walk
$45B0W #Robot shoot
$467CW #Platform move l\r
$46BFW #Platform sit (Hit walls)
$46DFW #Tantalus ray sit
$4A29W #Keen stand?
$66A9W #Keen stand?
$69CDW #Keen jump
$6ADBW #Keen fall
$7547W #Sit and vanish (zap\zot)
$7567W #Shots Move until hits tiles
$75FCW #Jump then fall down animating (Shot sprites)


Keen 3

#Keen 3
$414AW #Vorticon Walk\jump\chase Keen
$4227W #Vorticon walk only
$4275W #Vorticon walk towards Keen
$4311W #Vortikid run\jump
$4391W #Vortikid walk only
$440CW #Vortimom walk
$44B9W #Vortimom shoot
$466EW #Vortimom's shot
$4746W #Meep walk
$47D3W #Meep shoot
$48D2W #Meep's shot (Goes through walls!)
$48F7W #Vortininja wait for Keen
$499DW #Vortininja jump
$4A0CW #Foob walk
$4B2CW #Foob run
$4C0BW #Ball
$4B7EW #Sit
$4BBDW #Jack
$4C47W #Platform move
$4CCAW #Platform turn
$4CF2W #Orange bullet
$4E02W #Purple spark
$4EA6W #Heart
$5553W #Stunned Keen
$5FA3W #Unknown
$6F07W #Standing Keen
$7230W #Keen jump
$7344W #Keen fall
$74BAW #Keen shoot
$756EW #Keen pogoing
$76F9W #Keen start pogo
$789EW #Keen dies
$7E05W #Sit and vanish (Zap\zot)
$7E29W #Keen's shot
$7EB1W #Dead sprite collision
$7EC0W #Sit (Dead sprites)


Keen 4

#Keen4 Keen
$0B800234RL #Entering doors 2
$0B80024CRL #Entering doors 3
$0B800395RL #Normal Keen [Stand and wait for arrows]
$0B80045CRL #Reading Keen [When arrows pressed become standing Keen]
$0B80049ARL #Keen looking up [Move screen up when up arrow pressed, else, standing Keen]
$0B8004E2RL #Keen looking down [Move screen down when down arrow pressed, else, standing Keen]
$0B80062CRL #Keen walk [Walk with arrows or be standing Keen]
$0B8007D8RL #Entering doors start [Move across slightly, start entering door]
$0B800842RL #Entering doors 4 [Go invisible, shift to target destination and become standing Keen]
$0B8008B9RL #Flicking switches [Animate switch tile behind sprite]
$0B800A34RL #Placing gem [Animate gem holder tile behind sprite]
$0B800B5BRL #Jumping and falling
$0B800CC9RL #Pogoing start [Bounce up in air]
$0B800CF5RL #Pogoing [Fall and bounce of ground, move with arrows]
$0B800ED3RL #Keen on pole [Sit in air and wait for arrows to climb pole]
$0B800F89RL #Keen go up poles [Climb with arrow up or sit on pole]
$0B80101CRL #Going down poles [Climb down with arrow or sit on pole]
$0B8010D1RL #Keen jump down from one-way-up platforms
$0B8010E0RL #Keen grip ledge [Hang in space, climb up or fall with arrows]
$0B801195RL #Shooting [Spawn Keen's shot in arrow direction]
$0B80134ARL #Climbing up from grip 1
$0B801369RL #Climbing up from grip 2
$0B801394RL #Climbing up from grip 3
$0B80139FRL #Climbing up from grip 4
$0B8013B9RL #Dead Keen [Fall offscreen]
$0D8F06AFRL #Map Keen waving
$0D8F06F0RL #Map Keen standing/walking
$0D8F07ABRL #Map Keen on Foot
$0D8F0826RL #Map Keen swimming
$0D8F0BC4RL #Flag flipping start [Appear with a pop sound]
$0D8F0BEFRL #Flag flipping [Head toward level marker]
$0D8F0C51RL #Flag land [Land in level marker with a thud sound]
$0D8F0D6ARL #Keen's shot [Move in a line]
$0D8F0F85RL #Doors open [Animate tiles behind where door sprite placed]
$0E8F0E17RL #Keen swimming 1
$0E8F0FAERL #Keen swimming 2
$11A20974RL #Keen's bubbles
#Keen 4 Sprites in general
$00000000L  #Do nothing
$09DC16C9RL #Fly through the air and wait to hit ground, then animate [E.g stunned sprites]
$09DC16E5RL #Same as above, almost. Used by Berkeloid flames
$09DC1701RL #Sit; used by Clouds
$09DC171FRL #Sit; used by Berks
$0FA8002ERL #Miragia animation 1
$0FA8008BRL #Miragia animation 2
$0FA800B3RL #Miragia animation 3
$0FA800DBRL #Miragia animation 4
$0FA80103RL #Miragia animation 5
$0FA8012BRL #Miragia animation 6
$0FA80153RL #Miragia animation 7
$0FA8017BRL #Miragia animation 8
$0FA8024ERL #Item animate (Regularly)
$0FA802D4RL #Randomly turn into a thinking Council member
$0FA80369RL #Randomly turn into a Sliming Slug
$0FA803A6RL #Produce Slug Slime and turn into a Poison Slug
$0FA80493RL #Mad Mushroom
$0FA805ABRL #Bird recover
$0FA80779RL #Walking Bird look for Keen 
$0FA807D7RL #Flying Bird
$0FA80AF9RL #Arachnut
$0FA80BE7RL #Skypest flying
$0FA80CF1RL #Skypest flying up off ground
$10800071RL #Wormouth look right
$10800091RL #Head toward Keen (Won't turn into Wormouth, I promise!)
$108000B4RL #Wormouth look left
$108000D4RL #Wormouth check if close to Keen before looking or biting
$1080020CRL #Cloud waking up
$10800278RL #Cloud look for Keen and maybe strike
$1080032ARL #Lightening made
$1080040BRL #Berkeloid
$108004A4RL #Berkeloid flame
$1080051CRL #Berkeloid after tossing flames
$10800770RL #Head toward Keen
$10800B42RL #Lick head toward Keen, maybe flame him
$10800D44RL #Move like an Airboard (Reverse when hitting Block sprites)]]
$1080114FRL #Become a falling platform if Keen jumps on it
$10801182RL #Fall until you hit a block sprite
$108011FBRL #Rise slowly until you find a block sprite
$11A20079RL #Look if there are items above you, if so, move up to get them
$11A2022ARL #Look for items, teleport to them as a Smirky
$11A20494RL #Look for Keen, if he's far away, become a sneaking Mimrock
$11A204F8RL #Mimrock looks for Keen, either jump or sit still
$11A20700RL #Keen dead (WoW only)
$11A20711RL #Head toward Keen both h and v
$11A2077ARL #Look for Keen and Schoolfish, if close become a snacking Dopefish
$11A2086ERL #Dopefish snacks on a sprite
$11A20912RL #Produce a big bubble
$11A20974RL #Bubbles
$11A20AF6RL #Head toward Keen, both h and v
$11A20BB1RL #Float u/d like a sprite
$11A20C18RL #Look for Keen and become a shooting sprite if he's near
$11A20C3BRL #Produce a Sprite Shot
$11A20E01RL #Float up and down like Lindsey
$11A20EE6RL #Produce Dart shooter Dart


Keen 5

#Keen 5 Keen
$00000000L  #Nothing
$090B1710RL #Fall
$0CCB0654RL #Map Keen wave
$0CCB0695RL #Map Keen move
$0CCB0A69RL #Map Keen
$0CCB10DARL #Keen's shot
$0CCB12F5RL #Open door
$0AAF02FARL #Keen go into doors 1
$0AAF0312RL #Keen go into doors 2
$0AAF032BRL #Platform Keen
$0AAF046DRL #Normal Keen (Wait for keypress)
$0AAF0531RL #Reading Keen (Sit and stop reading at keypress)
$0AAF056FRL #Keen look up
$0AAF05B7RL #Keen look down
$0AAF0701RL #Keen walk
$0AAF08ADRL #Keen open door
$0AAF0917RL #Keen go into doors 3
$0AAF09BARL #Keen flip switch (Activate switch tile)
$0AAF0B62RL #Keen place gem
$0AAF1001RL #Keen on pole
$0AAF10B7RL #Keen move up pole
$0AAF0C89RL #Keen jump/fall
$0AAF0E23RL #Keen pogo
$0AAF0DF7RL #Keen start pogo
$0AAF114ARL #Keen move down pole
$0AAF11FFRL #Keen stops looking down
$0AAF120ERL #Keen move up from ledgegripping 1
$0AAF12C3RL #Keen shoot (Spawnshot)
$0AAF1478RL #Keen move up from ledgegripping 2
$0AAF1497RL #Keen move up from ledgegripping 3
$0AAF14C2RL #Keen move up from ledgegripping 4
$0AAF14CDRL #Keen move up from ledgegripping 5
$0AAF14E7RL #Keen dies (Didn't make it window when falls offscreen)
#Keen 5 Sprites in general
$0F92052ARL #Items
$0F920545RL #Cards
$0F9206A2RL #Q.E.D/Fuse bust; show window, end level\game
$0F920776RL #Move u/d - l/r Red Platform
$0F92099CRL #Move u/d - l/r Purple Platform
$0F920C1BRL #Sit Red Platform
$0F920CB9RL #Fall\rise Red Platform
$0F921524RL #Sneaky platform
$0F921005RL #Info path Purple Platform
$0F92127ERL #Volte face
$0F921524RL #Info path Red Platform
$0F9215FDRL #Spawn pink shot
$1102006FRL #Sparky walk (Randomly look for Keen)
$1102008ERL #Sparky start charging
$110200A2RL #Sparky look left
$110200EFRL #Sparky look right
$1102013CRL #Sparky charge 1
$1102014CRL #Sparky charge 2
$110202ABRL #Ampton walk
$11020405RL #Ampton pole slide
$11020606RL #Ampton change tiles
$11020986RL #Shelly prepare to jump
$110209FARL #Shelly jump
$11020A0CRL #Shelley smash
$11C4036ARL #Mine sit
$11C40507RL #Mine move
$11C40626RL #Mine change direction
$11C40783RL #Mine explode
$11C409BCRL #Robo Red move
$11C40A61RL #Robo Red shoot
$11C40BAARL #Spriogrip spin (Randomly stop and move in that direction)
$11C40E86RL #Shikadi Master stand (Randomly go to walk or shoot)
$11C40EDARL #Shikadi Master shoot
$11C40F86RL #Shikadi Master teleport
$090B172CRL #Shikadi Master's shot
$11C412ECRL #Shikadi walk
$11C41455RL #Shikadi zap poles
$11C414E3RL #Shikadi polezap
$11C416E0RL #Shocksund sit
$11C416F4RL #Shocksund bark
$11C41664RL #Shocksund walk
$11C41A21RL #Sphereful
$11C41CE1RL #Korath walk


Keen 6

#Keen 6 Keen
$0AA2139ARL #Lose level if offscreen
#Keen 6 Sprites in general
$08F41765RL #Move through the air
$08F4179DRL #Enemy projectile
$0EFC0E08RL #Satellite on map
$0EFC11B0RL #Horizontal-Vertical Platform
$0EFC15BFRL #Goplat
$0EFC17F7RL #Sneaky Platform
$0EFC18D5RL #Bloog
$0EFC199ERL #Blooguard walk
$0EFC1A09RL #Blooguard club ground
$10CC0079RL #Nospike walk
$10CC0106RL #Nospike charge
$10CC02D8RL #Nospike make '?'
$10CC04C2RL #Gik chase Keen, jump
$10CC0541RL #Gik sliding
$10CC088ERL #Orbatrix float
$10CC09DARL #Orbatrix bounce
$10CC0A13RL #Orbatrix uncurl
$10CC0A71RL #Bip
$10CC0BBARL #Bipship fly
$10CC0D52RL #Bipship crashing
$10CC0E8FRL #Flect turn
$10CC0EDBRL #Flect walk, seek Keen
$11CF0083RL #Fleex walk
$11CF00BCRL #Fleex look for Keen
$11CF01D8RL #Landed Bobba
$11CF01C7RL #Sparkle turn into fireball
$11CF046FRL #Babobba jump, nap or shoot
$11CF066FRL #Landed cinder
$11CF068ERL #Dying cinder
$11CF080ARL #Ceilick wait\attack
$11CF084CRL #Ceilick Laugh
$11CF085DRL #Ceilick stunned

REMAINING BEHAVIORS TODO


Keen Dreams

#Keen Dreams Sprites in general
$05E80630RL #Vanish after a period of time
$07C501A4RL #Move through the air
$07C50402RL #Wilted Flower
$07C50461RL #Wilted Flower recover
$07C5052BRL #Items
$07C50596RL #Broccolash walk
$07C50587RL #Broccolash attack
$07C5064BRL #Tomatooth bounce
$08680055RL #Trooper walk
$086802BERL #Frenchy walk
$08680227RL #Frenchy charge
$08680236RL #Frenchy toss chip
$086803CBRL #Melon spit pip
$08680805RL #Squasher walk
$0868090ERL #Apel walk
$086809D9RL #Apel climb up poles
$08680A29RL #Apel climb down poles
$08680B22RL #Pea walk
$08680BADRL #Peapod make Pea
$08680C2BRL #Peapod walk, spit
$08680D74RL #Boobus Tuber die (Win game)
$08680D92RL #Boobus Tuber chase Keen
$08680CD4RL #Boobus Tuber dying

REMAINING BEHAVIORS TODO


Custom behaviors

These are behaviors that have been written from scratch rather than being copies of default behaviors. They cover all episodes.


Keen 2

In Keen 2 custom behaviors can be called by setting the sprite's behavior value to the location of the new behavior.


Randomly shoot blue and orange shots

This behavior causes the enemy in question to shoot both blue (Keen's) and orange (Enemy) shots. This will allow it to kill all enemies given enough time. While shooting it will not change animation, move or fall. Here it will only shoot right, which makes it useful as an 'enemy shooter' enemy.

This patch also alters the way both Keen and the orange shot collide with things, adding an exception labelled in this patch in blue. Sprite type $07 is not touched by either shot, allowing the enemy to shoot both types of shot if it has that sprite type. (And ONLY that sprite type.) As such this patch is incompatible with several that pertain to Keen's and the orange shot.

Also labeled in blue is the shot's speed, spawn height and the two sounds made when orange and blue shots are produced.

Rapidly randomly do something

#New behavior, randomly shoot red and blue shots
%patch $0B34 $55 $8B $EC $56 $E8 $ACABW  $8B $16 $5AF0W  $D1 $E2 $3B $C2 $73
             $38 $E8 $AC9EW  $8B $16 $2FC2W  $D1 $E2 $3B $C2 $73 $2E $B8 [$0026W]
                 $50 $E8 $AAB2W  $44 $44 $BE [$015EW]  $56 $A1 $96CAW  $8B
             $16 $96C8W  $81 $C2 [$FF00W]  $15 $FFFFW  $50 $52 $FF $36 $96C6W
             $FF $36 $96C4W  $E8 $6AC3W  $83 $C4 $0A $5E $5D $C3 $83 $3E $6028W
             $00 $7C $CB $B8 [$000CW]  $50 $E8 $AA7DW  $44 $44 $FF $36 $96CAW
             $FF $36 $96C8W  $FF $36 $96C6W  $FF $36 $96C4W  $E8 $6876W  $83
             $C4 $08 $5E $5D $C3

#Change shot collisions to respect type 7
%patch $7677 $75C5W
%patch $75BD $83 $3D [$07] $74 $27 $E9 $01B4W
%patch $75C5 $55 $8B $EC $56 $57 $8B $76 $04 $8B $7E $06 $83 $3D $06 $74 $14
             $83 $3D $0D $74 $0F $83 $3D $04 $74 $0A $83 $3D [$07] $74 $05 $E9
             $0192W  $90 $90


Keen 3

In Keen 3 custom behaviors can be called by setting the sprite's behavior value to the location of the new behavior.


Rapidly randomly do something

This patch causes a sprite to do something randomly and rapidly. The default patch here makes it animate between the two zap and zot sprites. What is altered is a Vorticon Sprite Parameter and a simple tweak can make the sprite randomly change movement, type, speed and more. As written here this patch will overwrite important code, so may need to be moved.

The first blue value is the probability of either option, here 50:50, or about equal. This can be altered to favor a certain outcome. The next two blue values are the values randomly set, in this case the animations used.

It is also possible to expand the code, to make this a 'decision behavior' where a sprite randomly picks a whole slew of things to do before moving on to a new behavior.

Rapidly randomly do something

#Sit and randomly animate
%patch $5056 $55 $8B $EC $56 $E8 $7AE7W  $3D [$0080W]  $7E $08 $C7 $06 $38 $99 [$0069W]
                 $EB $06 $C7 $06 $38 $99 [$006AW]  $5E $5D $C3


Keen 4

All behavior patches in this section use the EGAGRAPH check skip which is always the first line of the patch. This is optional however and the behavior can be located elsewhere without this addition. (This will be needed in fact if more than one custom behavior from this section is desired.) All of these behaviors 'as-is' can be called in a sprite action as $037D0526RL.


Kill Keen

This behavior will cause Keen to immediately die (unless he has God mode enabled as soon as it is run. This can be useful if the modder wants a sprite to kill the player in a certain area (The behavior will not be run unless Keen is close enough. This could create a 'dead zone' in the level a player couldn't normally enter.) or if a sprite was pushed into using this behavior. (An example would be a sprite that uses this behavior at the end of a 'countdown'; if the player did not shoot it in time the player would die.)

Kill Keen

#Custom behavior: Kill Keen = $037D0526RL
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 
             $9A $0B8013E9RL     $5F $5E $5D $CB


Force the player to do something

This patch is similar to the one above except that instead of forcing the player to die it forces the player to do something else. (In this patch to read a book.) The action the player uses is the second blue value. There is also a clipping variable in case the action involves moving through solid tiles. (This can be changed to some other sprite parameter if desired.)

It is advised that this behavior be used only intermittently. If it is used constantly it will 'freeze' the player in the target action preventing them from moving, jumping or escaping the area.

Force the player to do something

#Custom behavior: Force the player to do something = $037D0526RL
%patch $3CE5 $90 $90
%patch $3CF6  $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 
              $9A $037D053ARL     $5F $5E $5D $CB
%patch $3D0A  $55 $8B $EC $8B $1E $A7D6W  $81 $7F $1C [$0CD4W]  {$74} $19 $C7 $47
              $06 [$0001W]  $B8 [$0AD6W]  $50 $FF $36 $D6 $A7 $9A $09DC120ARL       #Set clip = 1, change Keen's action
              $83 $C4 $04 $8B $1E $A7D6W  $5D $CB


Search for and go to a target sprite

This behavior makes a sprite look for a sprite of a certain type (In this case type 2, or Keen) and move to that sprite's location. If multiple sprites of this type exist then the searching sprite will visit each of them in order. (Starting from the top left of the level and moving right and down.) If no target sprites exist the searching sprite will cease to exist. (To stop this delete $57 $9A $06BD1E8BRL $83 $C4 $02 in the last line of the patch.)

This behavior is used by the Treasure Eater. The blue highlighted action in line 3 is its reappearing action but this is not necessary. The other blue value $0080W is how high above the target sprite the searching sprite spawns.

Search for and go to a target sprite

#Custom behavior: Search for and go to a target sprite = $037D0526RL
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $56 $57 $8B $7E $06 $C7 $45 $3E $0000W  $8B $1E $D6
             $A7 $8B $77 $48 $EB $28 $83 $3C [$02] {$75} $20 $8B $44 $0A $2D [$0080W]
                 $89 $45 $0A $8B $44 $0C $89 $45 $0C $B8 [$3296W]  $50 $57 $9A
             $09DC118CRL    $83 $C4 $04 $5F $5E $5D $CB
                                                         $8B $74 $48 $0B $F6
             $75 $D4 $57 $9A $06BD1E8BRL    $83 $C4 $02 $5F $5E $5D $CB


React to [B] sprites

This patch is similar to the behavior of the Platform in that it reacts in some way to the [B] sprites in the game. (These are invisible infoplane markers and not proper sprites, they take up no memory or a place in the ObjArray.)

In the example given here the reaction involves changing the sprite action (the last blue value.) but other sprite parameters can also be altered. The first two blue values are the sprite's speed horizontally and vertically, these can be set to 0 and depend on what direction (If any) the sprite is facing.

React to [B] sprites

#Custom behavior: React to [B] sprites
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $83 $EC $04 $56 $57 $8B $7E $06 $8B $45 $0E $BA [$000CW]
                 $F7 $EA $F7 $2E $4C $A5 $A3 $23 $C9 $8B $45 $10 $BA [$000CW]
             $F7 $EA $F7 $2E $4C $A5 $A3 $21 $C9 $8B $45 $26 $03 $06 $23 $C9
             $89 $46 $FE $B1 $08 $D3 $E8 $89 $46 $FC $8B $45 $30 $3B $46 $FC
             $74 $34 $8B $5D $2E $D1 $E3 $8B $9F $25 $C9 $D1 $EB $D1 $E3 $8E
             $06 $EB $A7 $8B $46 $FC $D1 $E0 $03 $D8 $26 $83 $3F $1F $75 $16
             $C7 $45 {$1C} [$1F46W]  $8B $46 $FE $25 $FF $00 $8B $16 $23 $C9 $2B
             $D0 $89 $16 $23 $C9 $5F $5E $8B $E5 $5D $CB


Change sprite's type

This behavior changes a sprite's type. A sprite using this behavior for even a single tic will changes its type to the value in blue. This can be used for sneaky tricks such as a sprite being something Keen can stand on only for a short time

Change sprite's type

#Custom behavior: Change sprite's type
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $8B $44 $0A $C7 $04 [$0001W]  $5E $5D $CB


Play a sound

This behavior does nothing more than play a specific sound. This behavior must be called only once (Using the appropriate action type.) or the sound will play continuously. If this is not possible the random sound playing action below may be more appropriate. The sound played is marked in blue.

Play a sound

#Custom behavior: Play a sound
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $8B $44 $0A $B8 [$000DW]  $50 $9A
         $187409F1RL     $83 $C4 $02 $5E $5D $CB


Randomly play a sound

This behavior does nothing more than play a specific sound at random intervals. The sound played is marked in blue while the probability is $0010W, marked in yellow.

Randomly play a sound

#Custom behavior: Randomly play a sound
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $9A $1D02002ARL     $3D {$0010W  $7D}
             {$0F} $8B $44 $0A $B8 [$002EW]  $50 $9A $187409F1RL     $83 $C4 $02
             $5E $5D $CB


Move in a straight line

This behavior makes a sprite move in a straight line until it either hits something solid or leaves the level. The two blue values are the horizontal and vertical speeds respectively. Adjusting these can make the sprite move vertically, horizontally or diagonally. This may interfere with moving Platforms; if so then the two brown values should be changed to $0000W.

Move in a straight line

#Custom behavior: Move in a straight line = $037D0526RL
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $83 $EC $04 $56 $57 $8B $7E $06 $8B $45 $0E $BA [$000CW]
                 $F7 $EA $F7 $2E $4C $A5 $A3 {$C923W}  $8B $45 $10 $BA [$000CW]
             $F7 $EA $F7 $2E $4C $A5 $A3 {$C921W}  $5F $5E $8B $E5 $5D $CB


Animate a tile

This behavior will animate a single tile behind the sprite. This will only occur if the tile itself has an animation but no animation timer. (Such as a keygem holder or switch tile.) It will also play sound $15 when doing this. (To remove the sound simply delete $B8 $0015W $50 $9A $187409F1RL $83 $C4 $02.)

Kill Keen

#Custom behavior: animate tile = $037D0526RL
%patch $3CE5 $90 $90
%patch $3CF6 $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
             $34 $50 $16 $8D $46 $FA $50 $9A $16540F28RL     $83 $C4 $0E $B8
             [$0015W]  $50 $9A $187409F1RL     $83 $C4 $02 
                                             $8B $5E $F4 $D1 $E3 $8B $87 $25
             $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
             $1F $00 $26 $89 $07 $5F $5E $8B $E5 $5D $CB


Count up then do something

This behavior makes the sprite using it add 1 to it's $3E variable. It then checks this and if over $50 it ends the level (And sends Keen to level $0F). This in effect gives the sprite its own personalized counter independent of anything else in the game.

Count up then do something

#Custom behavior: Count up then do something = $037D0526RL
%patch $3CE5 $90 $90
%patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $FF $44 {$3E} $8B $44 {$3E} $3D [$0050W]
             {$75} $0C $C7 $06 {$7A68W}  [$000FW]  $C7 $06 {$7A70W}  [$0004W]  $5E $5D $CB


Keen 5

All behavior patches in this section use the EGAGRAPH check skip which is always the first line of the patch. This is optional however and the behavior can be located elsewhere without this addition. (This will be needed in fact if more than one custom behavior from this section is desired.) All of these behaviors 'as-is' can be called in a sprite action as $037D0520RL.


Randomly change action

This behavior causes the sprite that uses it to randomly change its action. (The example action here is that of the Vitalin got V.) The random check is in line 1 and the action change in line 2.

Randomly change action

#Custom behavior: Randomly change action
%patch $3CDF $90 $90
%patch $3CF0 $55 $8B $EC $56 $8B $76 $06 $9A $1DFB0036RL     $3D [$0040W]  {$7D}
             $05 $C7 $44 $1C [$19DCW]  $5E $5D $CB


Randomly pick a direction

This behavior causes a sprite to randomly pick a left or right horizontal direction. (Change $0E to $10 to make this a vertical direction pick.) If called continuously the sprite will 'jitter' back and forth randomly, so this is best called once by a 'pick' action.

This behavior is easily modified into one that randomly picks any other sprite variable.

Randomly pick a direction

#Custom behavior: Randomly pick a direction
%patch $3CDF $90 $90
%patch $3CF0 $55 $8B $EC $56 $8B $76 $06 $9A $1DFB0036RL     $3D [$0080W]  $7D
             $07 $C7 $44 $0E [$0001W]  $EB $05 $C7 $44 $0E [$FFFFW]  $5E $5D $CB


React to [B] sprites

This patch is similar to the behavior of the Platform in that it reacts in some way to the [B] sprites in the game. (These are invisible infoplane markers and not proper sprites, they take up no memory or a place in the ObjArray.)

In the example given here the reaction involves changing the sprite action (the last blue value.) but other sprite parameters can also be altered. The first two blue values are the sprite's speed horizontally and vertically, these can be set to 0 and depend on what direction (If any) the sprite is facing.

React to [B] sprites

#Custom behavior: React to [B] sprites
%patch $3CDF $90 $90
%patch $3CF0 $55 $8B $EC $83 $EC $04 $56 $57 $8B $7E $06 $8B $45 $0E $BA [$000CW]
                 $F7 $EA $F7 $2E $B4 $9B $A3 $85 $BF $8B $45 $10 $BA [$000CW]
             $F7 $EA $F7 $2E $B4 $9B $A3 $83 $BF $8B $45 $26 $03 $06 $85 $BF
             $89 $46 $FE $B1 $08 $D3 $E8 $89 $46 $FC $8B $45 $30 $3B $46 $FC
             $74 $34 $8B $5D $2E $D1 $E3 $8B $9F $87 $BF $D1 $EB $D1 $E3 $8E
             $06 $53 $9E $8B $46 $FC $D1 $E0 $03 $D8 $26 $83 $3F $1F $75 $16
             $C7 $45 {$1C} [$19DCW]  $8B $46 $FE $25 $FF $00 $8B $16 $85 $BF $2B
             $D0 $89 $16 $85 $BF $5F $5E $8B $E5 $5D $CB


Produce another sprite (Shoot)

This behavior will cause one sprite to produce another. This behavior must be called only once by a sprite action or it will produce a stream of sprites and crash the game. In essence this is a shooting behavior, producing a new sprite at some location relative to the old sprite. On the first line the Sprite's direction is checked. If it is shooting right then the Sprite's shot will have to be moved right a bit relative to the sprite. This amount (7 pixels) is on line 2, as is the action of the sprite produced. (In this example a Vitalin got sprite, though this should be changed.)

On line 3 is the vertical position of the shot (4 pixels down from thee Sprite's top.) Finally on the fifth line is the sound the sprite makes when producing a new sprite.

Produce another sprite

#Custom behavior: Produce another sprite
%patch $3CDF $90 $90
%patch $3CF0 $55 $8B $EC $56 $57 $8B $76 $06 $83 $7C {$0E} [$01] {$75} $0A $8B $44
             $0A $05 [$0070W]  $8B $F8 $EB $03 $8B $7C $0A $B8 [$19DCW]  $50 $8B
             $44 $0C $05 [$0040W]  $50 $57 $9A $0F920003RL     $83 $C4 $06 $3D
             $FFFFW  {$74} $21 $8B $44 $0E $BA $003CW  $F7 $EA $8B $1E $40 $9E
             $89 $47 $16 $8B $44 $0E $89 $47 $0E $B8 [$002AW]  $50 $9A $196E09EFRL
                     $83 $C4 $02 $5F $5E $5D $CB


Throw another sprite (Shoot)

This behavior is nearly exactly the same as the above with the exception that it is designed for shots that move in an arc instead of a straight line. The difference is in line 5 where the value $FFF0W sets the shot's upwards speed. If the shot uses a 'fall' behavior then this will cause it to move in an arc. All other variables are the same as above.

Produce another sprite

#Custom behavior: Produce another sprite
%patch $3CDF $90 $90
%patch $3CF0 $55 $8B $EC $56 $57 $8B $76 $06 $83 $7C {$0E} [$01] {$75} $0A $8B $44
             $0A $05 [$0100W]  $8B $F8 $EB $03 $8B $7C $0A $B8 [$2C20W]  $50 $8B
             $44 $0C $05 [$0080W]  $50 $57 $9A $0F920003RL     $83 $C4 $06 $3D
             $FFFFW  {$74} $20 $8B $44 $0E $BA $0030W  $F7 $EA $8B $1E $40 $9E
             $89 $47 $16 $C7 $47 $18 [$FFF0W]  $B8 [$0026W]  $50 $9A $196E09EFRL
                 $83 $C4 $02 $5F $5E $5D $CB


Increase a counter to x then change action

This behavior causes a sprite to 'tick' a counter until that counter reaches a certain value, then its [[Patch:Sprite actions}action]] changes and the counter is reset. The end effect is a sprite can wait a while before changing its action (or other variable). However while doing so it can animate and do other things, which is different from the standard action timer.

The first line adds a certain amount to the timer variable $0032W; here this is +13 ticks per cycle. If the action type calls the behavior continuously (Say type 1 or 2) then the counter will increase much faster. The greater the addition the faster the counter will increase also.

This is followed at the end of line 1 with a check of the counter. Here if it is larger than $0400W then the action will change. Here the action changes to $19DCW or the first 'Vitalin got' action.

The counter is also reset by taking its reset value ($0034W) and copying it to the counter. The reset value set here is $0300W, so in this case all later sprites that use this behavior will switch in 1/4 the time of the first one.

It is good to set the counter when the sprite spawns or when the level starts so that there is a 'clean slate' each time.

Increase a counter to x then change action

#Custom behavior: Increase a counter to x then change action
%patch $3CDF $90 $90
%patch $3CF0 $55 $8B $EC $56 $8B $76 $06 $83 $06 {$0032W}  [$0D] $81 $3E {$0032W}
             [$0400W]  {$7C} $0B $C7 $44 $1C [$19DCW]  $A1 {$0034W}  $A3 {$0032W}  $5E
             $5D $CB

#Initial and reset counter values
%patch $30372 [$0000W  $0300W]


Play a sound

This behavior does nothing more than play a specific sound. This behavior must be called only once per action (Using the appropriate action type.) or the sound will play continuously. The blue value is the sound played.

Play a sound

#Custom behavior: Play a sound
%patch $3CDF $90 $90
%patch $3CF0 $55 $8B $EC $B8 [$0005W]  $50 $9A $196E09EFRL     $83 $C4 $02
             $5D $CB


Fall

This behavior causes a sprite to fall under the influence of gravity. This is actually a default behavior. It calls the 'gravity subroutine $E8 $FBB2W and as such the call will have to be changed if a custom behavior in a different location is created.

Increase a counter to x then change action

#Custom behavior: Fall under gravity
%patch $A7C0 $55 $8B $EC $56 $8B $76 $06 $56 $0E $E8 $FBB2W  $83 $C4 $02 $8B
             $44 $16 $F7 $2E $B4 $9B $A3 $BF85W  $5E $5D $CB


Keen 6

All behavior patches in this section require the removal of the Satellite as it uses the Satellite's behavior space. This is optional however and the behavior can be located elsewhere without this addition. (This will be needed in fact if more than one custom behavior from this section is desired.) All of these behaviors 'as-is' can be called in a sprite action as $0EFC0E08RL.


Randomly change action

This behavior causes the sprite that uses it to randomly change its action. (The example action here is that of the Viva got splash.) The random check is in line 1 and the action change in line 2. The probability of action change here is $0010W (Max $00FFW)

Randomly change action

#Custom behavior: Randomly change action
%patch $FDC8 $55 $8B $EC $56 $8B $76 $06 $9A $1CF30034RL     $3D [$0010W]  $7D
             $05 $C7 $44 $1C [$1A00W]  $5E $5D $CB


Randomly seek Keen

This behavior causes a sprite to randomly seek Keen horizontally, that is, turn in his direction. It works similarly to the above patch. If the $0001W and $FFFFW values are swapped then the sprite will randomly flee from Keen. It is also possible to remove the random check altogether.

Randomly seek Keen

#Custom behavior: Randomly seek Keen
%patch $FDC8 $55 $8B $EC $56 $8B $76 $06 $9A $1CF30034RL     $3D [$0020W]  {$7D}
             $19 $8B $44 $0A $8B $1E $64 $A9 $3B $47 $0A {$73} $08 $C7 $44 $0E
             [$0001W]  $5E $5D $CB $C7 $44 $0E [$FFFFW]  $5E $5D $CB


Produce a projectile

This behavior causes a sprite to produce a projectile (shot) moving in the same horizontal direction as the sprite. The projectile has an activity value of 3 (It will continue to animate and vanish when offscreen.), and a type of 4. (Enemy projectile.) Here it is spawned 4 pixels down from the shooting sprite's top ($0040W) and either 16 or 12 pixels right of its left side depending on whether the sprite is facing right or left respectively. Here the shot's starting action is $153EW (Keen's shot!) and it has a foreground value of 2.

Produce a projectile

#Custom behavior: Produce a projectile
%patch $FDC8 $55 $8B $EC $83 $EC $04 $56 $57 $8B $76 $06 $B8 $0001W  $50 $9A
             $069A1E25RL     $83 $C4 $02 $8B $1E $66 $A9 $C7 $47 $02 [$0003W]
             $C7 $07 [$0004W]  $8B $44 $0C $05 [$0040W]  $89 $47 $0C $8B $44 $0E
             $89 $47 $0E $83 $7C {$0E} [$01] {$75} $0B $8B $44 $0A $05 [$0100W]  $89
             $47 $0A $EB $0D $8B $44 $0A $05 [$00B0W]  $8B $1E $66 $A9 $89 $47
             $0A $8B $1E $66 $A9 $8B $47 $0E $B1 $05 $D3 $E0 $89 $47 $16 $B8
             [$153EW]  $50 $53 $9A $08F41219RL     $83 $C4 $04 $8B $1E $66 $A9
             $C7 $47 $20 [$0002W]  $5F $5E $8B $E5 $5D $CB


Jump

This behavior causes a sprite to jump a certain height and width (left or right.) There are two variables, the first is the jump width and the second the jump height. The sprite can jump off of edges when using this behavior.

Jump

#Custom behavior: Jump
%patch $FDC8 $55 $8B $EC $83 $EC $04 $56 $57 $8B $76 $06 $8B $44 $0E $D1 $E0
             $01 $46 $FC $47 $83 $FF $04 $7C $9B $8B $44 $0E $BA [$0018W]  $F7
             $EA $89 $44 $16 $C7 $44 $18 [$FFE0W]  $5F $5E $8B $E5 $5D $CB


Play a sound

This simple behavior causes the sprite that uses it to play a sound, nothing else. Caution must be taken as to what action type uses this as the sound can either be played once per action or continuously.

Play a sound

#Custom behavior: Play a sound
%patch $FDC8 $55 $8B $EC $B8 [$0037W]  $50 $9A $183B09F1RL     $83 $C4 $02 $5D
             $CB


Change a sprite variable

This simple behavior causes the sprite that uses it to change one if its variables. This can be anything from clipping to direction to animation. Though simple it can have a variety of uses.

Change a sprite variable

#Custom behavior: Change a sprite variable
%patch $FDC8 $55 $8B $EC $56 $8B $76 $06 $C7 $44 $04 [$0001W]  $5E $5D $CB


Keen Dreams

All behavior patches in this section require the removal of the titlescreen compression, which will be a given if the graphics have been edited in any way, as it uses the Satellite's behavior space. This is optional however and the behavior can be located elsewhere without this addition. All of these behaviors 'as-is' can be called in a sprite action as $0A100598RL.


Change action depending on sprite property

This behavior causes a sprite to change its action depending on a property of that sprite such as which direction it is facing or its type. This behavior has no associated movement or other code which means a sprite using it will do nothing but instantly change.

On the first line the sprite's property is checked; in this case integer 0 (Sprite type) is checked, and if equal to 5 then the sprite's action changes to Flower power thrown 1, otherwise it changes to Boobus Bomb explode 1. If it is desired that no change happen in one circumstance then the second action code, $C7 $44 $1E $0C4AW can be deleted.

The actions given here are just defaults and can be changed as desired.

Change action depending on sprite property

#Custom behavior: Change action depending on sprite property
%patch $A698 $55 $8B $EC $56 $57 $8B $76 $06 $8B $F8 $83 $7C {$00} [$05] {$75}
             $07 $C7 $44 $1E [$0BD2W]  $EB $05 $C7 $44 $1E [$0C4AW]
             $5F $5E $5D $CB


Move through the air

This behavior calls gravity and thus allows a sprite to fall or move through the air if tossed. The code is quite simple.

Move through the air

#Custom behavior: Move through the air
%patch $A698 $55 $8B $EC $56 $8B $76 $06 $56 $0E $E8 $D5AEW  $44 $44 $8B $44
             $16 $F7 $2E $D4 $BD $89 $44 $12 $5E $5D $CB