Script Classes for Adventure Games/Motion Classes
Chapter:
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
Index
The Motion Classes
The sub-classes of class Motion implement the various kinds of motion which Actors can execute.
Motion
The Motion class is the basis for all the specialized motions. If a caller is specified in the setMotion: for a motion, it will be notified of the motion's completion by being sent the cue: message.
In file: | motion.sc |
Inherits from: | Object |
Inherited by: | MoveTo |
Wander | |
Chase | |
Follow | |
Jump | |
Orbit | |
Path |
Properties
x
y
The coordinates towards which the Actor is moving.
client
The Actor being moved by the instance of motion.
caller
The object to cue: when the motion is complete.
dx
dy
b-moveCnt
b-i1
b-i2
b-di
b-xAxis
b-incrThese properties are used internally by the modified Bresenham line algorithm which moves the Actors.
Methods
moveDoneExecuted when the motion completes or is blocked. Cue:s the caller, if there was one, and dispose:s of the motion class.
MoveToThe MoveTo class just moves an object to a particular position. An Actor is moved to a position with (actor setMotion: MoveTo x y [caller]).
In file: motion.sc Inherits from: Motion Inherited by: none
WanderThe Wander motion class implements a random wander for Actors. It is invoked for an Actor by (actor setMotion: Wander [distance]) where the optional argument, distance, is the maximum distance of a leg of the wander (default is 20 pixels). This motion never completes — the Actor will keep wandering until a new motion type is set.
In file: motion.sc Inherits from: Motion Inherited by: none
Properties
distance<blockquoteThe maximum distance to be wandered on a given leg of the wander.</blockquote
Follow
This class is for making one Actor follow another. It is invoked for an Actor with (actor setMotion: Follow anotherActor [distance]), where anotherActor is the Actor to be followed and the optional distance specifies how closely to follow. If actor is further from anotherActor than distance, it will start moving towards anotherActor. Otherwise it will stop moving. The default distance is 15 pixels. As for Wander, this motion never completes.
In file: | motion.sc |
Inherits from: | Motion |
Inherited by: | none |
Properties
whoThe ID of the Actor being followed.
distanceThe distance to try and maintain from the Actor specified by who.
Chase
This class implements the concept of trying to catch another Actor. It is invoked with (actor setMotion: Chase anotherActor distance [caller]). As in Follow, anotherActor is the Actor to chase. Distance is the distance from anotherActor at which it is considered to be caught. When anotherActor has been caught, caller is cue:ed.
In file: | motion.sc |
Inherits from: | Motion |
Inherited by: | none |
Properties
whoThe ID of the Actor being chased.
distanceThe distance from who at which who is considered caught.
Jump
This class simulates motion under a gravitational field. It is useful to make an Actor simultate a falling motion. The fall is straight down by default. This simulates, for example, falling off of a cliff. A horizontal gravitation can also be simulated by setting the gx property.
In file: | jump.sc |
Inherits from: | Motion |
Inherited by: | JumpTo |
Properties
xx coord of finish. This property is set by the init method to reflect to clients velocity.
yy coord of finish. This property is also set internally.
gxgravitational acceleration in pixels/(animation cycle)**2. The default is no horizontal gravity, or 0.
gygravitational acceleration in pixels/(animation cycle)**2. This is set according to how intense a gravitation field you wish to have simulated. The default is 3 pixels per (animation cycle)**2, so after 1 cycle the Actor would be moving 3 pixels/animation cycle 6 after 2 cycles etc.
xStephorizontal step size. Used by Jump to calculate next position.
yStep
vertical step size. Used by Jump to calculate next position.
signalsave area for client's signal bits. Don't set this property.
illegalBitssave area for illegal bits of client. Don't set this property.
The following two properties, when true, indicate that we are to check for motion completion only after the apogee of the motion. This is necessary if we are to be able to jump onto things. Set these to FALSE if you do NOT want this behavior.
WaitApogeeX TRUE
waitApogeeY TRUE
setTestprivate — set up the jump completion test.
JumpToThis class sets up a Jump which will reach a certain x,y position. The kernel call (SetJump) does this in order to use long integer arithmetic. The Motion can the cue: a caller to signal then completion of the jump.
In file: jump.sc Inherits from: Jump Inherited by: none
Methods
initThis method is called by the Actors setMotion method. A JumpTo is initiated by, (actorNam. setMotion: JumpTo x y whoCares) This will make an Actor jump to the coordinates x y, and then cue whoCares.
OrbitThis class sets up an elliptical path for an Actor to follow. This allows the simulation of an object orbiting around another object. This mover takes into account the global variable perspective.
In file: orbit.sc Inherits from: Motion Inherited by: none
Properties
centerObjThe object (Feature View PicView Prop or Actor) to orbit around.
radiusThe radius of the orbit along its major axis (the widest part).
xTiltThe horizontal tilt of ellipse. 0 would be circular and 90 would be edge on.
yTiltThe horizontal tilt of ellipse. 0 would be circular and 90 would be edge on.
angleStepAngle degree increment per animation cycle.
windingThe direction of the orbit. clockwise=1 counterclockwise=-1
curAngleWhere the Actor will be along the Orbit. 0=north, 90=east etc.
Methods
initThis method is called by the Actors setMotion method. a JumpTo is initiated by,
Code:(anActor setMotion: Orbit ;class Orbit or an instance of it theCtrObj ;some object with x and y properties theRadius ;of the orbit theXTilt ;counterclockwise from x-axis in degrees theYTilt ;same from y-axis theStep ;in degrees, default is 10 theWinding ;clockwise=1 counterclockwise=-1 theAngle ;0=north, etc. )
PathThis class gives the Actor a Path to follow and allows cue'ing of an object at the intermediate points as well as at the end of the path. It requires less memory than a Script and is also easier to use. The points of the Path are specified in a local array.
In file: path.sc Inherits from: MoveTo Inherited by: RelPath
Properties
intermediateObject to cue at intermediate endpoints.
valueindex into path array
Methods
atReturns the nth element of control array. This method must be redefined to point to the users path array.
nextMove to next point in path. This method is used internally.
atEndReturns TRUE if at the end of the path. This method is used internally.
ExampleTo create a square Path (assuming that ego is positioned at 100,100) we do the following:
Code:(local sPath = [ 100 60 160 60 160 100 100 100 PATHEND ] ) (instance squarePath of Path (method (at n) (return [sPath n]) ) )
The following will make ego walk the path once and cue obj1 at completion of entire path and will cue obj2 at all intermediate pts.
(ego posn:100 100, setMotion: squarePath obj1 obj2)
RelPath
This class gives the Actor a Path to follow and allows cue'ing of an object at the intermediate points as well as at the end of the path. It requires less memory than a Script and is also easier to use. The relative offsets of the Path are specified in a local array.
In file: | path.sc |
Inherits from: | Path |
Inherited by: | none |
Example:
The following uses a RelPath to make ego do loop-the-loops across the screen:
(local
lPath = [
-10 -10
0 -10
1 -10
1 0
1 10
0 10
-10 10
PATHEND
]
)
(instance loopPath of Path
(method (at n)
(return [lPath n])
)
)
(instance rm1 of Room
(properties
picture 1
)
(method (init)
(ego
posn: 60 100,
init:,
setMotion: aPath self
)
(super init:)
)
(method (cue)
(ego setMotion: aPath self)
)
)
- Notes
< Previous: BegLoop Next: MoveTo >