Patch:Sprite-tile interaction

From KeenWiki
Jump to: navigation, search

The tile-checking (and/or drawing) function is a 32-bit (far) pointer to code that instructs the sprite based on its collisions with tiles (top, left, bottom, or right blocking). The tile checking function is also responsible for directing the game to draw the sprite. Unlike the sprite behavior functions, which might be called sporadically, the tile checking function is always called, every animation frame.

This page provides a section that lists of the default values of tile collision pointers used in Keen Galaxy and Dreams. Following that section is a section that lists general tile interaction codes, that is, codes used by more than one sprite. (These are usually quite simple.) patches relating to the tile interaction codes of specific sprites will be found on their pages.

Note that the code responsible for keeping things out of solid tiles (That is walking through walls or falling through floors.) is separate and is known as 'clipping code' This will depend on a sprite's clipping value, and is the same for all sprites, the player included.

Related pages are Patch:Sprite behavior and Patch:Sprite collision. Patching tile check is simple enough, a four-byte pointer for every sprite action that you wish to change. Interestingly, sprite tile checks and drawing are rather simpler and different in Keen Vorticons, integrated with the main sprite code, and as such there are no patches for Vorticons on this page. Patches do however tend to be more difficult and only really useful when copying a value to increase the number of actions a sprite has.


Values in games

There are two unique values for each game that should be noted. The first is 'draw sprite'; this interaction doesn't look for any specific tiles; clipping will keep a sprite out of walls and floors (Or not if it doesn't have any.) but it will not turn or jump or do anything else unusual relating to edges, walls or slopes.

The second is the generic 'stay on platform' interaction. This causes a sprite to turn at walls and reverse direction at platform edges. As a side-effect a sprite stuck 'in the air' will twitch left and right forever, stuck in a loop.

Keen 4:
$00000000L     #Nothing (Doesn't draw sprite!)
$04EC0FA8RL    #Display 'Not enough memory to save game' window, restart level
$0D8F0E32RL    #Keen's shot (Hit walls, floors, ceilings and go zap.)
$0E8F112FRL    #Swimming Keen (Hit walls, ceilings and floor 'softly')
$09DC1795RL    #General 'stay on platforms' interaction
$09DC176ERL    #Sit (Ignore all tiles unless clipped to notice them)
$09DC1847RL    #Crawling Poison Slug
$09DC1913RL    #Stunned sprite
$0B801A7BRL    #Floating Keen (Ignore all tiles, but stay in one place, e.g on poles.)
$0B801AA2RL    #Standing Keen
$0B801B5FRL    #Walking Keen
$0B801C48RL    #Jumping Keen
$0B801F81RL    #Pogoing Keen
$0B802071RL    #Going down poles Keen
$0FA804ECRL    #Mad Mushroom (Bounce like Mushroom off floors and ceilings)
$0FA808A1RL    #Walking Bird (Walk on ground)
$0FA80945RL    #Landing Bird (Check for ground, if found become walking Bird)
$0FA8097FRL    #Eggshell fragment (Move until hit ground)
$0FA809B4RL    #Flying Bird (Hit walls, get stuck or go to landing Bird)
$0FA80D0BRL    #Flying Skypest (Bounce off stuff, land sometimes)
$108002E1RL    #Cloud (Float, reverse when hitting walls)
$1080055ERL    #Berkeloid flame (Fly through air, become landed flame after hitting ground)
$108005B5RL    #Flaming Berkeloid (Float above ground)
$10800610RL    #Berkeloid (Float above ground and 'walk' along it)
$1080097ERL    #Bounder (Bounce off ground)
$10800C71RL    #Lick on ground (Wait then jump)
$10800F56RL    #Controllable Airboard (Ignore tiles, look for B sprites)
$11A203DERL    #Jumping Smirky (Hit ceilings and stick, land on floors)
$11A205C1RL    #Jumping Mimrock (Hit ceilings, walls and floors)
$11A2062ERL    #Bouncing Mimrock (Hit floors)
$11A20A3CRL    #Swimming Dopefish and Schoolfish (Mind walls)
$11A20CA1RL    #Enemy shot (Darts, Sprite's shot; shoot into walls and vanish
Keen 5:
$00000000L     #Nothing (Doesn't draw sprite!)
$090B17B5RL    #Draw sprite
$090B17DCRL    #General 'stay on platforms' interaction
$090B195ARL    #Stunned sprite
$0AAF1A9FRL    #Keen sit ('Sit in air'; similar to normal Keen)
$0AAF1AC6RL    #Keen (Blocked by blocking tiles, killed by deadly, etc, complex.)
$0AAF1B83RL    #Keen walk
$0AAF1C6CRL    #Keen in air (Fall, hit ground and walls)
$0AAF200BRL    #Keen pogo (Can break fuses!)
$0AAF2145RL    #Keen go down poles (If no pole left, fall)
$0CCB11A2RL    #Keen's shot
$0F920119RL    #Explosion fragments
$0F9200A8RL    #Master teleport
$0F9216ACRL    #Enemy shot
$11020188RL    #Sparky
$11020679RL    #Ampton walk (Check for poles and switches too)
$11020897RL    #Bouncy Slicestar
$11020B2FRL    #Shelley walk
$11020BA1RL    #Shelley fall
$11C4090ERL    #Shikadi mine
$11C40B09RL    #Robo red's shoot
$11C40C03RL    #Spirogrip slam
$11C40D86RL    #Spindred
$11C411B0RL    #Master's shot
$11C41248RL    #Master's sparks
$11C41538RL    #Shikadi (Check for poles)
$11C4179FRL    #Shocksund
$11C418CBRL    #Shocksund jump
$11C41980RL    #Shocksund's shot
$11C41AC4RL    #Sphereful
Keen 6:
$00000000L     #Nothing (Doesn't draw sprite!)
$08F4180ARL    #Draw sprite
$08F41831RL    #General 'stay on platforms' interaction
$08F419AFRL    #Stunned sprite
$0CA60FB1RL    #Keen's shot (Hit walls, floors, ceilings and go zap.)
$0EFC00B9RL    #Don't change until hitting the ground
$0EFC1754RL    #Goplat
$0EFC1A7FRL    #General 'stay on platforms' interaction but flashes when shot
$10CC07C6RL    #Pink shot
$11CF0602RL    #Babobba falling
Remaining: TODO
Keen Dreams:
$0868014BRL    #Cart
$07C501DDRL    #Draw sprite
$07C50299RL    #Run back and forth, turning at walls and edges
$07C5022DRL    #Draw sprite 2?
$07C506C4RL    #Tomatooth
$07C507DCRL    #Carrot run
$07C509DERL    #Grape fall
$07C509A7RL    #Grape rise
$086804AFRL    #Melon pips
$08680E1DRL    #Boobus Tuber walk
$08680ED4RL    #Boobus Tuber in air
Remaining: TODO


General interaction codes

As mentioned above these are tile interaction codes that affect more than one sprite. Altering them will affect the game as a whole, but copying them may be useful.


Keen 4

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


Just draw sprite

This is the simplest interaction code, it does nothing but draw the sprite. Tile clipping is handled automatically by the clipping code. This code is used by anything that just needs to appear in-level and not worry about hills or walking. (E.g. Clouds.) This occurs in the executable by default and can be called by using $09DC176ERL.

Patch: Keen 4
#Custom tile collision: Draw sprite
%patch $B52E $55 $8B $EC $56 $8B $76 $06 $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16541641RL $83 $C4 $0C $5E $5D $CB


Vanish when hitting any solid tile

This tile interaction causes the sprite to vanish when it hits any solid tile of any type. This includes slopes, one-way-up tiles and so on. This is used by enemy projectiles such as Darts.

Patch: Keen 4
#Custom tile collision: Vanish when hitting any solid tile
%patch $3CE5 $90 $90 %patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $83 $7C $36 $00 $75 $12 $83 $7C $38 $00 $75 $0C $83 $7C $3A $00 $75 $06 $83 $7C $3C $00 $74 $0C $56 $9A $06BD1E8BRL $83 $C4 $02 $5E $5D $CB $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16541641RL $83 $C4 $0C $5E $5D $CB


Smash like Keen's shot when hitting any solid tile

This collision is identical to the above collision except that instead of vanishing the sprite smashes like Keen's shot, with the same sound and smashed shot sprite.

Patch: Keen 4
#Custom tile collision: Smash like Keen's shot when hitting any solid tile
%patch $3CE5 $90 $90 %patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $83 $7C $36 $00 $75 $12 $83 $7C $38 $00 $75 $0C $83 $7C $3A $00 $75 $06 $83 $7C $3C $00 $74 $0C $56 $9A $0D8F0D43RL $83 $C4 $02 $5E $5D $CB $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16541641RL $83 $C4 $0C $5E $5D $CB


Custom smash when hitting any solid tile

This collision is identical to the above except the modder can choose both the action and sound the sprite changes to (Both marked in blue). It involves the creation of a 'sprite change' subroutine that can be called by other sprites as well.

Patch: Keen 4
#Custom tile collision: Hit tiles and smash
%patch $3CE5 $90 $90 %patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $83 $7C $36 $00 $75 $12 $83 $7C $38 $00 $75 $0C $83 $7C $3A $00 $75 $06 $83 $7C $3C $00 $74 $0C $56 $9A $2EE7011FRL $83 $C4 $02 $5E $5D $CB $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16541641RL $83 $C4 $0C $5E $5D $CB
#Smash code = $2EE7011FRL
%patch $2EF8F $55 $8B $EC $56 $8B $76 $06 $C7 $04 $01 $00 $B8 $39F8W $50 $56 $9A $09DC120ARL $83 $C4 $04 $B8 $0019W $50 $9A $187409F1RL $83 $C4 $02 $5E $5D $CB


Bounce on ground with noise

This tile collision is similar to that of the Mad Mushroom; any sprite using it will bounce off of flat ground while making a noise. (It will also bounce down off of ceilings, making no noise.)

The first blue value is the 'downwards bounce' the sprite experiences when hitting ceilings. If this is made large enough the sprite can be made to bounce rapidly between floor and ceiling. The second value is the height of the upwards bounce and the third value the sound played when a floor bounce occurs.

Patch: Keen 4
#Custom tile interaction: Bounce with noise on ground
%patch $3CE5 $90 $90 %patch $3CF6 $55 $8B $EC $56 $8B $76 $06 $83 $7C $3A $00 $74 $05 $C7 $44 $18 $0010W $83 $7C $36 $00 $74 $11 $C7 $44 $18 $FFBCW $B8 $0010W $50 $9A $187409F1RL $83 $C4 $02 $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16541641RL $83 $C4 $0C $5E $5D $CB


Keen 5

These patches are existing tile collisions so modifying them will alter the behavior of default sprites.


Fall until hit ground

This is a general tile interaction that allows a sprite to fall until it hits a floor at which point it will change to the next action in its action structure. This is generally used by sprites with an action type of 2, that is, an action that will not animate. It is called by using the interaction value of $0F9200A8RL.

The sprite will also stop moving horizontally if it touches a wall. On the first line two checks are made for left and right walls respectively. If detected then the sprite's horizontal speed is set to 0 on the second line.

On the end of the second line ceilings are checked for, and if found the sprite's vertical speed is set to 0. Finally on the same line floors are checked for, and if found, again vertical speed is set to 0. If touching a floor and its next action (variable $1C) is 0 then the 'remove object' code is run (The sprite is destroyed.) This happens on lines 5-6 The remaining code draws the sprite on screen.

Patch: Keen 5
#Generic fall until hit ground tile collision
%patch $F9C8 $55 $8B $EC $56 $8B $76 $06 $83 $7C $38 $00 $75 $06 $83 $7C $3C $00 $74 $05 $C7 $44 $16 $0000W $83 $7C $3A $00 $74 $05 $C7 $44 $18 $0000W $83 $7C $36 $00 $74 $28 $C7 $44 $18 $0000W $8B $5C $1C $83 $7F $1C $00 $74 $0E $FF $77 $1C $56 $9A $090B1242RL $83 $C4 $04 $EB $0C $56 $9A $06B91E47RL $83 $C4 $02 $5E $5D $CB $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $174E163ERL $83 $C4 $0C $5E $5D $CB


Turn at platform edges

This is a general tile interaction that allows a sprite to walk back and forth on a platform and turn at edges. t does not however allow it to turn when it hits a wall; if this happens it will keep running against the wall. It is called by using the interaction value of $11020B2FRL and overwrites the Shelley's walking tile interaction.

The first line checks to see if the sprite is moving right; if it is it then checks to see if there is ground underneath. If not its horizontal direction is set to right (-1 or $FFFFW) and the next check is skipped.

On the third line a check is made to see if the sprite is moving left; if it is then a ground check is made which if failed sets the sprite's horizontal direction to right 9+1 or $0001W). The rest of the code draws the sprite onscreen.

In order for this interaction to work the sprite action using it also enable its 'stick to ground' variable.

Patch: Keen 5
#Generic turn at platform edges tile collision
%patch $11B4F $55 $8B $EC $56 $8B $76 $06 $83 $7C $0E $01 $75 $13 $83 $7C $36 $00 $75 $0D $8B $44 $12 $29 $44 $0A $C7 $44 $0E $FFFFW $EB $17 $83 $7C $0E $FF $75 $11 $83 $7C $36 $00 $75 $0B $8B $44 $12 $29 $44 $0A $C7 $44 $0E $0001W $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $174E163ERL $83 $C4 $0C $5E $5D $CB


Keen 6

These patches are existing tile collisions so modifying them will alter the behavior of default sprites.


Stay on platforms

This interaction makes a sprite turn when it hits a wall and reverse direction when it reaches the edge of a platform. It is also responsible for some sprites getting 'stuck' in midair (This is due to 'action resetting'). It can be divided up into four sections.

The first section starts on line 1. It checks if the sprite is moving right and if so then checks to see if it is touching a right wall. If it is then the sprite's horizontal direction is set to -1 (left) and the action is reset. It then skips the second and third sections.

The second section starts at the end of line 4 and checks to see if the sprite is moving left. If so it then checks to see if the sprite is touching a left wall. If it is then the sprite's horizontal direction is set to 1 (right) and the action is reset. It then skips the third section.

The third section starts int he middle of line 7 and checks to see if the sprite is touching a floor. If it is not then its horizontal direction is reversed (left becomes right and right left.) and its action reset.

The fourth section begins on line 10 and draws the sprite on the screen.

Patch: Keen 6
#'Stay on platforms' tile interaction
%patch $A771 $55 $8B $EC $56 $8B $76 $06 $83 $7C $0E $01 $75 $2A $83 $7C $3C $00 $74 $24 $8B $44 $12 $29 $44 $0A $C7 $44 $0E $FFFFW $9A $1CF30034RL $B1 $05 $D3 $F8 $89 $44 $08 $FF $74 $1C $56 $0E $E8 $FA34W $83 $C4 $04 $EB $5B $83 $0E $FF $75 $2A $83 $7C $38 $00 $74 $24 $8B $44 $12 $29 $44 $0A $C7 $44 $0E $0001W $9A $1CF30034RL $B1 $05 $D3 $F8 $89 $44 $08 $FF $74 $1C $56 $0E $E8 $FA04W $83 $C4 $04 $EB $2B $83 $7C $36 $00 $75 $25 $8B $44 $12 $29 $44 $0A $8B $44 $0E $F7 $D8 $89 $44 $0E $9A $1CF30034RL $B1 $05 $D3 $F8 $89 $44 $08 $FF $74 $1C $56 $0E $E8 $F9D7W $83 $C4 $04 $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16081770RL $83 $C4 $0C $5E $5D $CB


Stay on platforms, flash when shot

This interaction makes a sprite turn when it hits a wall and reverse direction when it reaches the edge of a platform. It is also responsible for some sprites getting 'stuck' in midair (This is due to 'action resetting'). It is identical to the above interaction but also allows the sprite to flash when it is shot by Keen. It can be divided into five sections.

The first section starts on line 1. It checks if the sprite is moving right and if so then checks to see if it is touching a right wall. If it is then the sprite's horizontal direction is set to -1 (left) and the action is reset. It then skips the second and third sections.

The second section starts at the end of line 4 and checks to see if the sprite is moving left. If so it then checks to see if the sprite is touching a left wall. If it is then the sprite's horizontal direction is set to 1 (right) and the action is reset. It then skips the third section.

The third section starts int he middle of line 7 and checks to see if the sprite is touching a floor. If it is not then its horizontal direction is reversed (left becomes right and right left.) and its action reset.

The fourth section begins on line 10, it checks to see whether the sprite's first misc variable is 1 (This happens by default if the sprite has multiple health and is shot by Keen, but can happen under other circumstances if coded.) If it is then the sprite is drawn, but 'flashed' (all white) if it is not the sprite is drawn normally in the fifth section.

Patch: Keen 6
#'Stay on platforms' and flash when shot tile interaction
%patch $10A3F $55 $8B $EC $56 $8B $76 $06 $83 $7C $0E $01 $75 $2B $83 $7C $3C $00 $74 $25 $8B $44 $12 $29 $44 $0A $C7 $44 $0E $FFFFW $9A $1CF30034RL $B1 $05 $D3 $F8 $89 $44 $08 $FF $74 $1C $56 $9A $08F41297RL $83 $C4 $04 $EB $5F $83 $7C $0E $FF $75 $2B $83 $7C $38 $00 $74 $25 $8B $44 $12 $29 $44 $0A $C7 $44 $0E $0001W $9A $1CF30034RL $B1 $05 $D3 $F8 $89 $44 $08 $FF $74 $1C $56 $9A $08F41297RL $83 $C4 $04 $EB $2E $83 $7C $36 $00 $75 $28 $8B $44 $12 $D1 $E0 $29 $44 $0A $8B $44 $0E $F7 $D8 $89 $44 $0E $9A $1CF30034RL $B1 $05 $D3 $F8 $89 $44 $08 $FF $74 $1C $56 $9A $08F41297RL $83 $C4 $04 $83 $7C $3E $00 $74 $24 $FF $4C $3E $FF $74 $20 $B8 $0001W $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16081770RL $83 $C4 $0C $5E $5D $CB $FF $74 $20 $33 $C0 $50 $FF $74 $1E $FF $74 $0C $FF $74 $0A $8B $C6 $05 $46 $00 $50 $9A $16081770RL $83 $C4 $0C $5E $5D $CB