Difference between revisions of "Script Classes for Adventure Games/Room Class"
Line 39: | Line 39: | ||
| | ||
− | + | ==<br /> The Room Class == | |
+ | |||
+ | The Room class is the most specific Region. It is the point at which a picture, or 'scene' is defined for the player to walk around in. | ||
+ | |||
+ | {| | ||
+ | |width= "125"|In file:||game.sc | ||
+ | |- | ||
+ | |Inherits from:||Region | ||
+ | |- | ||
+ | |Inherited by:||none | ||
+ | |} | ||
+ | |||
+ | ===<br /> Properties === | ||
+ | |||
+ | ==== picture ==== | ||
+ | <blockquote>The number of the picture corresponding to the room. Usually, this will just be the room number.</blockquote> | ||
+ | |||
+ | ==== style ==== | ||
+ | <blockquote>If style is specified, it overrides the global showStyle when picture is drawn during the Room's init:. Any other picture drawn once the Room is running must have its show style explicitly specified.</blockquote> | ||
+ | |||
+ | ==== horizon ==== | ||
+ | <blockquote>The y coordinate which is considered to be the room's horizon. Actors which have not had an ignoreHorizon: done on them cannot be positioned above this coordinate. Also, an Ego which hits this coordinate will have its edgeHit property set to northEdge.</blockquote> | ||
+ | |||
+ | ==== blocks ==== | ||
+ | <blockquote>A Set of software blocks (Blocks), rectangles which Actors are not allowed to enter.</blockquote> | ||
+ | |||
+ | ==== north <br /> east <br /> south <br /> west ==== | ||
+ | <blockquote>The number of the room to which you wish to automatically change when ego hits the specified edge of the room. If you wish to control the room change yourself when ego hits a certain edge, do not specify the room for that edge in the Room instance and check (ego edgeHit?) yourself. The edgeHit property will have the value northEdge, southEdge, eastEdge, or westEdge if ego hit one of the edges.</blockquote> | ||
+ | |||
+ | ==== controls ==== | ||
+ | <blockquote>A set of dialog items (DItems) which are push-buttons for this</blockquote> | ||
+ | |||
+ | ==== picAngle ==== | ||
+ | <blockquote>This property is the angle above level that you are viewing the picture. It is used to set the global perspective upon room entry.</blockquote> | ||
+ | |||
+ | ==== vanishingX <br /> vanishingY ==== | ||
+ | <blockquote>These are set according to where the vanishing point is in the picture to be shown. They determine the angle that the arrow keys will move ego in a room. The Up key will always move ego towards the vanishing point and the down arrow away. The default give a straight up and down in response to these keys.</blockquote> | ||
+ | |||
+ | ===<br /> Methods === | ||
+ | |||
+ | ==== init: ==== | ||
+ | <blockquote>The default init: for a Room is to create an empty Set of Blocks, draw the picture specified by picture, and set ego's position based on its position in the previous room. You will want to supplement this with the following: | ||
+ | |||
+ | <blockquote>Load all views, sounds, pictures, etc. which will be required by the room so as to get all disk access done at Room initialization time.<br /> | ||
+ | Initialize all Actors and Actors which are to be in the Room initially.<br /> | ||
+ | Set a script for the Room.<br /> | ||
+ | Add any required Blocks to the Room.</blockquote></blockquote> | ||
+ | |||
+ | ==== doit: ==== | ||
+ | <blockquote>Send the doit: message to this Room's script, if it has one, then check to see if ego has hit the edge of the Room. If ego has hit an edge and there is a room number specified for the edge, invoke the newRoom: method to change to that room.</blockquote> | ||
+ | |||
+ | ==== dispose: ==== | ||
+ | <blockquote>This is called by the game when changing from this Room to a new Room. The game handles disposing of the current cast, then does a (curRoom dispose:). The default dispose: simply disposes of the Room's script, blocks, and controls. You will want to supplement this to dispose: of anything else which you have created which is specific to the Room, and any modules which the Room has loaded.</blockquote> | ||
+ | |||
+ | ==== setRegions: region [region ...] ==== | ||
+ | <blockquote>Sets the Regions which contain this room. This should be invoked in the init: method of the room. The parameters region are the script numbers of the regions. They should be listed from most specific to most general, since the order in which they are listed is the order in which they will be invoked. Thus, for a room in Ulence Flats in Space Quest, we might write | ||
+ | |||
+ | <blockquote>(self setRegions: ULENCE_FLATS KERONA)</blockquote> | ||
+ | |||
+ | to say that we are in the town of Ulence Flats on the planet Kerona. | ||
+ | |||
+ | The global variable regions contains the ID of a List of regions which are sent the doit: and handleEvent: messages in order when appropriate. The newRoom: method of Game puts the current room at the head of this list, and setRegions: adds Regions to the end of the list in the order in which they are listed in the parameter list. If the Region was used in the previous Room, it will be neither reloaded nor reinitialized. At the end of the newRoom: method, all Regions in the list which do not refer to the current Room are deleted.</blockquote> | ||
+ | |||
+ | ==== handleEvent: event ==== | ||
+ | <blockquote>The default Room method passes the event along to the Room script (if there is one) and then to any controls in the room.</blockquote> | ||
+ | |||
+ | ==== newRoom: n ==== | ||
+ | <blockquote>This method is the one to use when changing Rooms. It is invoked when the Room automatically changes to a new Room when ego hits the edge. Reimplement this method if you need to do some processing (such as dispose:ing a Region) before changing rooms.</blockquote> | ||
+ | |||
+ | ==== overlay: picture ==== | ||
+ | <blockquote>This method overlay a picture over the current picture.</blockquote> | ||
+ | </blockquote> | ||
| |
Revision as of 01:37, 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 Room Class
The Room class is the most specific Region. It is the point at which a picture, or 'scene' is defined for the player to walk around in.
In file: | game.sc |
Inherits from: | Region |
Inherited by: | none |
Properties
picture
The number of the picture corresponding to the room. Usually, this will just be the room number.
style
If style is specified, it overrides the global showStyle when picture is drawn during the Room's init:. Any other picture drawn once the Room is running must have its show style explicitly specified.
horizon
The y coordinate which is considered to be the room's horizon. Actors which have not had an ignoreHorizon: done on them cannot be positioned above this coordinate. Also, an Ego which hits this coordinate will have its edgeHit property set to northEdge.
blocks
A Set of software blocks (Blocks), rectangles which Actors are not allowed to enter.
north
east
south
west
The number of the room to which you wish to automatically change when ego hits the specified edge of the room. If you wish to control the room change yourself when ego hits a certain edge, do not specify the room for that edge in the Room instance and check (ego edgeHit?) yourself. The edgeHit property will have the value northEdge, southEdge, eastEdge, or westEdge if ego hit one of the edges.
controls
A set of dialog items (DItems) which are push-buttons for this
picAngle
This property is the angle above level that you are viewing the picture. It is used to set the global perspective upon room entry.
vanishingX
vanishingY
These are set according to where the vanishing point is in the picture to be shown. They determine the angle that the arrow keys will move ego in a room. The Up key will always move ego towards the vanishing point and the down arrow away. The default give a straight up and down in response to these keys.
Methods
init:
The default init: for a Room is to create an empty Set of Blocks, draw the picture specified by picture, and set ego's position based on its position in the previous room. You will want to supplement this with the following:
Load all views, sounds, pictures, etc. which will be required by the room so as to get all disk access done at Room initialization time.
Initialize all Actors and Actors which are to be in the Room initially.
Set a script for the Room.
Add any required Blocks to the Room.
doit:
Send the doit: message to this Room's script, if it has one, then check to see if ego has hit the edge of the Room. If ego has hit an edge and there is a room number specified for the edge, invoke the newRoom: method to change to that room.
dispose:
This is called by the game when changing from this Room to a new Room. The game handles disposing of the current cast, then does a (curRoom dispose:). The default dispose: simply disposes of the Room's script, blocks, and controls. You will want to supplement this to dispose: of anything else which you have created which is specific to the Room, and any modules which the Room has loaded.
setRegions: region [region ...]
Sets the Regions which contain this room. This should be invoked in the init: method of the room. The parameters region are the script numbers of the regions. They should be listed from most specific to most general, since the order in which they are listed is the order in which they will be invoked. Thus, for a room in Ulence Flats in Space Quest, we might write
(self setRegions: ULENCE_FLATS KERONA)
to say that we are in the town of Ulence Flats on the planet Kerona.
The global variable regions contains the ID of a List of regions which are sent the doit: and handleEvent: messages in order when appropriate. The newRoom: method of Game puts the current room at the head of this list, and setRegions: adds Regions to the end of the list in the order in which they are listed in the parameter list. If the Region was used in the previous Room, it will be neither reloaded nor reinitialized. At the end of the newRoom: method, all Regions in the list which do not refer to the current Room are deleted.
handleEvent: event
The default Room method passes the event along to the Room script (if there is one) and then to any controls in the room.
newRoom: n
This method is the one to use when changing Rooms. It is invoked when the Room automatically changes to a new Room when ego hits the edge. Reimplement this method if you need to do some processing (such as dispose:ing a Region) before changing rooms.
overlay: picture
This method overlay a picture over the current picture.
- Notes
< Previous: The Locale Class Next: The Timer Class >