Patch:Enemy shooter (Keen 6)
The enemy shooter in Keen 6 is an invisible sprite that regularly spawns new sprites, in its case pink shots. There are four different varieties of shooter (Though they are not different sprites in themselves.) that shoot in different directions. Similar sprites occur in Keen 3 and Keen 5, as well as the dart gun in Keen 4 and the watermelons in Keen Dreams.
Sprite Type
Dart guns are type 18, which is only used for them. The pink shots are type 4, which is used for enemy projectiles such as the Babobba's cinders.
Keen 6
#Sprite types
%patch $1138D $12 #Gun
%patch $113F0 $04 #Gun's pink shot
Sprite Actions
There are three separate sets of actions relating to the shooter. The first is the invisible shooter, the next is the pink shot and the third is the shot hitting things and dissipating.
The way the gun works is simple, it loops between shooting and not-shooting, making one new sprite each time. The shots when produced loop four actions to move around and will smash when they hit either Keen or solid ground. The smashed shots have two actions before vanishing.
Actions: $26F6W #Gun wait $2714W #Gun shoot $2732W #Pink shot 1 $2750W #Pink shot 2 $276EW #Pink shot 3 $278CW #Pink shot 4 $27AAW #Pink shot smash 1 $27C8W #Pink shot smash 2
Keen 6
#Spawn gun
%patch $113C7 [$26F6W] #Spawn enemy gun
#Gun loop
%patch $33442 [$2714W] #Gun wait
%patch $33460 [$26F6W] #Gun Make shot
#Make shots
%patch $1143D [$2732W]
#Shot loop
%patch $3347E [$2750W]
%patch $3349C [$276EW]
%patch $334BA [$278CW]
%patch $334D8 [$2732W]
#Shots collide
%patch $11475 [$27AAW] #Bullet zap when enemy bullet collides with Keen
%patch $114B2 [$27AAW] #Bullet zap when enemy bullet collides with ground
#Destroyed shots
%patch $334F6 [$27C8W]
%patch $33514 [$0000W]
Sprite Behavior
There are two behaviors, the shooter uses a 'produce shot' behavior when it is shooting. This produces the pink shots and gives them their direction depending on what shooter produced them. The pink shot uses the 'Projectile' behavior, which means it simply moves in its current direction. Smashed shots and waiting guns have no behavior.
Behaviors: $08F4179DRL #Projectile $10CC0717RL #Spawn pink shot
Keen 6
#Gun
%patch $33436 $00000000L #Nothing (Wait)
%patch $33454 $10CC0717RL #Spawn pink shot
#Pink shot
%patch $33472 $08F4179DRL
%patch $33490 $08F4179DRL
%patch $334AE $08F4179DRL
%patch $334CC $08F4179DRL
#Shot smash
%patch $334EA $00000000L
%patch $33508 $00000000L
Spawn shot behavior
This is the complete pink shot spawning behavior code. On the second line the shot's type is set (4, or 'enemy projectile') Next the sprite's activity is set. After this the directions are set by reference to a list of 4 items ($03 + 1) located at $1145B ($079BW). This sets one of four speeds for each shot direction. After this is the sprite's action (Line 7.) After all this sound $1D is played.
Keen 6
#Spawn pink shot behavior code
%patch $113D7 $55 $8B $EC $56 $8B $76 $06 $B8 $0001W $50 $9A $069A1E25RL
$83 $C4 $02 $8B $1E $66 $A9 $C7 $07 [$0004W] $C7 $47 $02 [$0001W]
$8B $44 $0A $89 $47 $0A $8B $44 $0C $89 $47 $0C $8B $5C $3E $83
$FB [$03] $77 $31 $D1 $E3 $2E $FF $A7 [$079BW] $8B $1E $66 $A9 $C7
$47 $18 [$FFC0W] $EB $1F $8B $1E $66 $A9 $C7 $47 $16 [$0040W] $EB
$14 $8B $1E $66 $A9 $C7 $47 $18 [$0040W] $EB $09 $8B $1E $66 $A9
$C7 $47 $16 [$FFC0W] $B8 [$2732W] $50 $FF $36 $66 $A9 $9A $08F41219RL
$83 $C4 $04 $B8 [$001DW] $50 $9A $183B09F1RL $83 $C4
$02 $5E $5D $CB
#Directions shots are spawned:
%patch $1145B $0752W #Up (At $11412)
%patch $1145D $075DW #Right (At $1141D)
%patch $1145F $0768W #Down (At $11428)
%patch $11461 $0773W #Left (At $11433
Shots spawn as removable
Normally when the pink shots spawn they use the sprite activity value of 1, which causes the shots to stop when offscreen. Since the shooters never stop spawning shots, this leads to the possibility of the object array being overloaded by shots, which can cause new objects to either not spawn or crash the game. This patch changes the sprite activity value to 3 so that the shots are removed when offscreen, similar to how the pink shots in Keen 5 are spawned.
Keen 6
#Shots spawn as removable
%patch $113F5 $0003W
Speed
Unlike most other enemy shots the pink shots do not utilize animation motion, instead using speeds set when the shots are created. In this case $16 is a horizontal speed and $18 a vertical one. Only one speed per direction is set by default.
Keen 6
#Pink shot's speeds
%patch $11418 $18 [$FFC0W] #Up
%patch $11423 $16 [$0040W] #Right
%patch $1142E $18 [$0040W] #Down
%patch $11439 $16 [$FFC0W] #Left
Animation motion
#Gun
%patch $33432 [$0000W $0000W] #Gun waiting
%patch $33450 [$0000W $0000W] #Gun shooting
#Pink shot
%patch $3346E [$0000W $0000W]
%patch $3348C [$0000W $0000W]
%patch $334AA [$0000W $0000W]
%patch $334C8 [$0000W $0000W]
#Pink shot smash
%patch $334E6 [$0000W $0000W]
%patch $33504 [$0000W $0000W]
Shot spawn directions
The directions that the shots move are determined by pointers to their code. As a result there is a four item list that controls the basic directions of the four kinds of shot. All that can be done at present is to make two types of shot or more move in the same direction, so this is not a very useful patch.
Keen 6
#Number of shot types
%patch $11408 $03
#List location
%patch $11410 $079BW
#Directions shots are spawned:
%patch $1145B $0752W #Up (At $11412)
%patch $1145D $075DW #Right (At $1141D)
%patch $1145F $0768W #Down (At $11428)
%patch $11461 $0773W #Left (At $11433
Sprite Collision
The gun and shot collisions are quite simple. The gun has no collision, it does not interact with other sprites. (Thus it cannot be destroyed, or hurt Keen.) The shots themselves use a special pink shot collision, killing Keen if they touch him and transforming into a smashed shot.
Collision values
These are the values used by each frame in the game.
Keen 6 collision values
#Shooter
%patch $3343A $00000000L #Nothing
%patch $33458 $00000000L #Nothing
#Pink shot
%patch $33476 $10CC07A3RL #Pink shot
%patch $33494 $10CC07A3RL #Pink shot
%patch $334B2 $10CC07A3RL #Pink shot
%patch $334D0 $10CC07A3RL #Pink shot
#Pink shot smash
%patch $334EE $00000000L #Nothing
%patch $3350C $00000000L #Nothing
Collision code
The Pink Shot is the only Enemy Gun related sprite with a collision by default. It responds to Keen's sprite type, transforming into a smashed shot. Notice it doesn't make a sound when it smashes in this way.
Keen 6 collision code
#Pink shot sprite collision code
%patch $11463 $55 $8B $EC $56 $8B $76 $08 $83 $3C [$02] {$75} $14 $9A $0AA213CARL
$B8 [$27AAW] $50 $FF $76 $06 $9A $08F41297RL $83 $C4 $04
$5E $5D $CB
Pink shots can be destroyed by Keen's shot
This patch alters the Pink Shot's collision code so that Keen can destroy a pink shot with his own shot. Destroying a Pink Shot in this was will not kill Keen, but the shot is still lethal.
As a side effect the Orbatrix's collision cannot be messed with since this patch makes the two collisions share code.
Pink shots can be destroyed by Keen's shots
#Pink shots can be destroyed by Keen's shots
%patch $11463 $55 $8B $EC $56 $8B $76 $08 $83 $3C [$02] {$75} $07 $9A $0AA213CARL
$EB $05 $83 $3C [$03] {$75} $07 $B8 [$27AAW] $50 $E9 $013CW $5E $5D $CB
Animations
The shooter animations are simple, shots have four animations plus two smashing animations and the shooter itself is invisible. Note that the shooter animation speed is also the frequency it produces shots (It controls the firing rate.) Shots use the same animations no matter what direction they move.
Keen 6
#Cache
%patch $32456 [$00B0W] #Shooter cache start
%patch $324A6 [$00B5W] #Cache end
#Gun
%patch $33426 $0000W $0000W #No animation
%patch $33430 $0078W #Pause between shots
%patch $33444 $0000W $0000W #No animation
%patch $3344E $0001W #Shot time
#Pink shot
%patch $33462 $00B0W $00B0W
%patch $3346C $0008W #Animation speed
%patch $33480 $00B1W $00B1W
%patch $3348A $0008W #Animation speed
%patch $3349E $00B2W $00B2W
%patch $334A8 $0008W #Animation speed
%patch $334BC $00B3W $00B3W
%patch $334C6 $0008W #Animation speed
#Pink shot smash
%patch $334DA $00B4W $00B4W
%patch $334E4 $000AW #Animation speed
%patch $334F8 $00B5W $00B5W
%patch $33502 $000AW #Animation speed
Sounds
There are two sounds, one for when the shooters shoot and one for when the pink shot is destroyed. Each can be blocked. Interestingly the Pink Shot doesn't make a noise when it smashes against Keen.
Keen 6
#Sounds
%patch $1144D $1D #Enemy gun shooting
%patch $114A6 $1E #Pink shot destroyed
#Don't make sounds:
%patch $1144C $EB $0A #Enemy gun shooting
%patch $114A5 $EB $0A #Pink shot destroyed
Sprite-tile interaction
Only the pink shots themselves have a unique til collision, this makes them smash whenever they hit a tile blocking their path. The gun and smashed shots use a general code that simply draws the sprite.
Keen 6
#Shooter
%patch $3343E $08F4180ARL
%patch $3345C $08F4180ARL
#Pink shot
%patch $3347A $10CC07C6RL
%patch $33498 $10CC07C6RL
%patch $334B6 $10CC07C6RL
%patch $334D4 $10CC07C6RL
#Pink shot smash
%patch $334F2 $08F4180ARL
%patch $33510 $08F4180ARL
Tile interaction code
This is the complete code for the pink shot tile interaction code. On the first two lines right walls, floors, left walls and ceilings are checked for in that order. If any of these are blocking the shot's path then the next two lines of code are run. These play sound $1E and change the sprite's type to that of the smashed shot. The last three or so lines of code draw the pink shot on the screen.
Keen 6
#Pink shot tile interaction code
%patch $11486 $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} $19 $B8
[$001EW] $50 $9A $183B09F1RL $83 $C4 $02 $B8 [$27AAW] $50 $56
$9A $08F41297RL $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
Action type
The pink shot needs to move smoothly through the air and animate.As such its actions are type 3. All other actions are more basic and thus type 0.
Sprite action types
#Shooter
%patch $3342A [$0000W]
%patch $33448 [$0000W]
#Pink shot
%patch $33466 [$0003W]
%patch $33484 [$0003W]
%patch $334A2 [$0003W]
%patch $334C0 [$0003W]
#Pink shot smash
%patch $334DE [$0000W]
%patch $334FC [$0000W]
Deprotect and stick to ground
The shooter has no need for either of these variables and so has a value of 0 for both in all of its actions. The exception is its 'produce a shot' action, which is deprotected to ensure that it only appears for the single game tic it is supposed to.
Sprite deprotect, stick
#Shooter
%patch $3342C [$0000W $0000W]
%patch $3344A [$0001W $0000W]
#Pink shot
%patch $33468 [$0000W $0000W]
%patch $33486 [$0000W $0000W]
%patch $334A4 [$0000W $0000W]
%patch $334C2 [$0000W $0000W]
#Pink shot smash
%patch $334E0 [$0000W $0000W]
%patch $334FE [$0000W $0000W]
Sprite spawn code
There are four kinds of enemy shooters, (Referred to here as 'lasers' for simplicity,) up, down, left and right. Each type uses the same initiation code and to thus set the same cache in $C7 $06 $CD43W $0001W. This passes on the 'variety' to the spawn code, which in turn passes it to the laser itself.
In the spawn code the last blue highlighted value is the sprite action the sprite uses as it proceeds to act in-level. $C7 $02 $xxxxW sets the sprite activity and $C7 $07 $xxxxW sets the sprite type.
Keen 6 Enemy shooter Initiation code
#Location of initiation code
%patch $E9BA [$02EAW] #Laser up (At $E70A)
%patch $E9BC [$02EAW] #Laser right (At $E70A)
%patch $E9BE [$02EAW] #Laser down (At $E70A)
%patch $E9C0 [$02EAW] #Laser left (At $E70A)
#Enemy gun initiation code
%patch $E70A $8B $46 $FA $05 [$FFCBW] $50 $57 $56 $9A $10CC06B1RL $83 $C4
$06 $C7 $06 $CD43W $0001W $E9 $01A3W
#Enemy shooter spawn code
%patch $11371 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $33 $C0 $50 $9A
$069A1E25RL $83 $C4 $02 $8B $1E $66 $A9 $C7 $07 [$0012W] $C7 $47
$02 [$0001W] $8B $C6 $89 $47 $2C $89 $47 $30 $8B $C7 $89 $47 $32
$89 $47 $2E $8B $C6 $B1 $08 $D3 $E0 $89 $47 $26 $89 $47 $22 $89
$47 $0A $8B $C7 $D3 $E0 $89 $47 $28 $89 $47 $24 $89 $47 $0C $8B
$46 $0A $89 $47 $3E $B8 [$26F6W] $50 $53 $9A $08F41219RL $83
$C4 $04 $5F $5E $5D $CB