Difference between revisions of "Script Classes for Adventure Games/Motion Classes"

From SCI Wiki
Jump to navigationJump to search
 
(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/List|5]] |  
+
[[Script Classes for Adventure Games/Script Class|5]] |  
[[Script Classes for Adventure Games/Set|6]] |  
+
[[Script Classes for Adventure Games/Timer Class|6]] |  
[[Script Classes for Adventure Games/EventHandler|7]] |  
+
[[Script Classes for Adventure Games/Feature Class|7]] |  
[[Script Classes for Adventure Games/Inventory|8]] |  
+
[[Script Classes for Adventure Games/View Class|8]] |  
[[Script Classes for Adventure Games/Script|9]] |  
+
[[Script Classes for Adventure Games/PicView Class|9]] |  
[[Script Classes for Adventure Games/Timer|10]] |  
+
[[Script Classes for Adventure Games/Cycling Classes|10]] |  
[[Script Classes for Adventure Games/Feature|11]] |  
+
[[Script Classes for Adventure Games/Motion Classes|11]] |  
[[Script Classes for Adventure Games/View|12]] |  
+
[[Script Classes for Adventure Games/Avoider Class|12]] |  
[[Script Classes for Adventure Games/Prop|13]] |  
+
[[Script Classes for Adventure Games/Event Class|13]] |  
[[Script Classes for Adventure Games/Actor|14]] |
+
[[Script Classes for Adventure Games/User Class|14]]<br />
[[Script Classes for Adventure Games/Ego|15]] |
+
[[Script Classes for Adventure Games/Game Class|15]] |  
[[Script Classes for Adventure Games/PicView|16]] |
+
[[Script Classes for Adventure Games/Locale Class|16]] |  
[[Script Classes for Adventure Games/Cycle|17]] |
+
[[Script Classes for Adventure Games/Region Class|17]] |  
[[Script Classes for Adventure Games/Forward|18]] |
+
[[Script Classes for Adventure Games/Room Class|18]] |  
[[Script Classes for Adventure Games/Walk|19]] |
+
[[Script Classes for Adventure Games/Timer2 Class|19]] |  
[[Script Classes for Adventure Games/Reverse|20]] |
+
[[Script Classes for Adventure Games/InvItem Class|20]] |  
[[Script Classes for Adventure Games/CycleTo|21]] |
+
[[Script Classes for Adventure Games/Block Class|21]] |  
[[Script Classes for Adventure Games/EndLoop|22]] |
+
[[Script Classes for Adventure Games/Cage Class|22]] |  
[[Script Classes for Adventure Games/BegLoop|23]] |
+
[[Script Classes for Adventure Games/Sound Class|23]] |  
[[Script Classes for Adventure Games/Motion|24]] |
+
[[Script Classes for Adventure Games/StatusLine Class|24]] |  
[[Script Classes for Adventure Games/MoveTo|25]] |
+
[[Script Classes for Adventure Games/File Class|25]] |  
[[Script Classes for Adventure Games/Wander|26]]<br />
+
[[Script Classes for Adventure Games/Code Class|26]] |  
[[Script Classes for Adventure Games/Follow|27]] |
+
[[Script Classes for Adventure Games/Global Variables|27]] |  
[[Script Classes for Adventure Games/Chase|28]] |
 
[[Script Classes for Adventure Games/Jump|29]] |
 
[[Script Classes for Adventure Games/JumpTo|30]] |
 
[[Script Classes for Adventure Games/Orbit|31]] |
 
[[Script Classes for Adventure Games/Path|32]] |
 
[[Script Classes for Adventure Games/RelPath|33]] |
 
[[Script Classes for Adventure Games/Avoider|34]] |
 
[[Script Classes for Adventure Games/Event|35]] |
 
[[Script Classes for Adventure Games/User|36]] |
 
[[Script Classes for Adventure Games/Game|37]] |  
 
[[Script Classes for Adventure Games/Locale|38]] |  
 
[[Script Classes for Adventure Games/Region|39]] |  
 
[[Script Classes for Adventure Games/Room|40]] |  
 
[[Script Classes for Adventure Games/Timer2|41]] |
 
[[Script Classes for Adventure Games/TimeOut|42]] |  
 
[[Script Classes for Adventure Games/InvItem|43]] |  
 
[[Script Classes for Adventure Games/Block|44]] |  
 
[[Script Classes for Adventure Games/Cage|45]] |  
 
[[Script Classes for Adventure Games/Sound|46]] |  
 
[[Script Classes for Adventure Games/StatusLine|47]] |  
 
[[Script Classes for Adventure Games/File|48]] |  
 
[[Script Classes for Adventure Games/Code|49]] |  
 
[[Script Classes for Adventure Games/Global Variables|50]] |  
 
 
[[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 />
+
===== dx<br /> dy<br /> b-moveCnt<br /> b-i1<br /> b-i2<br /> b-di<br /> b-xAxis<br /> b-incr =====
'''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 =====
<blockquoteThe maximum distance to be wandered on a given leg of the wander.</blockquote
+
<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>
 
+
&nbsp;
 
<div class="CodeBlockHeader">Code:</div>
 
<div class="CodeBlockHeader">Code:</div>
 
<syntaxhighlight lang="sci">
 
<syntaxhighlight lang="sci">
Line 438: Line 417:
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</blockquote>
  
 
&nbsp;
 
&nbsp;
Line 450: Line 430:
 
&nbsp;
 
&nbsp;
  
<span style="float: left">[[Script Classes for Adventure Games/BegLoop|&lt; Previous: BegLoop]]</span>
+
<span style="float: left">[[Script Classes for Adventure Games/Cycling Classes|&lt; Previous: The Cycling Classes]]</span>
<span style="float: right">[[Script Classes for Adventure Games/MoveTo|Next: MoveTo &gt;]]</span>
+
<span style="float: right">[[Script Classes for Adventure Games/Avoider Class|Next: The Avoider Class &gt;]]</span>
  
 
&nbsp;
 
&nbsp;

Latest revision as of 01:46, 19 January 2016

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 >