home *** CD-ROM | disk | FTP | other *** search
/ APDL Soft Rock Games / APDL_SOFTROCK.iso / trellis / docs / part06 < prev    next >
Encoding:
Text File  |  1999-04-02  |  14.1 KB  |  303 lines

  1.                         TRELLIS - The Adventure Interpreter
  2.                       (c) copyright 1991-9 Soft Rock Software
  3.  
  4.                                Implementing Puzzles
  5.                                --------------------
  6.  
  7. Puzzles are an integral part of an adventure game. Without them the game
  8. would present no challenge to the player, except perhaps as a maze. There
  9. are all sorts of puzzles you can implement, many of which are variations
  10. on  a theme, and this section will show how to use the simplest types in a
  11. game. You will need to have read the sections, on Stores and  the TScript
  12. command set, since it's by using stores and TScript programming that you will
  13. add puzzles to your game.
  14.  
  15. One of the simplest puzzles to implement is a darkened room, in which the
  16. player must use a torch or some other source of light in order to see.
  17. This  has been mentioned before in these instructions, so will not be
  18. explained again - except to say that !Pyramid provides an example of this.
  19.  
  20. Another very simple puzzle is to define the amount a player can carry, by
  21. way of a weight limit. When this is done the player may only be able to
  22. carry, say, the sword if he/she drops the shield first, and so must decide
  23. which would be more useful. Again, this has been explained elsewhere in
  24. these instructions, so will not be covered here, except for...
  25.  
  26. Using the 'weight' idea, you could limit the player to carrying a certain
  27. *number* of items. Give each of the objects the player can carry a weight
  28. of 1 (in the Objects file) and at the start of your script file, use...
  29.  
  30. LET Store%(1)=5
  31.  
  32. (If the maximum number of objects the player can carry is 5)
  33.  
  34. The use of doors is another type of puzzle, and may well be one of the
  35. most  common puzzles found in adventure games. This is probably because
  36. doors are  very easy to code, as you can see from the following example:-
  37.  
  38. Suppose you want a door to lead North from room 15 to room 16. Firstly, to
  39. stop Trellis automatically telling the player that there's an exit North,
  40. you should not include a link between these two rooms in your rooms file -
  41. ie, there should be no 'N16' as part of the definition of room 15, or
  42. 'S15'  as part of room 16.
  43.  
  44. When the rooms are set up, North%(15) and South%(16) will both contain 0.
  45.  
  46. You can also lock the door. Do this by using one of the Store%()
  47. variables to contain, perhaps, 0 if the door is locked and -1 if unlocked.
  48. In this example, I'll use Store%(21). So, to ensure the door is locked
  49. include the following line near the start of your script:-
  50.  
  51. LET Store%(21)=0
  52.  
  53. With these initial components of the puzzle in place, you can now tell the
  54. player  about the door (if you want to). Somewhere after the 'LOOK'
  55. command in your TScript file you should  include something like this:-
  56.  
  57. IF Store%(3)=15 AND North%(15)=0 THEN PRINT" There is a closed door to the
  58. North"
  59. IF Store%(3)=16 AND South%(16)=0 THEN PRINT" There is a closed door to the
  60. South."
  61.  
  62. You will notice that I have not said whether or not the door is locked.
  63. This is because you can't normally tell if a door is locked just by
  64. looking at it. You have to try to open it to discover this fact.
  65.  
  66. So, you can allow the player to interact with the door. First of all, the
  67. door needs to be unlocked. Somewhere after the 'INPUT' command you need to
  68. include something like this:-
  69.  
  70. IF FNSaid("UNLOCK") AND FNSaid("DOOR") THEN
  71.  IF Store%(3)<>15 AND Store%(3)<>16 THEN GOTO you_cant
  72.  IF Location%(4)<>0 THEN GOTO you_cant
  73.  IF Store%(21)=-1 THEN GOTO you_cant
  74.  LET Store%(21)=-1
  75.  PRINT"You unlock the door."'
  76.  GOTO input_loop
  77. END IF
  78.  
  79. If the player enters the commands UNLOCK and DOOR Trellis will check
  80. various things, to see if the door can be unlocked.
  81.  
  82. Firstly, it checks to see if the player is at either room 15 or room 16 -
  83. the rooms that the door connects. If the player is not there, the door
  84. can't be opened so a jump is made to the 'you_cant' label - which simply
  85. tells the player 'You can't do that' and gets the next command.
  86.  
  87. Secondly, it checks to see if the player is carrying the key. (I have
  88. assumed for the purposes of this example that the key is object 4.) If so,
  89. the key's location will be 0. If it isn't the jump is again made to
  90. 'you_cant'
  91.  
  92. Thirdly, it checks that the door is locked. Obviously, it can't be
  93. unlocked if it is already so. Again, a jump might be made to 'you_cant'
  94.  
  95. These three checks could have been included on one line. When writing
  96. adventure games, it often pays to do this for reasons of speed. However,
  97. the line becomes long and spills over several screen lines, making it
  98. difficult to read. To make these instructions clearer I have, and will
  99. continue to split them up in this manner.
  100.  
  101. If you wanted, you could have more messages than the ubiquitous 'You can't
  102. do that.' You could tell the player he/she doesn't have the key, or isn't
  103. near a door, or that the door is already unlocked. To do this, however,
  104. splitting the checks up as I have done above becomes necessary since each
  105. IF statement checks for these particular circumstances.
  106.  
  107. Once these checks are carried out you know the player is able to unlock
  108. the door, so the contents of Store%(21) is changed to -1, a message is
  109. displayed on the screen for the player's benefit, and the script jumps to
  110. the input command.
  111.  
  112. To enable the player to open the door, the next section of script could be
  113. used, also after the 'INPUT' command:-
  114.  
  115. IF FNSaid("OPEN") AND FNSaid("DOOR") THEN
  116.  IF Store%(3)<>15 AND Store%(3)<>16 THEN GOTO you_cant
  117.  IF Store%(21)=0 THEN GOTO you_cant
  118.  IF North%(15)<>0 THEN GOTO you_cant
  119.  LET North%(15)=16
  120.  LET South%(16)=15
  121.  PRINT"You open the door."'
  122.  GOTO input_loop
  123. END IF
  124.  
  125. As you can see, the basic structure of this is similar to the script for
  126. unlocking the door, given above. The checks are made for the player being
  127. in one of the right rooms, the door being unlocked, and the door being
  128. already open respectively. The first two are fairly clear, but the third
  129. might need explaining:-
  130.  
  131. By not defining the exit N16 in the rooms file for room 15, and S15 for
  132. room 16, the variables North%(15) and South%(16) are set to 0 and Trellis
  133. won't let the player use them. When you open the door (which comes next)
  134. you change the contents of these two variables. Therefore, if one or the
  135. other of these stores contains 0 the door must be closed - hence the check
  136. to see if North%(15) contains 0.
  137.  
  138. So having made the various checks, the door can be opened by changing the
  139. contents of North%(15) (which leads to room 16) and South%(16) (which leads
  140. to room 15). A message is printed, and a jump is made to the input routine.
  141. The player can now move between the rooms freely. Trellis will handle this.
  142.  
  143. It's worth remembering that you can also redefine the room descriptions,
  144. by using LET Room$( )="..." To put this in the context of the above
  145. example, the original room descriptions could have included the messages
  146. about a closed door. When the door was opened, you could have changed the
  147. contents (of both room descriptions) to include a message about an open
  148. door.
  149.  
  150. If you look at the examples above, you will notice that I am allowing the
  151. player to open the door from both of the rooms it connects. You might
  152. think that if this is one of the puzzles in the game, the player will need
  153. to get past the door after first finding the key - which means he/she will
  154. only reach the door from the one side, so checking for both rooms is not
  155. necessary.
  156.  
  157. This is not so. If the player can unlock and open the door, it should also
  158. be possible to close and lock the door. The player could unlock the door,
  159. open it, go through it, close it and lock it again. This means he/she is
  160. now on the other side of the locked door, where the same procedures can be
  161. applied.
  162.  
  163. The script for closing and locking the door is very similar to that given
  164. above. I'll leave it to you to try and work it out for yourselves.
  165.  
  166. Obviously, the script given in this example would need to be expanded if
  167. there were more than one door.
  168.  
  169. Another easy type of puzzle to include are creatures (which, for the
  170. purposes of adventure games, can be anything you like, such as another
  171. person, a monster or even a robot of some kind - the word 'creature' is
  172. used for convenience.)
  173.  
  174. If a creature in your game is blocking an exit, so that the player can't
  175. get through until it has been killed, the creature can almost be programmed
  176. in as a door! The only exceptions are that the TScript program must check
  177. the condition of the creature (alive or dead) and inform the player as is
  178. appropriate. In terms of the example doors above, then, the script might
  179. become:-
  180.  
  181. IF Store%(3)=15 THEN
  182.  PRINT" There is a demonic creature to the North."
  183.  IF Store%(21)=1 THEN PRINT" It is blocking your exit in that direction."
  184.  IF Store%(21)=0 THEN PRINT" It is dead."
  185. END IF
  186. IF Store%(3)=16 THEN PRINT" There is a demonic creature to the South. It is
  187. dead."
  188.  
  189. Now, store 21 is being used to represent whether or not the creature is dead
  190. (0) or alive (1). Also, notice that the IF/END IF structure has been
  191. dropped from location 16 and replaced with a simple IF THEN. This is
  192. because the player can't get from 15 to 16 until the creature is killed so,
  193. if the player is at 16 we know the creature is dead. The exception to this
  194. would be if there were another route the player could take to get to
  195. location 16, in which case the creature wouldn't present much of a problem
  196. anyway!
  197.  
  198. The next section of script used above might become:-
  199.  
  200. IF FNSaid("KILL") AND FNSaid("CREATURE") THEN
  201.  IF Store%(3)<>15 THEN GOTO you_cant
  202.  IF Store%(21)<>1 THEN GOTO you_cant
  203.  IF Location%(2)<>0 THEN GOTO you_cant
  204.  LET Store%(21)=0
  205.  PRINT" You attack the creature with your sword. You kill it."
  206.  GOTO what_next
  207. END IF
  208.  
  209. The first thing you will notice is that the player commands checked for
  210. have been replaced - you don't want to pick a fight with the command UNLOCK
  211. DOOR! This script will jump to the 'you_cant' routine in three cases: if
  212. the player is not at location 15, if the creature is not alive, and if the
  213. player is not carrying a sword (which I have assumed to be object number 2).
  214. Otherwise the creature is killed.
  215.  
  216. With the code for doors described above, there were two stages to opening
  217. a door - unlocking it, then opening it. With creatures there is just one
  218. stage - killing it. So the next section of code must enable the player to
  219. move between the rooms if the creature is dead. Again, if the player is at
  220. location 16 the creature MUST be dead. This means that a link south (S15)
  221. can be included in the rooms file definition for location 16 to enable
  222. Trellis to deal with that direction automatically. To move North from
  223. location 15 to 16, the easiest method is to provide a link North (N16) and
  224. put this section of code somewhere after the INPUT command.
  225.  
  226. IF FNsaid("NORTH") THEN
  227.  IF Store%(3)=15 AND Store%(21)=1 THEN GOTO you_cant
  228.  GOTO process_command
  229. END IF
  230.  
  231. If the player enters NORTH, the software will give the 'you cant' message if
  232. he/she is at location 15 with the creature alive. Otherwise, control is
  233. passed to the routine labelled 'process_command' which simply calls COMMAND
  234. and lets Trellis do the work.
  235.  
  236. The creature is now implemented, but using a method based loosely on doors.
  237. This can be simplified further by defining the creature as two objects - the
  238. creature and a dead creature. This means that the store need not be used to
  239. represent whether or not the creature is dead or alive - with objects you
  240. check to see which object is in the room, creature or corpse:-
  241.  
  242. IF Location%(6)=Store%(3) THEN PRINT "The demon blocks the way North."
  243.  
  244. This is much simpler than before, because Trellis will tell the player if
  245. the creature is 'here' automatically, so you need only check that the
  246. creature is alive and inform the player that he/she can't go North because
  247. of it - which is done by comparing the creature's location (assuming it has
  248. been set up as object 6) with the players location, which is held in
  249. Store%(3).
  250.  
  251. And the next section:-
  252.  
  253. IF FNSaid("KILL") AND FNSaid("CREATURE") THEN
  254.  IF Location%(6)<>Store%(3) THEN GOTO you_cant
  255.  IF Location%(2)<>0 THEN GOTO you_cant
  256.  LET Location%(6)=-1
  257.  LET Location%(7)=15
  258.  PRINT" You attack the creature with your sword. You kill it."
  259.  GOTO what_next
  260. END IF
  261.  
  262. This time, you don't even check that the player is in room 15 since, if the
  263. demon is in the same place as the player, that is what matters. If it is,
  264. and the player carries the sword, the creature can be killed. The creature
  265. is moved out of play, by setting its location to -1, and the corpse is moved
  266. to room 15. The final section of script, to move the player about, becomes
  267. the following:-
  268.  
  269. IF FNSaid("NORTH") THEN
  270.  IF Location%(6)=Store%(3) THEN GOTO you_cant
  271.  GOTO process_command
  272. END IF
  273.  
  274. The IF in this section is slightly simpler than in the alternative version
  275. above, which means it will run fractionally quicker - but that isn't the
  276. only advantage for using this method. By defining the creature (and it's
  277. corpse) as objects the player can examine them, thus providing more
  278. information about them. However, it probably wouldn't pay for the player to
  279. be able to pick up the creature so you should give it a weight in excess of
  280. the limit the player can carry.
  281.  
  282. An additional point to remember is that you might want to make the creature
  283. more versatile than in the above example. Perhaps, when the player attacks
  284. the creature without a weapon the creature will kill the player. Or maybe
  285. the creature stays hidden until the player tries to move North, then reveals
  286. itself to stop him. Another possibility is that the creature is too strong
  287. to be killed by the player, so should be bribed - or weakened with some kind
  288. of poison. There are many possibilities.
  289.  
  290. Again, the code would have to be altered if you wanted more than one
  291. creature. If you are using the 'object' method, each creature should have
  292. its own set of objects. Alternatively, use a series of flags to represent
  293. whether or not the creatures are dead or alive and, whenever the player
  294. enters a room in which there would be a creature check the appropriate flag.
  295. If the creature is alive bring the 'alive' object into the room and if dead
  296. bring the 'dead' object. This way, you only need the two objects.
  297.  
  298. You may well realise by now that there are all sorts of things you could do
  299. to create a puzzle for the player to solve, and for each type of puzzle you
  300. think of there are probably a number of ways to do it. The simple ideas
  301. presented above should give you a start - the rest is up to you and your
  302. imagination.
  303.