Patch:Miragia

From KeenWiki
Jump to navigation Jump to search

Miragia is a level in Keen 4, it is also however a sprite in the game, used by default to make the Miragia level entrance on the map appear and disappear. (It stays disappeared when Keen is close to it.) This page deals with patches that affect this sprite and thus how the Miragia entrance works.

Notice that the Miragia sprite can be used multiple times in a level on levels other than the map, like any other sprite.

Map patches can be found at Patch:Map (Keen 4). It is possible to change the Miragia sprite into a teleporter. This patch can be found on the Keen 4 map page.


How Miragia sprites work

The Miragia sprite can be divided into two main parts, the behaviors and the sprites.

The Miragia behaviors are simple tile replacements; the sprite that uses it stands still and overwrites one part of the level with a block of tiles from another place in the level. There are eight different Miragia behaviors, each copying tiles from a different place in the level. The first Miragia behavior also checks for Keen's presence, if he is there it does nothing. (This is how Miragia stays vanished when Keen is too close to it.)

Both the foreground and background layers of the level are overwritten. The sprite layer is also overwritten, in a special way, any values that are proper sprites (Enemies, items, Keen) are NOT copied, only switch values, level entrance values, etc. Thus Miragia can copy a door correctly, but not a Lick.

The replacement happens instantly when the behavior is called, if Keen alters the tiles, the alteration will remain until the next replacement is called. (They do not 'instantly fix' themselves.) Also when a level begins no tiles are placed. (This can be used to make a quick dash challenge, if Keen doesn't get to\past the tiles Miragia will overwrite them and they will never be the same again.)

Using sprite patches you can affect how many Miragia behaviors are used and how fast, it also allows other enemies to use tile replacements. If your enemy moves this can become very interesting. (A lick that deposits deadly spikes wherever it lands for example.)


Miragia is a teleporter

As noted above it is possible to turn the Miragia sprite into a teleporter. Since this is mainly meant for the map level, (though it can be adapted for other levels.), the patch is located on the Keen 4 map page.


Miragia sprites

These are patches relating to Miragia as a sprite.


Sprite Type

Miragia is type 1, used when sprite type is not important, as it isn't in this case.

Keen 4

#Blue bird sprite type
%patch $FA94  $01 #Miragia placed in level


Sprite Actions

There are eight Miragia sprite actions, each using a different Miragia behavior. By default Miragia sprites just sit in place, invisible and indestructible changing tiles in an endless loop. By changing the size of this loop it is possible to change the number of 'frames' the Miragia 'animation' consists of.

Actions:
$1DFCW #Miragia 1 (This one looks for Keen)
$1E1AW #Miragia 2
$1E38W #Miragia 3
$1E56W #Miragia 4
$1E74W #Miragia 5
$1E92W #Miragia 6
$1EB0W #Miragia 7
$1ECEW #Miragia 8

Keen 4

#Spawn Miragia
%patch $FAAA  {$1DFCW} #Miragia 1

#Miragia in-level
%patch $30C88 {$1E1AW} #Miragia 2
%patch $30CA6 {$1E38W} #Miragia 3
%patch $30CC4 {$1E56W} #Miragia 4
%patch $30CE2 {$1E74W} #Miragia 5
%patch $30D00 {$1E92W} #Miragia 6
%patch $30D1E {$1EB0W} #Miragia 7
%patch $30D3C {$1ECEW} #Miragia 8
%patch $30D5A {$1DFCW} #Miragia 1 (Loop back to 2)


Sprite Behavior

As mentioned above, each Miragia action uses a different tile-replace behavior.

Behaviors:
$0FA8002ERL #Miragia 1
$0FA8008BRL #Miragia 2
$0FA800B3RL #Miragia 3
$0FA800DBRL #Miragia 4
$0FA80103RL #Miragia 5
$0FA8012BRL #Miragia 6
$0FA80153RL #Miragia 7
$0FA8017BRL #Miragia 8

Keen 4

#Miragia behavior
%patch $30C7C {$0FA8002ERL} #Miragia animation 1
%patch $30C9A {$0FA8008BRL} #Miragia animation 2
%patch $30CB8 {$0FA800B3RL} #Miragia animation 3
%patch $30CD6 {$0FA800DBRL} #Miragia animation 4
%patch $30CF4 {$0FA80103RL} #Miragia animation 5
%patch $30D12 {$0FA8012BRL} #Miragia animation 6
%patch $30D30 {$0FA80153RL} #Miragia animation 7
%patch $30D4E {$0FA8017BRL} #Miragia animation 8


Location and size of Miragia blocks

As mentioned above there are eight Miragia behaviors, each copying a block of tiles from a certain location. As such four variables are patchable, the size of the block and its location. The 'timing' or frequency of replacements is a sprite patch as seen below.

The patches are listed for each behavior in order. By default several of the behaviors do the same thing, but this need not be the case, they are all independent.

Keen 4 Miragia block sizes and locations

#Miragia 1
%patch $FAEA [$0004W] #Copy a block 4 by...
%patch $FAEE [$0006W] #6 tiles from...
%patch $FAF8 [$003CW] #60,...
%patch $FAFC [$0008W] #8 in level

#Miragia 2
%patch $FB13 [$0004W] #Copy a block 4 by...
%patch $FB17 [$0006W] #6 tiles from...
%patch $FB21 [$003CW] #60,...
%patch $FB25 [$000EW] #14 in level

#Miragia 3
%patch $FB3B [$0004W] #Copy a block 4 by...
%patch $FB3F [$0006W] #6 tiles from...
%patch $FB49 [$003CW] #60,...
%patch $FB4D [$0014W] #20 in level

#Miragia 4
%patch $FB63 [$0004W] #Copy a block 4 by...
%patch $FB67 [$0006W] #6 tiles from...
%patch $FB71 [$003CW] #60,...
%patch $FB75 [$001AW] #26 in level

#Miragia 5
%patch $FB8B [$0004W] #Copy a block 4 by...
%patch $FB8F [$0006W] #6 tiles from...
%patch $FB99 [$003CW] #60,...
%patch $FB9D [$0014W] #14 in level

#Miragia 6
%patch $FBB3 [$0004W] #Copy a block 4 by...
%patch $FBB7 [$0006W] #6 tiles from...
%patch $FBC1 [$003CW] #60,...
%patch $FBC5 [$000EW] #14 in level

#Miragia 7
%patch $FBDB [$0004W] #Copy a block 4 by...
%patch $FBDF [$0006W] #6 tiles from...
%patch $FBE9 [$003CW] #60,...
%patch $FBED [$0008W] #8 in level

#Miragia 8
%patch $FC03 [$0004W] #Copy a block 4 by...
%patch $FC07 [$0006W] #6 tiles from...
%patch $FC11 [$003CW] #60,...
%patch $FC15 [$0002W] #2 in level


Complete block code

This is the complete code for the Miragia behaviors. It will be noticed that there is very little difference between each block behavior (and that in fact several behaviors are completely identical.)

Each behavior has four variables set (in blue); the height and width of the block to replace and the horizontal and vertical location in the level. The two values in brown position the block relative to the sprite; changing them to both be the same (Both $0A or $0C) will subtly change the location of the block, allowing the Miragia sprite to change more than one piece of the level.

Notice the first behavior is more complex; it looks for Keen. There are four checks for Keen's location relative to the Miragia sprite (in brown). The first and third detect whether Keen is above or left of Miragia while the second and fourth checks check whether Keen is within 5 tiles horizontally or 4 tiles vertically of Miragia. (That is inside Miragia's tile-changing box.)

Keen 4 Miragia block codes

#Miragia cycle 1- Check for Keen
%patch $FAAE  $55 $8B $EC $56 $57 $8B $7E $06 $8B $1E $A7D6W  $8B $47 $30 $3B
              $45 $0A {$72} $27 $8B $45 $0A $05 [$0005W]  $39 $47 $2C {$77} $1C $8B
              $47 $2E $3B $45 $0C {$72} $14 $8B $45 $0C $05 [$0004W]  $39 $47 $32
              {$77} $09 $C7 $45 $1C [$1ECEW]  $5F $5E $5D $CB

#If no Keen, block 1 is 4x6 at 3C,8
                                                          $B8 [$0004W]  $50 $B8
              [$0006W]  $50 $FF $75 {$0C} $FF $75 {$0A} $B8 [$003CW]  $50 $B8 [$0008W]
              $50 $9A $16540D78RL     $83 $C4 $0C $5F $5E $5D $CB

#Block 2 is 4x6 at 3C,E
%patch $FB0B  $55 $8B $EC $56 $8B $76 $06 $B8 [$0004W]  $50 $B8 [$0006W]  $50 $FF
              $74 {$0C} $FF $74 {$0A} $B8 [$003CW]  $50 $B8 [$000EW]  $50 $9A $16540D78RL
                      $83 $C4 $0C $5E $5D $CB

#Block 3 is 4x6 at 3C,14
%patch $FB33  $55 $8B $EC $56 $8B $76 $06 $B8 [$0004W]  $50 $B8 [$0006W]  $50 $FF
              $74 {$0C} $FF $74 {$0A} $B8 [$003CW]  $50 $B8 [$0014W]  $50 $9A $16540D78RL
                      $83 $C4 $0C $5E $5D $CB

#Block 4 is 4x6 at 3C,1A
%patch $FB5B  $55 $8B $EC $56 $8B $76 $06 $B8 [$0004W]  $50 $B8 [$0006W]  $50 $FF
              $74 {$0C} $FF $74 {$0A} $B8 [$003CW]  $50 $B8 [$001AW]  $50 $9A $16540D78RL
                      $83 $C4 $0C $5E $5D $CB

#Block 5 is 4x6 at 3C,14
%patch $FB83  $55 $8B $EC $56 $8B $76 $06 $B8 [$0004W]  $50 $B8 [$0006W]  $50 $FF
              $74 {$0C} $FF $74 {$0A} $B8 [$003CW]  $50 $B8 [$0014W]  $50 $9A $16540D78RL
                      $83 $C4 $0C $5E $5D $CB

#Block 6 is 4x6 at 3C,E
%patch $FBAB  $55 $8B $EC $56 $8B $76 $06 $B8 [$0004W]  $50 $B8 [$0006W]  $50 $FF
              $74 {$0C} $FF $74 {$0A} $B8 [$003CW]  $50 $B8 [$000EW]  $50 $9A $16540D78RL
                      $83 $C4 $0C $5E $5D $CB

#Block 7 is 4x6 at 3C,8
%patch $FBD3  $55 $8B $EC $56 $8B $76 $06 $B8 [$0004W]  $50 $B8 [$0006W]  $50 $FF
              $74 {$0C} $FF $74 {$0A} $B8 [$003CW]  $50 $B8 [$0008W]  $50 $9A $16540D78RL
                      $83 $C4 $0C $5E $5D $CB

#Block 8 is 4x6 at 3C,2
%patch $FBFB  $55 $8B $EC $56 $8B $76 $06 $B8 [$0004W]  $50 $B8 [$0006W]  $50 $FF
              $74 {$0C} $FF $74 {$0A} $B8 [$003CW]  $50 $B8 [$0002W]  $50 $9A $16540D78RL
                      $83 $C4 $0C $5E $5D $CB


Miragia cycles when Keen has an item

This patch makes Miragia check not Keen's position, but whether he has a certain item (In this case it checks if he has 1 or more blue gems.) Miragia will not appear if Keen does not ave the item, but will cycle continuously if he does. Check Patch:Jump conditions and Patch:Game stats may be helpful in using this patch.

Keen 4 Miragia cycles when Keen has an item

#Miragia cycle 1- Check for blue gem = 1
%patch $FAAE  $55 $8B $EC $56 $57 $8B $7E $06 $8B $1E $A7D6W  $90 $83 $3E {$7A62W}
                  [$00] {$77} $09 $C7 $45 $1C $1ECEW  $5F $5E $5D $CB

#If no Keen, block 1 is 4x6 at 3C,8
                                                          $B8 [$0004W]  $50 $B8
              [$0006W]  $50 $FF $75 $0C $FF $75 $0A $B8 [$003CW]  $50 $B8 [$0008W]
              $50 $9A $16540D78RL     $83 $C4 $0C $5F $5E $5D $CB


Speed and Jump Height

Miragia sprites do not move and it's no certain they can while using tile replace behavior.

Keen 4

#Miragia speeds
%patch $30C78 [$0000W] [$0000W] #Speed 1
%patch $30C96 [$0000W] [$0000W] #Speed 2
%patch $30CB4 [$0000W] [$0000W] #Speed 3
%patch $30CD2 [$0000W] [$0000W] #Speed 4
%patch $30CF0 [$0000W] [$0000W] #Speed 5
%patch $30D0E [$0000W] [$0000W] #Speed 6
%patch $30D2C [$0000W] [$0000W] #Speed 7
%patch $30D4A [$0000W] [$0000W] #Speed 8


Sprite Collision

Miragia sprites have no collision, this makes them indestructible. As they have no sprite the collision doesn't matter in any case. Making Miragia sprites destructible could lead to interesting effects.

Keen 4 collision values

%patch $30C80 $00000000L #No collision
%patch $30C9E $00000000L #No collision
%patch $30CBC $00000000L #No collision
%patch $30CDA $00000000L #No collision
%patch $30CF8 $00000000L #No collision
%patch $30D16 $00000000L #No collision
%patch $30D34 $00000000L #No collision
%patch $30D52 $00000000L #No collision


Animations and tile replacement speed

Miragia sprites also have no animations, they are invisible. The animation speed affects the tile replacement speed, since this happens once per animation. There are two interesting values, the time Miragia spends 'present' and 'absent' (In reality these are just extra long pauses set up.)

Keen 4

#No sprites used
%patch $30C6C $0000W $0000W
%patch $30C76 $012CW        #Miragia absent time
%patch $30C8A $0000W $0000W
%patch $30C94 $001EW        #Animation speed
%patch $30CA8 $0000W $0000W
%patch $30CB2 $001EW        #Animation speed
%patch $30CC6 $0000W $0000W
%patch $30CD0 $001EW        #Animation speed
%patch $30CE4 $0000W $0000W
%patch $30CEE $012CW        #Miragia fully present time
%patch $30D02 $0000W $0000W
%patch $30D0C $001EW        #Animation speed
%patch $30D20 $0000W $0000W
%patch $30D2A $001EW        #Animation speed
%patch $30D3E $0000W $0000W
%patch $30D48 $001EW        #Animation speed


Clipping and foreground

Miragia cannot have its clipping or foreground values patched because it uses default ones and does not require them in any case.


Sprite-tile interaction

There is no real use for sprite-tile interaction variables for default Miragia sprites, since they don't do anything. By default it has none.

Keen 4

%patch $30C84 $00000000L #Miragia 1
%patch $30CA2 $00000000L #Miragia 2
%patch $30CC0 $00000000L #Miragia 3
%patch $30CDE $00000000L #Miragia 4
%patch $30CFC $00000000L #Miragia 5
%patch $30D1A $00000000L #Miragia 6
%patch $30D38 $00000000L #Miragia 7
%patch $30D56 $00000000L #Miragia 8


Action type

Miragia uses type 0 for all of its actions. This runs its behavior once, when the action changes. This is all Miragia needs to function.

Keen 4

#Miragia action type
%patch $30C70 [$0000W]
%patch $30C8E [$0000W]
%patch $30CAC [$0000W]
%patch $30CCA [$0000W]
%patch $30CE8 [$0000W]
%patch $30D06 [$0000W]
%patch $30D24 [$0000W]
%patch $30D42 [$0000W]


Deprotect and stick to ground

Like the above section there is also no need for Miragia to stick to the ground, at least by default.

Keen 4

%patch $30C72 $0000W $0000W #Miragia 1
%patch $30C90 $0000W $0000W #Miragia 2
%patch $30CAE $0000W $0000W #Miragia 3
%patch $30CCC $0000W $0000W #Miragia 4
%patch $30CEA $0000W $0000W #Miragia 5
%patch $30D08 $0000W $0000W #Miragia 6
%patch $30D26 $0000W $0000W #Miragia 7
%patch $30D44 $0000W $0000W #Miragia 8


Sprite spawn code

In the initiation code notice Miragia has no Sprite cache'

In the spawning 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 $07 $xxxxW sets the sprite type.

This patch contains, and is thus incompatible with, the sprite action patch, sprite type patch, and sprite clipping patch.

Keen 4

#Location of initiation code
%patch $EEC5 [$03A3W] #Miragia (At $EC93)

#Miragia Initiation code
%patch $EC93 $FF $76 $FC $57 $9A {$0FA80000RL}     $83 $C4 $04 $E9 $015BW

#Miragia spawning code
%patch $FA80  $55 $8B $EC $33 $C0 $50 $9A $06BD1E11RL     $83 $C4 $02 $8B $1E
              $D8 $A7 $C7 $07 [$0001W]  $C7 $47 $02 [$0002W]  $8B $46 $06 $89 $47
              $0A $8B $46 $08 $89 $47 $0C $C7 $47 $1C [$1DFCW]  $5D $CB