Script Classes for Adventure Games/Motion Classes

From SCI Wiki
Jump to: navigation, search

Official SCI Documentation

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 | Index


The Motion Classes

Author: Jeff Stephenson

Date: 5 April 1988

 


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-incr
These properties are used internally by the modified Bresenham line algorithm which moves the Actors.


Methods


moveDone
Executed when the motion completes or is blocked. Cue:s the caller, if there was one, and dispose:s of the motion class.


MoveTo

The 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


Wander

The 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
The maximum distance to be wandered on a given leg of the wander.


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


who
The ID of the Actor being followed.

distance
The 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


who
The ID of the Actor being chased.

distance
The 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


x
x coord of finish. This property is set by the init method to reflect to clients velocity.

y
y coord of finish. This property is also set internally.

gx
gravitational acceleration in pixels/(animation cycle)**2. The default is no horizontal gravity, or 0.

gy
gravitational 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.

xStep
horizontal step size. Used by Jump to calculate next position.

yStep
vertical step size. Used by Jump to calculate next position.

signal
save area for client's signal bits. Don't set this property.

illegalBits
save 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


setTest
private — set up the jump completion test.


JumpTo

This 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


init
This 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.


Orbit

This 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


centerObj
The object (Feature View PicView Prop or Actor) to orbit around.

radius
The radius of the orbit along its major axis (the widest part).

xTilt
The horizontal tilt of ellipse. 0 would be circular and 90 would be edge on.

yTilt
The horizontal tilt of ellipse. 0 would be circular and 90 would be edge on.

angleStep
Angle degree increment per animation cycle.

winding
The direction of the orbit. clockwise=1 counterclockwise=-1

curAngle
Where the Actor will be along the Orbit. 0=north, 90=east etc.


Methods


init
This 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.
)


Path

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 points of the Path are specified in a local array.

In file: path.sc
Inherits from: MoveTo
Inherited by: RelPath


Properties


intermediate
Object to cue at intermediate endpoints.


value

index into path array


Methods


at
Returns the nth element of control array. This method must be redefined to point to the users path array.

next
Move to next point in path. This method is used internally.

atEnd
Returns TRUE if at the end of the path. This method is used internally.

Example

To 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:

Code:
(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])
   )
)

 

Code:
(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


 

Table of Contents

 

< Previous: The Cycling Classes Next: The Avoider Class >