Difference between revisions of "Script Classes for Adventure Games/Motion Classes"
(→caller) |
|||
(26 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
Chapter: | Chapter: | ||
[[Script Classes for Adventure Games/Introduction|1]] | | [[Script Classes for Adventure Games/Introduction|1]] | | ||
− | [[Script Classes for Adventure Games/RootObj|2]] | | + | [[Script Classes for Adventure Games/RootObj Class|2]] | |
− | [[Script Classes for Adventure Games/Object|3]] | | + | [[Script Classes for Adventure Games/Object Class|3]] | |
− | [[Script Classes for Adventure Games/Collection|4]] | | + | [[Script Classes for Adventure Games/Collection Class|4]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Script Class|5]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Timer Class|6]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Feature Class|7]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/View Class|8]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/PicView Class|9]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Cycling Classes|10]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Motion Classes|11]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Avoider Class|12]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Event Class|13]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/User Class|14]]<br /> |
− | + | [[Script Classes for Adventure Games/Game Class|15]] | | |
− | + | [[Script Classes for Adventure Games/Locale Class|16]] | | |
− | + | [[Script Classes for Adventure Games/Region Class|17]] | | |
− | + | [[Script Classes for Adventure Games/Room Class|18]] | | |
− | + | [[Script Classes for Adventure Games/Timer2 Class|19]] | | |
− | + | [[Script Classes for Adventure Games/InvItem Class|20]] | | |
− | + | [[Script Classes for Adventure Games/Block Class|21]] | | |
− | + | [[Script Classes for Adventure Games/Cage Class|22]] | | |
− | + | [[Script Classes for Adventure Games/Sound Class|23]] | | |
− | + | [[Script Classes for Adventure Games/StatusLine Class|24]] | | |
− | + | [[Script Classes for Adventure Games/File Class|25]] | | |
− | + | [[Script Classes for Adventure Games/Code Class|26]] | | |
− | + | [[Script Classes for Adventure Games/Global Variables|27]] | | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[Script Classes for Adventure Games/Game| | ||
− | [[Script Classes for Adventure Games/Locale| | ||
− | [[Script Classes for Adventure Games/Region| | ||
− | [[Script Classes for Adventure Games/Room| | ||
− | [[Script Classes for Adventure Games/Timer2| | ||
− | |||
− | [[Script Classes for Adventure Games/InvItem| | ||
− | [[Script Classes for Adventure Games/Block| | ||
− | [[Script Classes for Adventure Games/Cage| | ||
− | [[Script Classes for Adventure Games/Sound| | ||
− | [[Script Classes for Adventure Games/StatusLine| | ||
− | [[Script Classes for Adventure Games/File| | ||
− | [[Script Classes for Adventure Games/Code| | ||
− | [[Script Classes for Adventure Games/Global Variables| | ||
[[Script Classes for Adventure Games/Index|Index]] | [[Script Classes for Adventure Games/Index|Index]] | ||
</div><br /> | </div><br /> | ||
Line 105: | Line 82: | ||
<blockquote>The object to cue: when the motion is complete.</blockquote> | <blockquote>The object to cue: when the motion is complete.</blockquote> | ||
− | + | ===== dx<br /> dy<br /> b-moveCnt<br /> b-i1<br /> b-i2<br /> b-di<br /> b-xAxis<br /> b-incr ===== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<blockquote>These properties are used internally by the modified Bresenham line algorithm which moves the Actors.</blockquote> | <blockquote>These properties are used internally by the modified Bresenham line algorithm which moves the Actors.</blockquote> | ||
</blockquote> | </blockquote> | ||
Line 121: | Line 91: | ||
=====<br /> moveDone ===== | =====<br /> moveDone ===== | ||
<blockquote>Executed when the motion completes or is blocked. Cue:s the caller, if there was one, and dispose:s of the motion class.</blockquote> | <blockquote>Executed when the motion completes or is blocked. Cue:s the caller, if there was one, and dispose:s of the motion class.</blockquote> | ||
+ | </blockquote> | ||
===<br /> MoveTo === | ===<br /> MoveTo === | ||
Line 149: | Line 120: | ||
<blockquote> | <blockquote> | ||
=====<br /> distance ===== | =====<br /> distance ===== | ||
− | < | + | <blockquote>The maximum distance to be wandered on a given leg of the wander.</blockquote> |
</blockquote> | </blockquote> | ||
Line 215: | Line 186: | ||
=====<br /> y ===== | =====<br /> y ===== | ||
− | <blockquote>y coord of finish. This property is also set internally. | + | <blockquote>y coord of finish. This property is also set internally.</blockquote> |
+ | |||
=====<br /> gx ===== | =====<br /> gx ===== | ||
<blockquote>gravitational acceleration in pixels/(animation cycle)**2. The default is no horizontal gravity, or 0.</blockquote> | <blockquote>gravitational acceleration in pixels/(animation cycle)**2. The default is no horizontal gravity, or 0.</blockquote> | ||
Line 225: | Line 197: | ||
<blockquote>horizontal step size. Used by Jump to calculate next position.</blockquote> | <blockquote>horizontal step size. Used by Jump to calculate next position.</blockquote> | ||
− | yStep | + | =====<br /> yStep ===== |
<blockquote>vertical step size. Used by Jump to calculate next position.</blockquote> | <blockquote>vertical step size. Used by Jump to calculate next position.</blockquote> | ||
Line 257: | Line 229: | ||
====<br /> Methods ==== | ====<br /> Methods ==== | ||
+ | <blockquote> | ||
=====<br /> init ===== | =====<br /> init ===== | ||
<blockquote>This method is called by the Actors setMotion method. A JumpTo is initiated by, (actorNam. setMotion: JumpTo x y whoCares) | <blockquote>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.</blockquote> | This will make an Actor jump to the coordinates x y, and then cue whoCares.</blockquote> | ||
+ | </blockquote> | ||
===<br /> Orbit === | ===<br /> Orbit === | ||
Line 276: | Line 250: | ||
<blockquote> | <blockquote> | ||
− | ====<br /> centerObj ===== | + | =====<br /> centerObj ===== |
<blockquote>The object (Feature View PicView Prop or Actor) to orbit around.</blockquote> | <blockquote>The object (Feature View PicView Prop or Actor) to orbit around.</blockquote> | ||
Line 300: | Line 274: | ||
====<br /> Methods ==== | ====<br /> Methods ==== | ||
+ | <blockquote> | ||
=====<br /> init ===== | =====<br /> init ===== | ||
<blockquote>This method is called by the Actors setMotion method. a JumpTo is initiated by, | <blockquote>This method is called by the Actors setMotion method. a JumpTo is initiated by, | ||
Line 317: | Line 292: | ||
) | ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | <blockquote> | + | </blockquote> |
+ | </blockquote> | ||
===<br /> Path === | ===<br /> Path === | ||
Line 333: | Line 309: | ||
====<br /> Properties ==== | ====<br /> Properties ==== | ||
− | ====<br /> intermediate ==== | + | <blockquote> |
+ | =====<br /> intermediate ===== | ||
<blockquote>Object to cue at intermediate endpoints.</blockquote> | <blockquote>Object to cue at intermediate endpoints.</blockquote> | ||
====<br /> value ==== | ====<br /> value ==== | ||
<blockquote>index into path array</blockquote> | <blockquote>index into path array</blockquote> | ||
+ | </blockquote> | ||
====<br /> Methods ==== | ====<br /> Methods ==== | ||
+ | <blockquote> | ||
=====<br /> at ===== | =====<br /> at ===== | ||
<blockquote>Returns the nth element of control array. This method must be redefined to point to the users path array.</blockquote> | <blockquote>Returns the nth element of control array. This method must be redefined to point to the users path array.</blockquote> | ||
Line 377: | Line 356: | ||
<blockquote>(ego posn:100 100, setMotion: squarePath obj1 obj2)</blockquote> | <blockquote>(ego posn:100 100, setMotion: squarePath obj1 obj2)</blockquote> | ||
− | |||
===<br /> RelPath === | ===<br /> RelPath === | ||
Line 391: | Line 369: | ||
|} | |} | ||
− | Example | + | ===<br /> Example === |
The following uses a RelPath to make ego do loop-the-loops across the screen: | The following uses a RelPath to make ego do loop-the-loops across the screen: | ||
+ | <blockquote> | ||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
<syntaxhighlight lang="sci"> | <syntaxhighlight lang="sci"> | ||
Line 416: | Line 395: | ||
) | ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | | |
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
<syntaxhighlight lang="sci"> | <syntaxhighlight lang="sci"> | ||
Line 438: | Line 417: | ||
) | ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | </blockquote> | ||
| | ||
Line 450: | Line 430: | ||
| | ||
− | <span style="float: left">[[Script Classes for Adventure Games/ | + | <span style="float: left">[[Script Classes for Adventure Games/Cycling Classes|< Previous: The Cycling Classes]]</span> |
− | <span style="float: right">[[Script Classes for Adventure Games/ | + | <span style="float: right">[[Script Classes for Adventure Games/Avoider Class|Next: The Avoider Class >]]</span> |
| |
Latest revision as of 01:46, 19 January 2016
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
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.
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
distanceThe 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
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.
yStepvertical 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.
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
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.
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
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. )
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
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:
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
< Previous: The Cycling Classes Next: The Avoider Class >