Patch:Enemy shooter (Keen 5)

From KeenWiki
Jump to navigation Jump to search

The enemy shooter in Keen 5 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 6, as well as the dart gun in Keen 4 and the watermelons in Keen Dreams.


Sprite Type

Dart guns are type 15, which is only used for them. The pink shots are type 4, which is used for enemy projectiles such as the Shikadi's pole blasts.

Keen 5

#Sprite types
%patch $10ED3 $0F #Gun
%patch $10F36 $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 tiles 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:
$1DFEW #Gun wait
$1E1CW #Gun shoot
$1E3AW #Pink shot 1
$1E58W #Pink shot 2
$1E76W #Pink shot 3
$1E94W #Pink shot 4
$1EB2W #Pink shot smash 1
$1ED0W #Pink shot smash 2

Keen 5

#Spawn gun
%patch $10F0D [$1DFEW] #Spawn enemy gun

#Gun loop
%patch $3215A [$1E1CW] #Gun wait
%patch $32178 [$1DFEW] #Gun Make shot

#Make shots
%patch $10F83 [$1E3AW]

#Shot loop
%patch $32196 [$1E58W]
%patch $321B4 [$1E76W]
%patch $321D2 [$1E94W]
%patch $321F0 [$1E3AW]

#Shots collide
%patch $10FBB [$1EB2W] #Bullet zap when enemy bullet collides with Keen
%patch $10FF8 [$1EB2W] #Bullet zap when enemy bullet collides with ground

#Destroyed shots
%patch $3220E [$1ED0W]
%patch $3222C [$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:
$090B1748RL #Projectile
$0F9215FDRL #Spawn pink shot

Keen 5

#Gun
%patch $3214E $00000000L  #Nothing (Wait)
%patch $3216C $0F9215FDRL #Spawn pink shot

#Shot
%patch $3218A $090B1748RL #Projectile
%patch $321A8 $090B1748RL #Projectile
%patch $321C6 $090B1748RL #Projectile
%patch $321E4 $090B1748RL #Projectile

#Shot smash
%patch $32202 $00000000L  #Nothing
%patch $32230 $00000000L  #Nothing


Shooter behavior code

This is the complete behavior for the enemy shooter. It is run once every time the shooter cycles. On the first line a type 1 sprite is produced. On line 2 the shot's type and clipping are set.

On line 4 the four types of shot are differentiated using a list at $F920 + $1681 = $10FA1. (Each of the four values in the list is also offset from $F920.) Each shot type sets a horizontal or vertical speed. All codes go to the second to last line where the shot's action is set and sound $1D is played.

Keen 5

#Enemy shooter behavior
%patch $10F1D $55 $8B $EC $56 $8B $76 $06 $B8 $0001W  $50 $9A $06B91DCDRL   
              $83 $C4 $02 $8B $1E $40 $9E $C7 $07 [$0004W]  $C7 $47 $02 [$0003W]
              $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 [$1681W]  $8B $1E $40 $9E $C7
              $47 $18 [$FFC0W]  $EB $1F $8B $1E $40 $9E $C7 $47 $16 [$0040W]  $EB
              $14 $8B $1E $40 $9E $C7 $47 $18 [$0040W]  $EB $09 $8B $1E $40 $9E
              $C7 $47 $16 [$FFC0W]  $B8 [$1E3AW]  $50 $FF $36 $40 $9E $9A $090B11C4RL
                      $83 $C4 $04 $B8 [$001DW]  $50 $9A $196E09EFRL     $83 $C4
              $02 $5E $5D $CB

#Directions shots are spawned:
%patch $10FA1 [$1638W] #Up (At $10F58)
              [$1643W] #Right (At $10F63)
              [$164EW] #Down (At $10F6E)
              [$1659W] #Left (At $10F79)


Speed

None of the sprites involved moves, which is unusual and different from how the otherwise similar shot of the player moves. The speed seems to be set when the shot is created, possibly to allow the shot to use the same projectile behavior as other enemy projectiles.It is still possible to add a constant speed to the shots however.

Keen 5

#Gun
%patch $3214A [$0000W $0000W] #Gun waiting
%patch $32168 [$0000W $0000W] #gun shooting

#Pink shot
%patch $32186 [$0000W $0000W]
%patch $321A4 [$0000W $0000W]
%patch $321C2 [$0000W $0000W]
%patch $321E0 [$0000W $0000W]

#Pink shot smash
%patch $321FE [$0000W $0000W]
%patch $3221C [$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 5

#Directions shots are spawned:
%patch $10FA1 [$1638W] #Up (At $10F58)
              [$1643W] #Right (At $10F63)
              [$164EW] #Down (At $10F6E)
              [$1659W] #Left (At $10F79)


Horizontal shots move diagonally

This patch changes things so that the horizontal shots also move upwards, that is, diagonally. This is done by changing things so that the horizontal shots also use the vertical upwards code, giving them an additional vertical speed. As such changing the vertical speed of shots will change the diagonal speed too. Note that this patch is incompatible with the shot speed patches on this page as it rearranges code.

Keen 5

#Shots move diagonally upwards
%patch $10F58 $8B $1E $40 $9E $C7 $47 $16 [$FFC0W] $EB $16 #Left move upwards
              $8B $1E $40 $9E $C7 $47 $18 [$0040W] $EB $14
              $8B $1E $40 $9E $C7 $47 $16 [$0040W] $90 $90 #Right moves upwards
              $8B $1E $40 $9E $C7 $47 $18 [$FFC0W]

#Directions shots are spawned:
%patch $10FA1 [$1659W] #Up (At $10F79)
              [$164EW] #Right (At $10F6E)
              [$1643W] #Down (At $10F63)
              [$1638W] #Left (At $10F58)


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.

Keen 5 collision values

#Shooter
%patch $32152 $00000000L  #Nothing
%patch $32170 $00000000L  #Nothing

#Pink shot
%patch $3218E $0F921689RL #Pink shot
%patch $321AC $0F921689RL #Pink shot
%patch $321CA $0F921689RL #Pink shot
%patch $321E8 $0F921689RL #Pink shot

#Pink shot smash
%patch $32206 $00000000L  #Nothing
%patch $32224 $00000000L  #Nothing


Collision code

This is the complete collision code for the pink shot. On the first line it checks for Keen's sprite type. If found it does two things; firstly it kills Keen ($9A $0AAF1517RL) and secondly it transforms into a smashed shot.

Keen 5 collision code

#Pink shot sprite collision
%patch $10FA9 $55 $8B $EC $56 $8B $76 $08 $83 $3C [$02] {$75} $14 $9A $0AAF1517RL
                  $B8 [$1EB2W]  $50 $FF $76 $06 $9A $090B1242RL    $83 $C4 $04
              $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 5

#Cache
%patch $31A2A [$00ECW] #Shooter cache start
%patch $31A7E [$00F1W] #Cache end

#Gun
%patch $3213E $0000W $0000W #No animation
%patch $32148 $0078W        #Pause between shots
%patch $3215C $0000W $0000W #No animation
%patch $32166 $0001W        #Shot time

#Pink shot
%patch $3217A $00ECW $00ECW
%patch $32184 $0008W        #Animation speed
%patch $32198 $00EDW $00EDW
%patch $321A2 $0008W        #Animation speed
%patch $321B6 $00EEW $00EEW
%patch $321C0 $0008W        #Animation speed
%patch $321D4 $00EFW $00EFW
%patch $321DE $0008W        #Animation speed

#Pink shot smash
%patch $321F2 $00F0W $00F0W
%patch $321FC $000AW        #Animation speed
%patch $32210 $00F1W $00F1W
%patch $3221A $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.

Keen 5

#Sounds
%patch $10F93 $1D #Pink gun shooting
%patch $10FEC $1E #Pink shot destroyed

#Don't make sounds:
%patch $10F92 $EB $0A #Pink gun shooting
%patch $10FEB $EB $0A #Pink shot destroyed


Sprite-tile interaction

Shooters and smashed shots use the 'solid' collision, that is they are blocked by solid tiles. Shots use their own special interaction; they turn into smashing shots when they hit a tile that blocks in any direction.

Keen 5

#Shooter
%patch $32156 $090B17B5RL #Solid
%patch $32174 $090B17B5RL #Solid

#Shots
%patch $32192 $0F9216ACRL #Pink shot
%patch $321B0 $0F9216ACRL #Pink shot
%patch $321CE $0F9216ACRL #Pink shot
%patch $321EC $0F9216ACRL #Pink shot

#Shot smashes
%patch $3220A $090B17B5RL #Solid
%patch $32228 $090B17B5RL #Solid


Interaction code

This is the complete code for the pink shot tile interaction. There are four checks made on the first two lines. These check for walls, floors and ceilings and if detected then line three's code is run. This plays sound $1E and changes the shot's action to smashed.

Keen 5

#Pink shot tile collision
%patch $10FCC $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 $196E09EFRL     $83 $C4 $02 $B8 [$1EB2W]  $50 $56
              $9A $090B1242RL     $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 $174E163ERL
                      $83 $C4 $0C $5E $5D $CB


Action type

While the shooter and smashed shots use type 0, shots themselves use type 3, allowing them to respond instantly to tiles and Keen. Due to the way their motion is set, their motion is still smooth.

Keen 5

#Gun
%patch $32142 [$0000W]
%patch $32160 [$0000W]

#Pink shot
%patch $3217E [$0003W]
%patch $3219C [$0003W]
%patch $321BA [$0003W]
%patch $321D8 [$0003W]

#Shot smash
%patch $321F6 [$0000W]
%patch $32214 [$0000W]


Deprotect and stick to ground

The shooter and shots do not use either of these values since they have no interaction with sloped tiles at all.

Keen 5

#Gun
%patch $32144 [$0000W] [$0000W]
%patch $32162 [$0000W] [$0000W]

#Pink shot
%patch $32180 [$0000W] [$0000W]
%patch $3219E [$0000W] [$0000W]
%patch $321BC [$0000W] [$0000W]
%patch $321DA [$0000W] [$0000W]

#Pink shot smash
%patch $321F8 [$0000W] [$0000W]
%patch $32216 [$0000W] [$0000W]


Sprite spawn code

Only partial spawn code is available for the enemy shooters. (Referred to here as 'lasers' for simplicity.) Note that there are for kinds; up, down, left and right and that each has three types, one for each difficulty. Though grouped in-game by difficulty, each type has its own initiation code. Notice each type set the same cache in $C7 $06 $C27DW $0001W. Notice also that each initiation code points to the same spawning code. (Though passing a different value to it.)

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, $C7 $47 $06 $xxxxW sets the clipping, $C7 $07 $xxxxW sets the sprite type, $C7 $20 $xxxxW sets the foreground value., Finally $D3 $E0 $05 $xxxx is how far down (Or more usually up) the sprite is spawned from where it is placed. This is necessary for sprites that walk on the ground as they can only be placed in the level at multiples of 16 pixels high while their actual height can be anything. Notice how many of these features the shooter spawn lacks.

Keen 5 Location of initiation code

%patch $F51E [$0418W] #Easy laser up (At $F168)
%patch $F520 [$0442W] #Easy laser right (At $F192)
%patch $F522 [$046DW] #Easy laser left (At $F1BD)
%patch $F524 [$0498W] #Easy laser down (At $F1E8)

%patch $F526 [$040EW] #Normal laser up (At $F15E)
%patch $F528 [$0438W] #Normal laser right (At $F188)
%patch $F52A [$0463W] #Normal laser down (At $F1B3)
%patch $F52C [$048EW] #Normal laser left (At $F1DE)

%patch $F52E [$0404W] #Hard laser up (At $F154)
%patch $F530 [$042EW] #Hard laser right (At $F17E)
%patch $F532 [$0459W] #Hard laser down (At $F1A9)
%patch $F534 [$0484W] #Hard laser left (At $F1D4)

Keen 5 Enemy shooter Initiation code

#Laser up
%patch $F154 $83 $3E [$6F6CW]  {$03 $7D} $03 $E9 $0249W $83 $3E [$6F6CW]  {$02 $7D}
                 $03 $E9 $023FW  $33 $C0 $50 $57 $56 $9A {$0F921597RL}    $83 $C4
             $06 $C7 $06 $C27DW  $0001W  $E9 $0229W

#Laser right
%patch $F17E $83 $3E [$6F6CW]  {$03 $7D} $03 $E9 $021FW  $83 $3E [$6F6CW]  {$02 $7D}
             $03 $E9 $0215W  $B8 [$0001W]  $50 $57 $56 $9A {$0F921597RL}     $83 $C4
             $06 $C7 $06 $C27DW  $0001W  $E9 $01FEW

#Laser down
%patch $F1A9 $83 $3E [$6F6CW]  {$03 $7D} $03 $E9 $01F4W  $83 $3E [$6F6CW]  {$02 $7D}
             $03 $E9 $01EAW  $B8 [$0002W]  $50 $57 $56 $9A {$0F921597RL}     $83 $C4
             $06 $C7 $06 $C27DW  $0001W  $E9 $01D3W

#Laser left
%patch $F1D4 $83 $3E [$6F6CW]  {$03 $7D} $03 $E9 $01C9W  $83 $3E [$6F6CW]  {$02 $7D}
             $03 $E9 $01BFW  $B8 [$0003W]  $50 $57 $56 $9A {$0F921597RL}     $83 $C4
             $06 $C7 $06 $C27DW  $0001W  $E9 $01A8W

Keen 5 Enemy shooter Spawn code

#Enemy shooter spawn code
%patch $10EB7 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $33 $C0 $50 $9A $06B91DCDRL
                          $83 $C4 $02 $8B $1E $40 $9E $C7 $07 [$000FW]  $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 [$1DFEW]  $50 $53 $9A $090B11C4RL     $83
              $C4 $04 $5F $5E $5D $CB