Patch:Tank Robot

From KeenWiki
Jump to: navigation, search

Tank Robots are harmless one-eyed enemies found in Keen 1 that shoot at Keen. This page lists patches relating to Tank Robot sprites. It is divided into sections relating to the various sprite properties the patches involve. Being fluent with various sprite patch pages will help when working with these patches.

Sprite Type

Tank Robots use sprite type 6 which means they push Keen about but don't hurt him. However the Tank Bot's shots can kill Keen if they touch him. This is what makes the Tank dangerous. See Patch:Keen (Keen 1) for how to patch the pushing of Keen. This will affect the Patch:Butler Robot too!

Patch: Keen 1
#Tank Robot sprite type:
%patch $171E $06

Sprite Behavior

Tanks have several simple, but closely related behaviors. They are spawned facing the screen, a behavior that is never used again. Then it settles into walking back and forth, occasionally shooting. Turning occurs after shooting, hitting a wall or reaching the end of a platform. The Tanks will turn towards Keen.

Interestingly turning occurs in three separate situations; the first is after shooting and the second when hitting right walls, but the third occurs both when hitting left walls or reach the (left or right) ends of platforms.

$1F75W #Tank Bot sit and animate
$1F8FW #Tank Bot turn
$1EA9W #Tank Bot walk\shoot
$1FC1W #Tank Bot shoot
$2045W #Tank Bot collision (Do nothing)

Patch: When spawned
%patch $1768 $1F75W

Patch: In level
%patch $1EE5 $1FC1W 
#Randomly shoot while walking
%patch $1F4E $1F8FW
#Turn after hitting right wall
%patch $1F68 $1F8FW
#Turn after hitting left wall or reaching end of platforms
%patch $1F8A $1EA9W
#Walk after spawn behavior
%patch $1FB7 $1EA9W
#Walk after turning
%patch $2040 $1F8FW
#Turn after shooting
%patch $176D $2045W
#Tank Robot collision

Complete Tank bot walking code

This is the complete default code for the Tank Robot's walking code. It contains, and is thus incompatible with, many of the patches on this page. The code can be divided into three sections, animation, shooting and tile collision.

For the animation code, the first thing done is to set the animations at the end of line 1 and the start of line 2. These will be different depending on the direction the bot is traveling. This is followed by the number of animation frames at the start of line 3. All of these values are highlighted in blue. Note that in the default code animation speed cannot be altered.

Line 4 is where the shooting code starts. A random check is made and if passed the Robot's behavior is set to 'shooting/ (At the same time it's frame timer and Misc variable B are set to 0, priming the shooting action.) The behavior is colored brown.

This is followed by two calls to gravity and tile collision, $E8 $xxxxW at the end of line 6. (Colored brown) Replacing the first with $90 $90 $90 will make the Bot never fall and the second will make it pass through tiles like a ghost. (Both of these affect the Tank Bot less than you would think.)

After this comes three tile checks, beneath, left and right. The first, on line 7, checks to see if the Bot has reached the end of a platform. If it has it then checks what direction it is facing (Rather oddly by checking what animation it is using; the default 'walk left' animation is $66, in blue.) If turning left its horizontal speed is set to $FFA6W (But while turning it will not move.) and a horizontal position adjustment of -18 pixels ($FF4CW) is made to stop it falling off the platform edge before the code jumps to the end of line 12, setting the action to 'turning'. If turning right then again a horizontal position adjustment is made (18 pixels, $00B4W, that is, in the opposite direction) before the code jumps to the start of line 12 where the speed is set to $005AW and the action is changed to 'turning'.

The next check is on line 10 and checks for right walls. If one is found the Robot's speed is changed to $FFA6W and the action to 'turning' Finally at the start of line 12 a check for left walls is performed. If one is found the speed is changed to $005AW and the action to 'turning'. Note that line 12 is jumped to by the 'end of platform' code discussed above.

Patch: Tank Bot moving code
#Tank Robot behavior code
%patch $1EA9 $55 $8B $EC $56 $83 $3E $40 $82 $00 $7E $08 $C7 $06 $48 $82 $0062W
#Animation stuff
$EB $06 $C7 $06 $48 $82 $0066W $A1 $5135W $D1 $E8 $D1 $E8 $D1 $E8 $25 $0003W $8B $16 $48 $82 $03 $D0 $89 $16 $48 $82 $E8 $A1F3W $3B $06 $14 $5B $73 $1E $C7 $06 $52 $82 $1FC1W $C7 $06
#Goto shooting
$4A $82 $0000W $C7 $06 $4C $82 $0000W $A1 $8240W $A3 $824EW $C7 $06 $40 $82 $0000W $E8 $0D28W $E8 $0D68W $8B $F0 $33 $C0 $A3 $8242W $A3 $823EW $F7 $C6 $02 $00 $75 $29 $83 $3E $48 $82
#Tile collision stuff
$66 $7D $13 $A1 $5B14W $BA $FF4CW $F7 $EA $A3 $823CW $C7 $06 $4C $82 $FFA6W $EB $35 $A1 $5B14W $BA $00B4W $F7 $EA $A3 $823CW $EB $22 $EB $26 $F7 $C6 $04 $00 $74 $14 $C7 $06 $4C $82 $FFA6W $C7 $06 $52 $82 $1F8FW $33 $C0 $A3 $8240W $A3 $824AW $F7 $C6 $01 $00 $74 $14 $C7 $06 $4C $82 $005AW $C7 $06 $52 $82 $1F8FW $33 $C0 $A3 $8240W $A3 $824AW $5E $5D $C3

Robot shooting time

This is how long the Tank Robot spends still while shooting. By default it is 78 game ticks. The longest it can be made to take turning is $7F game ticks, any higher causes near-instant shooting. Note however that if this time is too short then the Robot will stop, but not produce a shot.

Patch: Tank Robot turning time
#Tank Robot turning time
%patch $2012 $78 $7E

Robot turning behavior code

This is the complete default code for the Tank Robot's turning code. It contains, and is thus incompatible with, many of the patches on this page.

The turning code is quite simple. On the third line is a time check, once this time is up the behavior will change to walking and several variables will be reset. This happens at the end of the code. On the second line the animation speed, animation frames and sprite are set, in that order. All these values are marked in blue.

Patch: Tank Robot turning behavior code
#Tank Robot turning behavior code
%patch $1F8F $55 $8B $EC $A1 $824AW $03 $06 $14 $5B $A3 $824AW $A1 $5135W $B1 $04 $D3 $E8 $25 $0001W $05 $006AW $A3 $8248W $83 $3E $824AW $32 $7E $0C $C7 $06 $52 $82 $1EA9W $A1 $824CW $A3 $8240W $5D $C3

Robot turning time

This is how long the Tank Robot spends turning. By default it is 32 game ticks. The longest it can be made to take turning is $7F game ticks, any higher causes near-instant turning. To skip turning all together simply replace the turning behavior with a walking one.

Patch: Tank Robot turning time
#Tank Robot turning time
%patch $1FB0 $32 $7E

Robot turning horizontal adjustment

When turning the robot must adjust its horizontal position or become stuck at the edge of platforms. (This may also occur if the Robot's sprite width has been changed.) To do this it moves back a number of pixels before turning. (So this is actually part of the robot moving code.) By default this is 18 pixels backwards. There are two equal and opposite entries for turning left and right.

Patch: Tank Robot turning horizontal adjustment
#Tank Robot turning horizontal adjustment
%patch $1F20 $FF4CW
#When turning right
%patch $1F33 $00B4W
#When turning left

Robot face screen code

This is the complete code for the first behavior the Tank Robot uses, that of facing the screen. Its sole function is to change the behavior to that of a walking Tank Robot, this is done in the second line. The behavior calls gravity and tiles in the first line.

Patch: Tank Robot face screen behavior code
#Tank Robot face screen behavior
%patch $1F75 $55 $8B $EC $56 $E8 $0CAEW $E8 $0CEEW $8B $F0 $A9 $02 $00 $74 $06 $C7 $06 $52 $82 $1EA9W $5E $5D $C3

Speed and Jump Height

The default speed of Tank Robots is +-90. When spawned Tank Robots will head right by default. They will also head towards Keen after turning (if possible.) While turning Tanks sit still.

Patch: Starting speed
%patch $1747 $005AW 
#Initial speed (Move right)

Patch: In level
%patch $1F2B $FFA6W 
#Left speed
%patch $2019 $005AW
#Right speed after shooting
%patch $2034 $FFA6W
#Left speed after shooting
%patch $1EFD $0000W
#Sit still while turning

Shot speed

This alters the Tank's shot's speed. However the shot will always move in one direction all the time, which is limiting.

Patch: Keen 1
#Tank shot moves l or r
%patch $490F $C7 $44 $20 $0190W $90
#Thank shot moves u or d
%patch $490F $C7 $44 $22 $FFA6W $90

Sprite Collision

Tank Robots 'interact' with its own shots, being immune to them, so it can shoot Keen. The shots also don't interact with Zap\Zots produced by other Tank shots (But do react with other Zap\zots!) Oddly enough it doesn't interact with anything else, relying on other sprites to interact with it. As such the two interaction patches below are for the Tank's shot, not the Tank itself.

Patch: Keen 1
%patch $176D $2045W  
#Tank Robot collision
%patch $4A0C $3D $06
#Tank shots NOT killed by Tanks
%patch $4A11 $3D $0E
#Tank shots not killed by Tank zap/zots


An interesting note about Tanks is that their walking animation does not work like others in Keen 1; this results in the odd fact that it is vital that the walking left animation variable is larger than that of walking right. If somehow this is not the case then the Robot will often get stuck when it reaches the left end of a platform. This also means the default code does not have a variable for the animation speed. (See subsection below however.)

Finally there is an odd use of sprite animation; when turning the Robot must adjust its horizontal position. This involves checking what direction it is facing and this si done very oddly by checking which animation it is currently using. If it is using the walking left animation then it will adjust right, anything else and it adjusts left. Therefore this check must match the walking left animation if this is changed.

Patch: When spawned
%patch $1772 $006AW 

Patch: In level
%patch $1EC0 $0066W 
#Walking left
%patch $1EB8 $0062W
#Walking right
%patch $1ECC $03
#And next 3 frames
#Slow down Tank's walking animation speed
%patch $1ED2 $02 %patch $1FA7 $006AW
%patch $1FA4 $01
#And next frame
%patch $1FA0 $04
#Animation speed
#Turning horizontal adjustment check
%patch $1F19 $66

Change walking Robot's animation speed

This patch makes the Tank Robot's animation work the same way as most sprites in the game, eliminating the odd animation bug mentioned above and allowing its animation speed to be easily controlled.

This patch will overwrite, and is thus incompatible with, the number of frames when walking patch above. (In this patch is is the second blue variable, $0003W.) The animation speed is now given by the blue $05 in the patch.

Patch: Change walking Robot's animation speed
#Change walking Robot's animation speed
%patch $1EC5 $B1 $05 $D3 $E8 $25 $0003W $90 $90

Tank spawn height

The Tank spawns 8 pixels lower than where it is placed, because it is not quite two tiles tall. If the Tank's sprite height is changed this should also be changed by the same amount.

Patch: Keen 1
#Tank's spawn height
%patch $1739 $0800W
#Eight pixels down


These are the sounds the sprite uses.

Patch: Keen 1
#Tankbot fire sound
%patch $1FDC $26
#Don't make #Tankbot fire sound:
%patch $1FDB $EB $07

Tank's Shots

This patch relates to the Tank's shot rather than the Tank itself.

Shot height

This controls the height at which the Tank's shots are spawned. It is divided into two values, the first in a 'fine-tuner', the number of pixels down from the Tank sprite's top the bullet appears. The second value is much rougher and is worth 256 pixels when +-1 It is really only useful when making the shot appear a negative number of pixels below (That is above) the sprite, when it will be changed to $FFFFW.

Patch: Keen 1
#Robot shot height (Default $000005, if zero then no shot appears)
%patch $4900 $05 %patch $4902 $0000W

Tank does not shoot

This patch skips the Tank shooting code. This makes the Tank robot entirely predictable, it moves back and forth.

Patch: Keen 1
#Tank does not shoot
%patch $1EDF $EB


These are patches that do not fit into any of the above sections. They may affect other sprites or have unintended side-effects.

Tank's shots aim towards Keen

With this patch the Tanks shots will always aim to hit Keen, no matter where he is. They will move horizontally and head towards his position when the shot was fired. This uses a patch to free up some space then redirects the Tank shot code.

The speed is hard to set and is highlighted in blue. It uses a double precision floating point number for the speed. To change the speed go here[1] and enter the speed you want and click 'rounded' The series of bytes in the hexadecimal entry in the bottom (64 bit) section will be the sequence of bytes you need to replace the blue bytes with. (Only integer values between +-1000 please!) The default patch speed is 500 so you can see how this works. (And how the bytes are placed in the patch in REVERSE order.)

The speed is the total bullet speed, both h and v.

Patch: Keen 1
#Robot's shot always aimed (Vertically and horizontally) towards Keen
%patch $4912 $E9 $0B $E6 %patch $2CE0 $A1 $3E $82 $66 $98 $66 $8B $D8 $66 $A1 $30 $82 $66 $03 $C3 $66 $A3 $30 $82 $66 $C1 $E8 $0C $89 $46 $F8 $66 $A1 $38 $82 $66 $03 $C3 $66 $A3 $38 $82 $66 $C1 $E8 $0C $89 $46 $F6 $66 $A1 $2C $82 $66 $C1 $E8 $0C $89 $46 $FC $66 $A1 $34 $82 $66 $C1 $E8 $0C $89 $46 $FA $83 $FB $00 $0F $84 $CE $00 $7C $65 $66 $A1 $38 $82 $66 $2B $C3 $66 $C1 $E8 $0C $3B $46 $F6 $0F $84 $BA $00 $8B $4E $FC $3B $4E $FA $0F $8F $B0 $00 $8B $46 $F6 $0F $AF $06 $08 $6C $03 $C1 $D1 $E0 $C4 $1E $48 $6C $03 $D8 $26 $8B $1F $D1 $E3 $83 $BF $34 $0A $00 $74 $28 $C7 $06 $42 $82 $00 $00 $66 $A1 $38 $82 $66 $40 $66 $25 $FF $0F $00 $00 $66 $29 $06 $3E $82 $66 $29 $06 $30 $82 $66 $29 $06 $38 $82 $C7 $46 $F4 $02 $00 $EB $6A $41 $EB $B0 $66 $A1 $30 $82 $66 $2B $C3 $66 $C1 $E8 $0C $3B $46 $F8 $74 $57 $8B $4E $FC $3B $4E $FA $7F $4F $8B $46 $F8 $0F $AF $06 $08 $6C $03 $C1 $D1 $E0 $C4 $1E $48 $6C $03 $D8 $26 $8B $1F $D1 $E3 $83 $BF $C0 $13 $00 $74 $2E $C7 $06 $42 $82 $00 $00 $66 $A1 $30 $82 %patch $2DD0 $66 $25 $FF $0F $00 $00 $66 $F7 $D8 $66 $05 $00 $10 $00 $00 $01 $06 $3E $82 $66 $01 $06 $30 $82 $66 $01 $06 $38 $82 $C7 $46 $F4 $08 $00 $EB $03 $41 $EB $AC $A1 $3C $82 $66 $98 $66 $8B $D8 $66 $A1 $2C $82 $66 $03 $C3 $66 $A3 $2C $82 $66 $C1 $E8 $0C $89 $46 $F8 $66 $A1 $34 $82 $66 $03 $C3 $66 $A3 $34 $82 $66 $C1 $E8 $0C $89 $46 $F6 $66 $A1 $30 $82 $66 $C1 $E8 $0C $89 $46 $FC $66 $A1 $38 $82 $66 $C1 $E8 $0C $89 $46 $FA $83 $FB $00 $0F $84 $CC $00 $7C $64 $66 $A1 $34 $82 $66 $2B $C3 $66 $C1 $E8 $0C $3B $46 $F6 $0F $84 $B8 $00 $8B $4E $FC $3B $4E $FA $0F $8F $AE $00 $8B $C1 $0F $AF $06 $08 $6C $03 $46 $F6 $D1 $E0 $C4 $1E $48 $6C $03 $D8 $26 $8B $1F $D1 $E3 $83 $BF $86 $18 $00 $74 $27 $C7 $06 $40 $82 $00 $00 $66 $A1 $34 $82 $66 $40 $66 $25 $FF $0F $00 $00 $66 $29 $06 $3C $82 $66 $29 $06 $34 $82 $66 $29 $06 $2C $82 $83 $4E $F4 $04 $EB $69 $41 $EB $B1 $66 $A1 $2C $82 $66 $2B $C3 $66 $C1 $E8 $0C $3B $46 $F8 $74 $56 $8B $4E $FC $3B $4E $FA $7F $4E $8B $C1 %patch $2EC0 $0F $AF $06 $08 $6C $03 $46 $F8 $D1 $E0 $C4 $1E $48 $6C $03 $D8 $26 $8B $1F $D1 $E3 $83 $BF $FA $0E $00 $74 $2D $C7 $06 $40 $82 $00 $00 $66 $A1 $2C $82 $66 $25 $FF $0F $00 $00 $66 $F7 $D8 $66 $05 $00 $10 $00 $00 $01 $06 $3C $82 $66 $01 $06 $34 $82 $66 $01 $06 $2C $82 $83 $4E $F4 $01 $EB $03 $41 $EB $AD $8B $46 $F4 $5F $5E $8B $E5 $5D $C3 %patch $2F20 $EB $14 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $40 $7F $40 $00 $00 $00 $00 $50 $66 $A1 $DE $6E $66 $2B $44 $04 $66 $05 $C8 $00 $00 $00 $66 $2E $A3 $22 $2F $66 $A1 $E2 $6E $66 $2B $44 $08 $66 $05 $58 $02 $00 $00 $66 $2E $A3 $26 $2F $2E $DB $06 $26 $2F $D9 $E0 $2E $DB $06 $22 $2F $D9 $F3 $DD $D1 $D9 $FF $2E $DC $0E $2A $2F $2E $DF $1E $32 $2F $D9 $FE $2E $DC $0E $2A $2F $D9 $E0 $2E $DF $1E $34 $2F $2E $A1 $32 $2F $89 $44 $20 $2E $A1 $34 $2F $89 $44 $22 $58 $E9 $7C $19

Turn after shooting right

The Tank will turn left whenever it shoots right, but otherwise will turn towards Keen if possible.

Patch: Keen 1
#Robot turns around every time he shoots right
%patch $2015 $C0

Vanish after shooting

The first time the Tank shoots it will disappear. Manipulation of its shooting frequency may be needed.

Patch: Keen 1
#Tank vanishes when it shoots
%patch $4A06 $7D $03