Difference between revisions of "Script Classes for Adventure Games/Actor Class"
(6 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 62: | Line 39: | ||
| | ||
− | + | ==<br /> The Actor Class == | |
+ | |||
+ | The Actor class is the embodiment of an animated object. | ||
+ | |||
+ | {| | ||
+ | |width= "125"|In file:||actor.sc | ||
+ | |- | ||
+ | |Inherits from:||Prop | ||
+ | |- | ||
+ | |Inherited by:||Ego | ||
+ | |} | ||
+ | |||
+ | ===<br /> Properties === | ||
+ | |||
+ | <blockquote> | ||
+ | ====<br /> xLast <br />yLast ==== | ||
+ | <blockquote>The coordinates of the Actor's previous position.</blockquote> | ||
+ | |||
+ | ====<br /> xStep <br />yStep ==== | ||
+ | <blockquote>The x and y step sizes for the Actor. Default is (= xStep 3) and (= yStep 2).</blockquote> | ||
+ | |||
+ | ====<br /> heading ==== | ||
+ | <blockquote>The compass direction in which the Actor is headed. North (toward the top of the screen) is 0, south 180.</blockquote> | ||
+ | |||
+ | ====<br /> moveSpeed ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> illegalBits ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> baseSetter ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> mover ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> looper ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> viewer ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> avoider ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | </blockquote> | ||
+ | |||
+ | ===<br /> Methods === | ||
+ | |||
+ | <blockquote> | ||
+ | ====<br /> init: ==== | ||
+ | <blockquote>Does the usual setup for a Prop, sets looper to DirLoop, and sets avoider to an instance of class Avoider for all but ego.</blockquote> | ||
+ | |||
+ | ====<br /> doit: ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> setLoop: [newLoop]: ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> ignoreHorizon: [n] ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> setMotion: motion [caller] ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> setAvoider: avoider ==== | ||
+ | <blockquote>Set the Actor's Avoider to avoider. To remove an Avoider from the Actor, do a setAvoider:0.</blockquote> | ||
+ | |||
+ | ====<br /> isStopped: ==== | ||
+ | <blockquote>Return TRUE if the Actor is in the same position as it was during the previous animation cycle, FALSE otherwise.</blockquote> | ||
+ | |||
+ | ====<br /> isBlocked: ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> canBeHere: ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> findPosn: ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> check: other ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> distanceTo: anObject ==== | ||
+ | <blockquote>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.]</blockquote> | ||
+ | |||
+ | ====<br /> inRect: left top right bottom ==== | ||
+ | <blockquote>Returns TRUE if the Actor's x and y are within the bounding rectangle, FALSE otherwise.</blockquote> | ||
+ | |||
+ | ====<br /> onControl: [origin] ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | </blockquote> | ||
| |
Latest revision as of 00:15, 11 December 2015
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
The Actor class is the embodiment of an animated object.
In file: | actor.sc |
Inherits from: | Prop |
Inherited by: | Ego |
Properties
xLast
yLastThe coordinates of the Actor's previous position.
xStep
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.
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: 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.]
inRect: left top right bottomReturns 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
< Previous: The Prop Class Next: The Ego Class >