Script Classes for Adventure Games/Actor Class
From SCI Wiki
The Actor Class
Author: Jeff Stephenson
Date: 5 April 1988
Author: Jeff Stephenson
- 1 The Actor Class
- 1.1 Properties
- 1.2 Methods
- 1.2.1 init:
- 1.2.2 doit:
- 1.2.3 setLoop: [newLoop]:
- 1.2.4 ignoreHorizon: [n]
- 1.2.5 setMotion: motion [caller]
- 1.2.6 setAvoider: avoider
- 1.2.7 isStopped:
- 1.2.8 isBlocked:
- 1.2.9 canBeHere:
- 1.2.10 findPosn:
- 1.2.11 check: other
- 1.2.12 distanceTo: anObject
- 1.2.13 inRect: left top right bottom
- 1.2.14 onControl: [origin]
The Actor Class
The Actor class is the embodiment of an animated object.
yLastThe coordinates of the Actor's previous position.
yStepThe x and y step sizes for the Actor. Default is (= xStep 3) and (= yStep 2).
headingThe compass direction in which the Actor is headed. North (toward the top of the screen) is 0, south 180.
moveSpeedThe number of animation cycles between motions of the Actor. Normally this is 0, meaning that the Actor moves at each animation cycle. If you want the Actor to move more slowly, set this to a larger value. By playing with this and cycleSpeed, many strange effects may be discovered.
illegalBitsA bit-mapped word which specifies which controls an Actor CANNOT be on. The low bit ($0001) corresponds to control 0 and the high bit ($8000) to control 15. By convention, control 0 is generally accessible to all Actors, whereas control 15 is off-limits to all Actors — thus, the default value of illegalBits is $8000.
baseSetterThe object ID of an instance of BaseSetter which is used to compute the base rectangle of the Actor. The default for the base of an Actor is a rectangle whose left and right sides are the sides of the nowSeen rectangle, whose bottom is the y coordinate of the Actor's origin, and whose top is the Actor's yStep above the bottom. This default is used if baseSetter is 0.
moverThe ID of an instance of a Motion class which is used to determine an Actor's path of motion. Don't modify this directly, but use the setMotion: method to set the type of motion to be executed by the Actor. The code pointed to by this property will be invoked with (mover doit: self) by the Actor in each animation cycle.
looperThe object ID of an instance of class Code which sets the Actor's loop based on the direction in which it is headed. The code is called with (looper doit: self theAngle) by the Actor during the initialization period of any setMotion:. It uses the current position of the Actor and the direction in which the Actor is heading (theAngle) to determine which loop to display. The default, which gets installed during the init: phase of an Actor, will handle virtually every case you'll encounter.
viewerThe object ID of an instance of class Code which sets the Actor's view. This is used, for example, when an Actor should wade or swim when on certain controls. The code pointed to by viewer is called with (viewer doit: self) and can test for the Actor being on a control and set the view accordingly.
avoiderThe object ID of an instance of class Avoider. If a moving Actor collides with something (control in the picture, another Actor, etc.) which prevents it from moving, the avoider attempts to find a way around it.
init:Does the usual setup for a Prop, sets looper to DirLoop, and sets avoider to an instance of class Avoider for all but ego.
doit:If an Actor has any of the following, it invokes them in order: a script, a viewer, an avoider or mover (the avoider, if present will call the mover), and a cycler.
setLoop: [newLoop]:Normally, an Actor's loop is set by invoking the looper method, which does so based on the Actor's direction. Sending the setLoop: message with no argument fixes the loop at its current value. If newLoop is present, the loop is set to its value. If the newLoop is -1, loop determination is returned to the looper method.
ignoreHorizon: [n]If n is absent or TRUE, this allows the Actor to be above the current Room's horizon. If n is FALSE, the Actor will not be allowed to go above the horizon of the current Room and will be repositioned to the horizon if an attempt is made to position it there. The default state of an Actor is equivalent to ignoreHorizon:FALSE.
setMotion: motion [caller]Sets the Actor's motion property to an instance of a Motion class, deleting any former instance. Doing a setMotion:0 disposes any current motion without installing a new one. The optional caller argument is the object to be cue:ed when the motion is completed.
setAvoider: avoiderSet the Actor's Avoider to avoider. To remove an Avoider from the Actor, do a setAvoider:0.
isStopped:Return TRUE if the Actor is in the same position as it was during the previous animation cycle, FALSE otherwise.
isBlocked:Returns TRUE if the Actor tried to move, but was unable to because of something blocking it. If this is TRUE, the avoider will generally be invoked.
canBeHere:Return TRUE if the Actor can be in its current position, FALSE otherwise. This checks to see whether the Actor's baseRect is on any illegal controls (specified by illegalBits), whether it has collided with a View, Prop, Actor or Ego, and whether it has collided with one of the Room's Blocks. In any of these cases, FALSE will be returned.
findPosn:Reposition the Actor until canBeHere: returns TRUE. This is called whenever canBeHere: returns FALSE during animation. It searches in concentric rectangles outward from the Actor's position for a legal position.
check: otherCheck to see if the Actor's baseRect intersects that of other. Return TRUE if it does not, indicating that the Actor has not collided with other.
distanceTo: anObjectReturns the distance (in pixels) to anObject (which had better have x and y properties). [Note: this is the real distance, not the kludge used in the previous interpreter. Because this uses the square-root function, it is slow — don't use it 100 times per animation cycle, or you'll notice a degradation in performance.]
Returns TRUE if the Actor's x and y are within the bounding rectangle, FALSE otherwise.
onControl: [origin]Returns a bit-mapped word (mapped like the illegalBits property) indicating which controls the baseRect of the object encloses. If the optional origin argument is used (just use the word "origin"), the control under the x, y coordinate of the object is returned.