Patch:Sprite clipping and foreground
This page deals with sprite clipping and foreground code. The clipping is how a sprite reacts to solid tiles. Foreground is how the sprite appears behind\ in front of various tiles. Both are treated differently in Keen Vorticons vs Keen Galaxy.
Clipping
In many poorly made games characters will walk through things that are supposed to be solid, or are blocked by things that are not. Even worse are inconsistencies, where things end up where they shouldn't. The Keen games avoid this with a robust clipping system.
Clipping is specifically deals with generalities rather than specifics; many sprites have specific code to look for certain tile types, clipping however affects ALL sprites.
Keen Vorticons has no specific clipping variables; sprites use various bits of code to make them stop moving when they hit solid things, but any sprite can be made to simply 'ghost' through tiles by disabling calls to that code.
Keen Galaxy (And Dreams) have a dedicated clipping system; each sprite has a variable that controls how it reacts to solid tiles, and no matter what a sprites Sprite-tile interaction code is, all sprites use a basic system for Keeping them out of solid tiles. (This can be seen if Keen is placed in a block of ground, he will quickly be ejected from it at speed.) If no clipping is set, a default value of 1 is used for a sprite.
The galaxy clipping variable can be set from 0 to 2 as follows:
0: Ignore all tiles 'Ghost' 1: Hit solid tiles, but don't get pushed out of them if accidentally inside 2: Hit solid tiles and get pushed out of them if accidentally inside
Most sprites are not given a clipping specifically, it seems to be set to 1 unless otherwise changed.
Foreground
The foreground variable is another thing that appears only in Keen Galaxy. There are two types of tile in Keen games, those that are background and those that are foreground. In Keen Vorticons Foreground tiles always appear in front of Keen and sprites.
In Keen Galaxy not only are there fore and back tiles (Really masked and unmasked) giving the level three layers (Back, front ans sprite), but the fore tiles can be foreground or not (Or if you wish super-foreground) The foreground variable can be set between 0 to 3 as follows:
0: Appear behind all sprites and fore tiles 1: Appear behind fore tiles 2: Appear in front o normal fore tiles 3: Appear in front of everything
A sprite will appear behind another sprite if it has a higher foreground value OR if it was created first. Thus sprites that appear in front of everything (Value 3) will also always appear in front of Keen(Value 2) and there is nothing that can be done about this.
Keen Dreams
Keen Dreams has a similar setup to Keen Galaxy, and in theory sprites could be given the same sorts of foreground variables. However, these have not been implemented in the default game. Instead there is a special tile collision used by acquired items and a few other sprites that makes them appear in front of all tiles. This makes foreground manipulation considerably more difficult.
Clipping, foreground and sprite parameters
Both clipping and foreground in Keen Galaxy are sprite parameters; every sprite has values for these parameters and they can be changed in the game. Clipping is int $06 and foreground int $20 which means to change these variables an any Galaxy game the following code needs to appear (in this example setting the values to 1.):
Keen Galaxy
#Chnage forground and clipping variable of a sprite to 1
%patch $ABCD $C7 $47 $20 [$0001W] #Foreground
%patch $ABCD $C7 $47 $06 [$0001W] #Clipping
FullClipToWalls errors
This is an issue with a sprite's clipping; specifically it is trying to use a clipping of 2 (Full clipping to walls\slopes) when it can't. Most sprites use a clipping of 1, allowing them to move up slopes but not into walls. Some sprites however like the Dopefish need to avoid sloped tiles altogether and thus use a value of 2. But this has very limited usability.
This error usually occurs when an 'ordinary' sprite is given the wrong clipping but can also occur if something goes severely wrong and a sprite gets muddled. To identify the error make a test level and add sprites in one-by-one.
FullClipToWalls errors
#Keen 4 :
%patch $A7BC [$08D8W] #Text called from
%patch $2F748 "FullClipToWalls: Bad obclass" $00
#Keen 5 :
%patch $9AE4 [$07C4W] #Text called from
%patch $30B04 "FullClipToWalls: Bad obclass" $00
#Keen 6 :
%patch $99C9 [$07BCW] #Text called from
%patch $314EC "FullClipToWalls: Bad obclass" $00