Script Classes for Adventure Games/Actor Class

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 Actor Class

Author: Jeff Stephenson

Date: 5 April 1988

 


The Actor Class

The Actor class is the embodiment of an animated object.

In file: actor.sc
Inherits from: Prop
Inherited by: Ego


Properties


xLast
yLast

The coordinates of the Actor's previous position.


xStep
yStep

The x and y step sizes for the Actor. Default is (= xStep 3) and (= yStep 2).


heading

The compass direction in which the Actor is headed. North (toward the top of the screen) is 0, south 180.


moveSpeed

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


illegalBits

A 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.


baseSetter

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


mover

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


looper

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


viewer

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


avoider

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


Methods


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

Set 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: other

Check 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: anObject

Returns 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.]


inRect: left top right bottom

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.

 

Notes


 

Table of Contents

 

< Previous: The Prop Class Next: The Ego Class >