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.

This page is divided into two major sections; the first deals with the Tank Robot itself, while the second deals with its shots. The first section contains patches such as those controlling the Tank's speed while the second contains patches such as those controlling the shot's speed. Patches about the Tank shooting (And things like shot position relative to the Tank) are in the first section.


Tank Robot Patches

This section contains patches relating to the Tank Robot itself, including those about how it shoots.


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.)

Note that if the Tank's type is changed without also changing the 'ignore Tank type' then the Tank's own shots will smash as soon as they're produced, rendering them essentially useless.

Patch: Keen 1
#Tank Robot sprite type:
%patch $171E $06
#Ignore Tank type:
%patch $4A0C $3D $06


Sprite Behavior

Tanks have several simple, but closely related behaviors. They are spawned facing the screen, a behavior used to allow them to fall to ground level that is therefore only used once. 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.

Behaviors:
$1F75W #Tank Bot fall to ground
$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


Robot 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 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 fall code

This is the complete code for the first behavior the Tank Robot uses, that of facing the screen and falling down. Its sole function is to find a floor, and after doing so go to the walking behavior. 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


Robot shooting code

This is the robot's complete shooting code. The first thing to note is that it does not produce a shot on its own, rather it calls shot production code which happens elsewhere.

On the first line the bot's timer counts up. On the second line the bot checks if it has shot already and, if not, checks its timer. If this is more than $50 game ticks it proceeds to shoot.

Shooting starts with producing sound $26. On line 3 the bot checks its former speed (How fast it was moving before it stopped to shoot) and stores a shot speed value. (This will make the shot move left or right depending on which direction the bot was moving before it shot.) On line 4 it sends its position to the 'make a shot' code.

After this, on line 5, the bot sets it's 'has shot' value to 1, so that it won't shoot more than once. It then checks its timer, if this is less than $7E then nothing else happens, the bot merely pauses.

Otherwise the bot ends its shooting behavior. First it checks where the player is and changes its speed to head towards him. Then it changes its timer to 0 and its behavior to 'walk'.

Patch: Robot shooting code
#Tank shooting behavior
%patch $1FC1 $55 $8B $EC $56 $A1 $824AW $03 $06 $14 $5B $A3 $824AW $83 $3E $824CW $00 $75 $38 $3D $5000W $7E $33 $B8 $0026W $50 $E8 $9F11W $44 $44 $BE $015EW $83 $3E $824EW $00 $7D $03 $BE $FEA2W $56 $FF $36 $822AW $FF $36 $8228W $FF $36 $8226W $FF $36 $8224W $E8 $28D9W $83 $C4 $0A $C7 $06 $824CW $0001W $83 $3E $824AW $78 $7E $2D $C7 $06 $824CW $005AW $A1 $8226W $8B $16 $8224W $3B $06 $6EE0W $7C $0E $7F $06 $3B $16 $6EDEW $76 $06 $C7 $06 $824CW $FFA6W $C7 $06 $824AW $0000W $C7 $06 $8252W $1F8FW $5E $5D $C3


Robot shooting time

This is how long the Tank Robot spends still while shooting. There are two values; the first is a pause before a shot is produce, and the second is the total pause time. By default it is $78 game ticks. The longest it can be made to take turning is $7F game ticks. If the total shoot time is less than the pause before shooting time then no shot will be produced.

Patch: Tank Robot turning time
#Tank Robot turning time
%patch $1FD7 $50
#Pause before shot
%patch $2012 $78 $7E
#Total pause time


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


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


Sprite Collision

Tank Robots have no real collision; while they do stuff to Keen this is a result of Keen's code rather than their own. The Tank's shots however have a special interaction that allows them to be shot by Tanks and not be auto-destroyed.

Patch: Keen 1
%patch $176D $2045W  
#Tank Robot collision (Do nothing)


Animations

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 
#Start

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
#Turning
%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 and shot position

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.

The Tank's shot is spawned five pixels down from the very top of the Tank sprite. This value can be anything up to $7F, that is nearly eight tiles down from the top of the sprite. It's horizontal spawn position cannot be altered.

Patch: Keen 1
#Tank's spawn height
%patch $1739 $0800W
#Eight pixels down
#Robot shot height
%patch $4900 $05
#Five pixels from Tank top


Sounds

These are the sounds the sprite uses, in this case only one; when it shoots. This sound can be blocked.

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


Misc

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


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 it 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


Tank Shot Patches

This section contains patches relating to the Tan Robot's shot, such as its animation or speed.


Sprite Type

Tank shots use sprite type 11 ($0B) which is lethal to Keen on contact.

Patch: Keen 1
#Tank shot sprite type:
%patch $48E9 $0B


Sprite Behavior

Tank shots have one behavior; this checks for tiles and if it finds any solid ones, destroys the shot and sets its behavior to Zap/Zot.

Patch: Keen 1
#Tank shot behavior:
%patch $490D $4808W


Shots don't smash on tiles

This patch alters things so that Tank shots simply vanish when they hit solid tiles instead of 'smashing' into a Zap/Zot. It should be noted that the patch comes in two parts. The first part stops shots auto-smashing when fired next to a wall. This is actually something that stops a shot being created at all under certain conditions. The second part stops a created shot from smashing on tiles.

Patch: Keen 1
#Shots don't auto-smah if enemy is near a wall
%patch $491F $5E $5D $C3
#Shots vanish on wall contact
%patch $4815 $C7 $06 $8220W $0000W $5E $5D $C3


Shot Speed

This alters the Tank's shot's speed. This is in fact set in The Tank's code rather than the shot spawned code

Patch: Keen 1
#Tank shot speeds:
%patch $1FE5 $015EW
#Right
%patch $1FEF $FEA2W
#Left


Shots Move Vertically

This patch allows shots to move up or down (But not both) instead of horizontally. However this means that all shots will move in the same direction at the same speed. (Most likely this will be useful for allowing Tank Robots to shoot upwards at things above them.) The blue value is the speed, upwards here.

Patch: Keen 1
#Thank shot moves up or down
%patch $490F $C7 $44 $22 $FFA6W $90


Sprite Collision

Tank Shots have a special collision, it causes them to be destroyed when they hit any sprite except for two special types. The first is the Tank Robot (Type 6) so that the shot doesn't get destroyed the second it's produced. The second is the destroyed shot's Zap/Zot for some unknown reason.

Patch: Keen 1
#Tank shot collision
%patch $4918 $4A00W
#'Safe' types:
%patch $4A0C $3D $06
#Tank shots NOT killed by Tanks
%patch $4A11 $3D $0E
#Tank shots not killed by Tank zap/zots


Shot Animation

By default the Tank shot has one animation that never changes.

Patch: When spawned
#Tank shot animation
%patch $491D $006DW


Shots Animate

This patch allows the Tank's shot to animate, at the cost of causing it to vanish when it hits walls instead of smashing. The first blue value is the start animation (Here the same as Keen's shot.) the second is the number of frames minus 1 and the third is the animation speed.

Patch: Keen 1
#Shots vanish on wall contact, animate
%patch $490D $4922W %patch $491F $5E $5D $C3 %patch $4922 $55 $8B $EC $56 $E8 $E344W $8B $F0 $0B $C0 $74 $09 $C7 $06 $8220W $0000W $5E $5D $C3 $C7 $06 $8248W $006CW $A1 $35 $51 $B1 $05 $D3 $E8 $25 $0001W $8B $16 $8248W $03 $D0 $89 $16 $8248W $5E $5D $C3


Misc

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 are stable!) 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 $E60BW %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