home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / games2 / trellis / Instructs / Part5 < prev    next >
Encoding:
Text File  |  1994-09-12  |  13.8 KB  |  294 lines

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