Patch:Sprite speed

From KeenWiki
Jump to navigation Jump to search

This page is a tutorial page on patching sprite speeds and jump heights. It contains information on what sprite speed is and how to patch it. A sprite's speed is, unsurprisingly, how fast a sprite is moving. Other sprite variables are discussed briefly in Patch:Galaxy Sprite Parameters.

There are two directions of speed, vertical and horizontal. Speeds are usually given in pixels (16ths of a tile) with 'positive' speeds ($0000W-$7FFFW) being right or down and 'negative' speeds ($8000W-$FFFFW) being left and right. (But see the section on direction below.)

It is possible to patch speeds in decimal, like all patches, which may be simpler for newer modders. A speed of +-10 looks better than $000AW\$FFF6W. However values of 0-256 patch only one byte, which can cause problems. Otherwise patching speeds is quite simple, both action and normal speeds require a simple two byte patch.


Speeds in Vorticons vs Galaxy

In Keen Vorticons sprite speeds are set in the sprite code. Most speeds are horizontal speeds, vertical speeds being mainly used to set jump heights. (Though exceptions exist, such as the Scrub. 'Coded' speeds are always 'smooth'; that is the sprite will not jump from one place to another, but smoothly cover all points between. That is a sprite with a speed of ten pixels per second will move one pixel every tenth of a second, giving the impression of smooth gliding movement.

In Galaxy the situation is more complex; not only are speeds given in spite code, but also in sprite actions. While coded speeds are smooth, 'action speeds' can be jerky, making the sprite move in fits and bursts, or even teleport from one place to another without covering the distance between. This is detailed in Patch:Galaxy Action Parameters.

As well as these two kinds of speeds there is the variable of sprite direction, detailed in the section below.

Keen Dreams uses the same methods as galaxy.


Direction

Speed and direction are two different variables. (Actually four, horizontal and vertical values exist for speed and direction.) Sprite direction can be considered the direction the sprite is facing, is it looking left, right, up or down (Or nowhere)? Direction has one of three values, -1, 0 and 1. (Left, nowhere, right.) If a direction is not set, it is 0.

This affects two things, firstly it affects the animation used. In Vorticons the horizontal direction controls which sprite animation is displayed whereas in galaxy both the horizontal and vertical direction can influence this (With horizontal taking priority.) If a sprite's direction is 0 it will show the same sprite as if it were facing left.

Direction may also affect action speed. A sprite with a horizontal action speed of 40 pixels will move 40 pixels right if its direction if right (or none) but will move 40 pixels left if the sprite's direction is left.

Keen Vorticons does not have independent sprite direction, a sprite that is moving left is automatically facing left, one moving right is facing right and one sitting still facing right. (In Galaxy and Dreams it is possible for a sprite to be facing left while moving right and so on.)

It is possible for a sprite's direction OR its' speed to affect other things if that is coded, as well as the action speed (Though this is not done by default.)

Sometimes two speeds do not make sense, jump heights can be positive (In theory downwards, not upwards.) and a sprite may use a negative speed to move right. As such the relation between magnitude and direction is a guide only and it is wise to pay attention to the default magnitude.


Examples

The following alters Keen 1's Yorp's walking speed. The speed is set when looking for Keen, (but not the direction.) As can be seen, this is a good example of the Vorticons 'two speed' system.

Keen 1

%patch $1A1C $FFC4W #If right of Keen after searching (Move left)
%patch $1A14 $003CW #If left of Keen after searching (Move right)


This patch illustrates the Keen 4 Dart speeds. There are three types of dart, up, down and left\right. Notice that both the speed and direction are set here and that in the case of the horizontal darts the direction controls whether they move left or right.

Dart speeds

#Horizontal darts
%patch $327FC [$0040W] [$0000W]
%patch $3281A [$0040W] [$0000W]

#Up darts
%patch $32838 [$0000W] [$0040W]
%patch $32856 [$0000W] [$0040W]

#Down darts 
%patch $32874 [$0000W] [$0040W]
%patch $32892 [$0000W] [$0040W]

Keen 4 dart directions

#Down dart
%patch $12948 $0000W #H
%patch $1294D $FFFFW #V

#Right Dart
%patch $12965 $0001W #H
%patch $1296A $0000W #V

#Up Dart
%patch $12982 $0000W #H
%patch $12987 $0001W #V

#Left dart
%patch $1299F $FFFFW #H
%patch $129A4 $0000W #V