Quote: "Hey! text on the screen yippee lol thx"
Np.
Quote: "Im still a wee bit confused, but ill look over it some more. I was wondering if, since I have the text game I want to make all planned out should I go ahead and make the layout with arrays? when you add items and such are you able to just add it onto the code?"
Well it's better to use files but you can use arrays till you learn about file loading.
Quote: "and if you explain items too me, could you also explain, unlocking doors and such, like you cant enter this room unless you had pressed the lever?"
Actually I've already covered it in the example. Room number 5 cannot be accessed at first because the direction for "in" is at -1 to block the player and give them the message "There doesn't appear to be a way inside the car.". Once the command "break window" is done in room number 4 the direction to get into the truck is changed from -1 to 5 so the player can access room number 5. The same thing can be done with anything at any location you want. You can make a button or switch teleport the player to another location, make the player 100 times stronger (carry more), open a door in any room (no matter how far away), create a stairway with vines, shrink the player, instantly kill them, or a slow painful death that kills them after 10 turns, anything you can think of.
Quote: "If you can add items right into the code, I think im ready for items. Ill be writing the arrays, for the game I have planned "
Ok I'll cover items... this is going to be long message.
Items are stored just like the rooms. All text is in one array and all item data is stored in another array.
` Dimensionalize the item text
dim Item$(20,7)
` Item$(xx,0) = Item Name
` Item$(xx,1) = Text shown for inventory
` Item$(xx,2) = Text shown for dropped item
` Item$(xx,3) - Item$(xx,7) = Item Description (5 lines max)
Item$(xx,0):
The first string stored is the item name which is used to recognize the item and manipulate it in the game.
Item$(xx,1):
The second string is what the player sees if the item is in their inventory.
Item$(xx,2):
The third string is what the player sees when the item is on the ground.
Item$(xx,3) to Item$(xx,7):
The last 5 strings is the item description shown when you look at the item. This is often where clues to puzzles are found by closely examining the item. I put this at 5 lines but it can be any length you need.
For the item data it can be as complicated as you want. The following is the main data an item would have for Infocom games:
` Dimensionalize the item data
dim Item(20,8)
` Item(xx,0) = Item Location room number or -ObjectNumber
` Item(xx,1) = Moveable Item 0 = No 1 = Yes
` Item(xx,2) = Object Weight
` Item(xx,3) = Wearable? 0 = No 1 = Yes but not worn 2 = Yes and being worn 3 = Yes and permanently attached
` Item(xx,4) = Container? 0 = No 1 = Yes and closed 2 = Yes and opened 3 = Yes and locked
` Item(xx,5) = Container weight limit
` Item(xx,6) = Current weight of items inside
` Item(xx,7) = Produces Light? 0 = No 1 = Yes but Off 2 = Yes and On 3 = Yes but burnt out
` Item(xx,8) = Number of turns item can produce light -1 = Unlimited
Item(xx,0):
The first and most important piece of item data is where the item is located (room number). Items that are in the players inventory can equal 1000... you can use any room number that wouldn't be used. Zero seems like a logical choice but zero should be used for destroyed and/or lost items (as the programmer you can add a way into room #0 to see all the lost or destroyed items). When an item is inside another item this number is no longer a room number but an item number... the way the computer knows its an item number rather than a room number is by using a negative number instead of a positive number (if this first piece of data is 1 the item is in room number 1... if it's -1 the item is inside item number 1).
Item(xx,1):
This determines if the item is movable or not ( 0 = No 1 = Yes). This gives you the ability to have item-like properties on things that cannot be picked up by the player for various reasons... like its too big, too heavy, or bolted to the floor. Non-movable items are not shown on the ground so the item must be mentioned in the room description where the item is placed. If it's not talked about in the room description the player won't know the item exists. All items you want the player to pick up and use will have a 1 stored in this piece of data.
Item(xx,2):
This stores the items weight. This really isn't vital but if you want containers its probably a good idea to keep it. When the player wants an item in a container it uses this number to determine if this item will fit in the container the player wants it in. This brings a bit of reality to the game. Without this a small sack can contain every single item in the game... no matter what the size.
Item(xx,3):
This stores if the item can be worn (0 = No 1 = Yes but not worn 2 = Yes and being worn 3 = Yes and permanently attached). Articles of clothing and jewelry would be the most common use for this stat. You can use this to only allow the player access to areas if their wearing a specific ring, gloves, hat, necklace, or something uncommon like orc skin. If you have an event where your player is knocked out and stripped of all items you can use this to keep what their wearing or only the items they can't remove. You can make it a puzzle to remove items that are "permanently attached".
Item(xx,4):
This determines if the item is a container (0 = No 1 = Yes and closed 2 = Yes and opened 3 = Yes and locked). This is given 4 options for the computer to quickly determine if this is able to hold items, if it's closed, if it's open, and if it's locked. When containers are in the players inventory if their open the contents of the item is shown. Generally if you have a container you always want it to start closed to give the game more reality. It gives the player something to look forward to revealing. The 4th option can be used to prevent the player from gaining access to the contents right away. Opening the locked item can be as difficult as you want or a simple as using a rock on it.
Item(xx,5):
This holds the weight limit of the container to prevent the player from putting any item they want in the container. This is vital for the next piece of data.
Item(xx,6):
This stores the current weight of the items inside the container. If the container starts with items you have to get the total weight of the items and put that number here. Without doing this initially for containers that start with items inside them a container that's technically full will still allow items stored in it beyond the max weight limit. When items are taken out or put into the container the item weight is subtracted from or added to this piece of data.
Item(xx,7):
This determines if the item is a light source (0 = No 1 = Yes but Off 2 = Yes and On 3 = Yes but burnt out). In all the Infocom games one of the best ways to prevent the player from going into certain areas is to require a light source. If they walk around too much in the dark they'll be eaten by Grues. This gives you the power to use the rooms light data "`Room(xx,12) = Light? 0=Dark 1=Lighted" or rather the lack of it to it's full potential.
Item(xx,8):
This is how many turns the light source will last if it's on. Every time the player makes a move with the light source on it'll reduce this number. To make the light source last forever make this -1.
Here are some items using the data structure above:
` Define Item #0
Item$(0,0)="whistle"
Item$(0,1)="an old whistle"
Item$(0,2)="On the ground is an old whistle."
Item$(0,3)="The whistle appears to be quite old and a bit rusty. On the back is "
Item$(0,4)="an almost worn off picture of a dog."
` Place Item #0 in room number 2
Item(0,0)=2
` The item can be moved
Item(0,1)=1
` The items weight is very light
Item(0,2)=1
` Define Item #1
Item$(1,0)="flashlight"
Item$(1,1)="a flashlight"
Item$(1,2)="On the floor is a flashlight."
Item$(1,3)="It looks like a common flashlight with a plastic case."
` Place Item #1 in room number 1
Item(1,0)=1
` The item can be moved
Item(1,1)=1
` The items weight is light
Item(1,2)=2
` The item produces light and is off
Item(1,7)=1
` The item has 100 turns worth of light
Item(1,8)=100
` Define Item #2 (unmovable item)
Item$(2,0)="jacket"
Item$(2,3)="The jacket is old and worn out. Being on a corpse probably doesn't help it"
Item$(2,4)="either. It has a single small pocket in the front."
` Place Item #2 in room number 5
Item(2,0)=5
` The item is a container
Item(2,4)=1
` Set the containers weight limit
Item(2,5)=4
` Set the current weight of the containers items
Item(2,6)=3
` Define Item #3
Item$(3,0)="note"
Item$(3,1)="a note"
Item$(3,2)="On the ground is a small note."
Item$(3,3)="It's a telegram:"
Item$(3,4)="Prof. Hawthorn. Please. Come. Immediately. STOP."
Item$(3,5)="Experiment. Almost. Out. Of. Control. STOP.
Item$(3,6)="Bring. Vial. And. Second. Vault. Key. Before. It. Escapes. STOP."
` Place Item #3 inside item #2
Item(3,0)=-2
` The item can be moved
Item(3,1)=1
` The items weight is very light
Item(3,2)=1
` Define Item #4
Item$(4,0)="vial"
Item$(4,1)="a vial"
Item$(4,2)="On the floor is a vile of mysterious liquid."
Item$(4,3)="It looks like the same kind of vial you'd see in movies with a"
Item$(4,4)="mad scientist. It has a rubber stopper at the top preventing"
Item$(4,5)="some purple liquid from escaping. On the side of the vial you see"
Item$(4,6)="a label with X-32.2381 written on it."
` Place Item #4 inside item #2
Item(4,0)=-2
` The item can be moved
Item(4,1)=1
` The items weight is very light
Item(4,2)=1
` Define Item #5
Item$(5,0)="key"
Item$(5,1)="a large key"
Item$(5,2)="A large key is on the ground."
Item$(5,3)="It's just like every other key you've seen except its twice the size."
` Place Item #5 inside item #2
Item(5,0)=-2
` The item can be moved
Item(5,1)=1
` The items weight is very light
Item(5,2)=1
Now the first thing we need to add is a way for the items to be seen. In Infocom games the items on the ground are after the room description... so adding a check to show items belongs in the same function but under the for/next loop for the room description. Also if the room has been visited before the items are still shown so the function needs to be modified accordingly.
The function before the changes:
function ShowRoom(RoomNumber)
` Show room number if Debug Mode is set to 1
if Player(0)=1 then Debug$=" ( Room Number "+str$(Player(1))+" )"
` Show the room name and room number (if debug mode is set to 1)
ShowText(Room$(RoomNumber,0)+Debug$)
` If the room has been visited before leave this function
if Room(RoomNumber,13)=1 then exitfunction
` Send all the lines that have text in the room description to the text scroller
for t=1 to 10
if Room$(RoomNumber,t)>" "
ShowText(Room$(RoomNumber,t))
endif
next t
` Set the map to show the room has been visited
Room(Player(1),13)=1
endfunction
The function after the changes (I got rid of "RoomNumber" and used "Player(1)" instead):
function ShowRoom()
` Show room number if Debug Mode is set to 1
if Player(0)=1 then Debug$=" ( Room Number "+str$(Player(1))+" )"
` Show the room name and room number (if debug mode is set to 1)
ShowText(Room$(Player(1),0)+Debug$)
` If the room has not been visited show the room description
if Room(Player(1),13)=0
` Send all the lines that have text in the room description to the text scroller
for t=1 to 10
if Room$(Player(1),t)>" "
ShowText(Room$(Player(1),t))
endif
next t
endif
` Go through all items
for t=0 to 20
` Check if the item location is the same as the room number
` and if the item is moveable
if Item(t,0)=Player(1) and Item(t,1)=1
` Send the item ground text to the text scroller
ShowText(Item$(t,2))
endif
next t
` Set the map to show the room has been visited
Room(Player(1),13)=1
endfunction
Next the player needs two more pieces of data... current weight and max weight. The player also needs a way to see his/her inventory. In Infocom games thats with the "inventory" command ("i" for short). The words need to be added to the word list and the new command added to the select/case in the "DoCommand()" function.
Words$(31)="inventory" : Words(31)=16
Words$(32)="i" : Words(32)=16
` Player(4) = Current Weight
` Player(5) = Max Weight
` Set max weight allowed for the player
Player(5)=20
` Inventory or I
case 16
` Check if the players current weight is more than zero
if Player(4)>0
` If it is send this message to the text scroller
ShowText("You are carrying:")
` Then go through all the items
for t=0 to 20
` If the item is in the inventory (room number = 1000)
if Item(t,0)=1000
` Send the inventory text to the text scroller
ShowText(" "+Item$(t,1))
endif
next t
else
` If the players current weight is zero then send this message to the text scroller
ShowText("You're not carrying anything.")
endif
endcase
The "inventory" command by itself isn't much without the ability to add to the inventory so we add the "take" command to the word list and add the new command to the "DoCommand()" function:
Words$(33)="take" : Words(33)=17
` Take
case 17
` Set FoundItem at -1 (because there is an item 0) and Item count at zero
FoundItem=-1
Items=0
` If the player didn't type a noun
if noun$=""
` Count the items in the room
for t=0 to 20
if Item(t,0)=Player(1)
` Make FoundItem = item in the room
FoundItem=t
` Increase item count
inc Items
endif
next t
` Check if there is at least 1 item in the room
if FoundItem>-1
` If there is only one item assume thats what the player wants
if Items=1
` Create a switch
Err=0
` Check if the item is already in the inventory
if Item(FoundItem,0)=1000
ShowText("You already have it.")
Err=1
endif
` Check if the item is in the room
if Item(FoundItem,0)<>Player(1) and Err=0
ShowText("I don't see that here.")
Err=1
endif
` Check if the item is movable
if Item(FoundItem,1)=0
ShowText("You can't take that.")
Err=1
endif
` Check if the players current weight + item weight is more than the players max weight
if Player(4)+Item(FoundItem,2)>Player(5)
ShowText("You can't carry anymore.")
Err=1
endif
` If no error above take the item
if Err=0
ShowText("("+Item$(FoundItem,0)+")")
ShowText("Taken.")
` Change item location to the players inventory
Item(FoundItem,0)=1000
` Add weight to players weight
Player(4)=Player(4)+Item(FoundItem,2)
endif
else
` Send this message if there are more than 1 item in the room
if Items>1 then ShowText("I can't make up your mind for you! Choose an item to pick up.")
endif
else
` If there are no items in the room
ShowText("You reach down to pick up nothing... your hand goes right though it.")
endif
else
` If a noun is typed by the player
` Go through all the items
for t=0 to 20
` Check if the noun equals the item name
if noun$=Item$(t,0)
` If it does make FoundItem equal the item number
FoundItem=t
` Exit the for/next loop (no need to go through the rest)
exit
endif
next t
if FoundItem>-1
` Reset the error switch
Err=0
` Check if the item is already in the inventory
if Item(FoundItem,0)=1000
ShowText("You already have it.")
Err=1
endif
` Check if the item is in the room
if Item(FoundItem,0)<>Player(1) and Err=0
ShowText("I don't see that here.")
Err=1
endif
` Check if the found item is non-moveable
if Item(FoundItem,1)=0
ShowText("You can't take that.")
Err=1
endif
` Check if the players current weight + item weight is more than the players max weight
if Player(4)+Item(t,2)>Player(5)
ShowText("You can't carry anymore.")
Err=1
endif
` Check the switch to see if it's still zero
if Err=0
` Send the taken message to the text scroller
ShowText("Taken.")
` Change the item found location to 1000 (the players inventory)
Item(FoundItem,0)=1000
` Add the items weight to the players current weight
Player(4)=Player(4)+Item(FoundItem,2)
endif
endif
` If a noun is there but not found in the list send this message to the text scroller
if FoundItem=-1
ShowText("You can't take that.")
endif
endif
endcase
The above "take" command has two parts. One that will take an item if no noun is typed and if there is only one item in the room. The other part will take items when the item name is typed in. Both parts have identical checks to make sure the item is in the room or on the player already, if the item can be picked up, and if picking up the item will go over the max weight limit for the player. It's complicated but its made that way to mimic the way Infocom games treat items.
Once items are in the inventory we need to add the "drop" command to remove items and place them in the current room.
Words$(34)="drop" : Words(34)=18
` Drop
case 18
` Set FoundItem to -1 (because there is an item 0)
FoundItem=-1
` If a noun has been typed
if noun$>""
` Go through all items
for t=0 to 20
` Check if the noun equals the item name
if noun$=Item$(t,0)
` If it does make FoundItem equal the item number
FoundItem=t
` Exit the for/next loop (no need to go through the rest)
exit
endif
next t
if FoundItem>-1
` Create a switch
Err=0
` Check if the item is not in the players inventory
if Item(FoundItem,0)<1000
ShowText("You aren't carrying that.")
Err=1
endif
` Drop the item
if Err=0
ShowText("Dropped.")
` Make the items location the current room number
Item(FoundItem,0)=Player(1)
` Take away the items weight from the players weight
Player(4)=Player(4)-Item(FoundItem,2)
endif
else
` If a noun is used but not found in the item list send this message to the text scroller
ShowText("I don't even know what that is.")
endif
else
` If no noun is used send this message to the text scroller
ShowText("You have to be more specific on what you want to drop.")
endif
endcase
The "drop" command is less complicated because the only check thats really needed is if the item is on the player.
Well... that's items in a nutshell. I'll cover container opening, closing, and taking items from containers in another message in a few days. One thing I didn't cover that you might want to try yourself (before I show you) is looking at the items. If you have any questions/comments I'll be happy to answer them.
Here's the previous example with the new code:
` Grog Grueslayers Quick and Dirty Text Adventure (Infocom Style)
` Newest Post: 2-8-07 Made in Pro edited to work in Classic
` Turn on syning so the ShowText function doesn't sync after each line printed
sync rate 0
sync on
` Don't need the mouse in a standard text adventure
hide mouse
` Set text to overwrite previous text (used mainly for the status bar)
set text opaque
` Dimensionalize the array to store the map
dim Room(20,13)
` xx = Room Number
` Room(xx,0) = North
` Room(xx,1) = South
` Room(xx,2) = West
` Room(xx,3) = East
` Room(xx,4) = NorthWest
` Room(xx,5) = NorthEast
` Room(xx,6) = SouthWest
` Room(xx,7) = SouthEast
` Room(xx,8) = Up
` Room(xx,9) = Down
` Room(xx,10) = In
` Room(xx,11) = Out
` Room(xx,12) = Light? 0=Dark 1=Lighted
` Room(xx,13) = Visited? 0=Not Visited 1=Visited
` Dimensionalize the array to store room text
dim Room$(20,10)
` xx = Room Number
` Room$(xx,0) = Room Name
` Room$(xx,1) through Room$(xx,10) = Room Description
` Define the map and room text (this is where you load it from a text file)
` Room Number 1 (it's best to not use room number zero because zeros show no room in the map
Room$(1,0)="Forest Clearing"
Room$(1,1)="Your in a clearing. All around you are twisted dark evil looking trees."
Room$(1,2)="There is but one obvious exit to the north."
` Change map to show room 2 is north of room 1
Room(1,0)=2
` Room 1 has light in it
Room(1,12)=1
` Room Number 2
Room$(2,0)="Dark Path"
Room$(2,1)="This path appears to be used quite often. There are tracks of many animals on"
Room$(2,2)="the ground. Some of the tracks are quite large. You hope you don't run into"
Room$(2,3)="any of them. The path leads to the north and south."
` Change map to show room 3 is north of room 2
Room(2,0)=3
` Change map to show room 1 is south of room 2
Room(2,1)=1
` Room 2 has light in it
Room(2,12)=1
` Room Number 3
Room$(3,0)="Abandoned Car"
Room$(3,1)="High above you in the trees is an old rusted car. The car is wedged between"
Room$(3,2)="the trees main 2 branches. The path continues to the north and south. There"
Room$(3,3)="is a vine hanging down."
` Change map to show a special block to the north
Room(3,0)=-2
` Change map to show room 2 is south of room 3
Room(3,1)=2
` Change map to show room 4 is up from room 3
Room(3,8)=4
` Room 3 has light in it
Room(3,12)=1
` Room Number 4
Room$(4,0)="Outside of Car"
Room$(4,1)="Hanging off the vine you can see the car closer. Its an old Ford with dust"
Room$(4,2)="covered windows all closed. You can't make out whats inside the car. The"
Room$(4,3)="only exit is down the vine."
` Change map to show a special block for the in direction
Room(4,10)=-1
` Change map to show room 3 is down from room 4
Room(4,9)=3
` Room 4 has light in it
Room(4,12)=1
` Room Number 5
Room$(5,0)="Inside of Car"
Room$(5,1)="This is an ordinary car except your sitting on a partially decomposed corpse."
Room$(5,2)="The body appears to be tall male wearing sunglasses, a green jacket, wranglers,"
Room$(5,3)="and snakeskin boots. The only exit is out through the broken window."
` Change map to show room 4 is out from room 5
Room(5,11)=4
` Room 5 has light in it
Room(5,12)=1
` Dimensionalize the item text
dim Item$(20,7)
` Item$(xx,0) = Item Name
` Item$(xx,1) = Text shown for inventory
` Item$(xx,2) = Text shown for dropped item
` Item$(xx,3) - Item$(xx,7) = Item Description (5 lines max)
` Dimensionalize the item data
dim Item(20,8)
` Item(xx,0) = Item Location room number or -ObjectNumber
` Item(xx,1) = Moveable Item 0 = No 1 = Yes
` Item(xx,2) = Object Weight
` Item(xx,3) = Wearable? 0 = No 1 = Yes but not worn 2 = Yes and being worn 3 = Yes and permanently attached
` Item(xx,4) = Container? 0 = No 1 = Yes and closed 2 = Yes and opened 3 = Yes and locked
` Item(xx,5) = Container weight limit
` Item(xx,6) = Current weight of items inside
` Item(xx,7) = Produces Light? 0 = No 1 = Yes but Off 2 = Yes and On 3 = Yes but burnt out
` Item(xx,8) = Number of turns item can produce light -1 = Unlimited
` Define Item #0
Item$(0,0)="whistle"
Item$(0,1)="an old whistle"
Item$(0,2)="On the ground is an old whistle."
Item$(0,3)="The whistle appears to be quite old and a bit rusty. On the back is "
Item$(0,4)="an almost worn off picture of a dog."
` Place Item #0 in room number 2
Item(0,0)=2
` The item can be moved
Item(0,1)=1
` The items weight is very light
Item(0,2)=1
` Define Item #1
Item$(1,0)="flashlight"
Item$(1,1)="a flashlight"
Item$(1,2)="On the floor is a flashlight."
Item$(1,3)="It looks like a common flashlight with a plastic case."
` Place Item #1 in room number 1
Item(1,0)=1
` The item can be moved
Item(1,1)=1
` The items weight is light
Item(1,2)=2
` The item produces light and is off
Item(1,7)=1
` The item has 100 turns worth of light
Item(1,8)=100
` Define Item #2 (unmovable item)
Item$(2,0)="jacket"
Item$(2,3)="The jacket is old and worn out. Being on a corpse probably doesn't help it"
Item$(2,4)="either. It has a single small pocket in the front."
` Place Item #2 in room number 5
Item(2,0)=5
` The item is a container
Item(2,4)=1
` Set the containers weight limit
Item(2,5)=4
` Set the current weight of the containers items
Item(2,6)=3
` Define Item #3
Item$(3,0)="note"
Item$(3,1)="a note"
Item$(3,2)="On the ground is a small note."
Item$(3,3)="It's a telegram:"
Item$(3,4)="Prof. Hawthorn. Please. Come. Immediately. STOP."
Item$(3,5)="Experiment. Almost. Out. Of. Control. STOP."
Item$(3,6)="Bring. Vial. And. Second. Vault. Key. Before. It. Escapes. STOP."
` Place Item #3 inside item #2
Item(3,0)=-2
` The item can be moved
Item(3,1)=1
` The items weight is very light
Item(3,2)=1
` Define Item #4
Item$(4,0)="vial"
Item$(4,1)="a vial"
Item$(4,2)="On the floor is a vile of mysterious liquid."
Item$(4,3)="It looks like the same kind of vial you'd see in movies with a"
Item$(4,4)="mad scientist. It has a rubber stopper at the top preventing"
Item$(4,5)="some purple liquid from escaping. On the side of the vial you see"
Item$(4,6)="a label with X-32.2381 written on it."
` Place Item #4 inside item #2
Item(4,0)=-2
` The item can be moved
Item(4,1)=1
` The items weight is very light
Item(4,2)=1
` Define Item #5
Item$(5,0)="key"
Item$(5,1)="a large key"
Item$(5,2)="A large key is on the ground."
Item$(5,3)="It's just like every other key you've seen except its twice the size."
` Place Item #5 inside item #2
Item(5,0)=-2
` The item can be moved
Item(5,1)=1
` The items weight is very light
Item(5,2)=1
` Dimensionalize an array to store words
dim Words$(50)
` Dimensionalize an array to store word numbers
dim Words(50)
` Define the words (also should be loaded from a file)
` Words$(xx) = Word Words(xx)= Word Number
` Same word numbers = same meaning
Words$(0)="north" : Words(0)=0
Words$(1)="n" : Words(1)=0
Words$(2)="south" : Words(2)=1
Words$(3)="s" : Words(3)=1
Words$(4)="west" : Words(4)=2
Words$(5)="w" : Words(5)=2
Words$(6)="east" : Words(6)=3
Words$(7)="e" : Words(7)=3
Words$(8)="northwest" : Words(8)=4
Words$(9)="nw" : Words(9)=4
Words$(10)="northeast" : Words(10)=5
Words$(11)="ne" : Words(11)=5
Words$(12)="southwest" : Words(12)=6
Words$(13)="sw" : Words(13)=6
Words$(14)="southeast" : Words(14)=7
Words$(15)="se" : Words(15)=7
Words$(16)="up" : Words(16)=8
Words$(17)="u" : Words(17)=8
Words$(18)="down" : Words(18)=9
Words$(19)="d" : Words(19)=9
Words$(20)="in" : Words(20)=10
Words$(21)="enter" : Words(21)=10
Words$(22)="out" : Words(22)=11
Words$(23)="exit" : Words(23)=11
Words$(24)="look" : Words(24)=12
Words$(25)="l" : Words(25)=12
Words$(26)="break" : Words(26)=13
Words$(27)="destroy" : Words(27)=13
Words$(28)="hit" : Words(28)=13
Words$(29)="open" : Words(29)=14
Words$(30)="quit" : Words(30)=15
Words$(31)="inventory" : Words(31)=16
Words$(32)="i" : Words(32)=16
Words$(33)="take" : Words(33)=17
Words$(34)="drop" : Words(34)=18
` Dimensionalize an array to store the text on the screen (for scrolling)
dim Tex$(29)
` Create an array to store the player data
` This is where you store all variables associated to
` the world (besides the map and inventory). Like if
` you had a fountain full of acid and you want a switch
` to control the acid level you place it in the player
` data. This is so you can quickly save/load a game
` without needing to remember to save each separate variable.
dim Player(5)
` Player(0) = Debug Mode
` Player(1) = Current Room Number
` Player(2) = Score
` Player(3) = Number of Moves
` Player(4) = Current Weight
` Player(5) = Max Weight
` Set Debug Mode ( this is a way to print stuff going on
` in the game that you want to view and/or track)
` When you don't want to track anything make this zero
Player(0)=0
` Player(0)=0 - Debug Mode Off
` Player(0)=1 - Show Room Numbers
` Player(0)=2 - Show verb$ and noun$
` Set starting Room Number
Player(1)=1
` Set max weight allowed for the player
Player(5)=20
` Call the function to show the current room
ShowRoom()
` Add a blank line to the text scroller
ShowText("")
do
` Call the function to get user input
GetCommand()
loop
end
function ShowRoom()
` Show room number if Debug Mode is set to 1
if Player(0)=1 then Debug$=" ( Room Number "+str$(Player(1))+" )"
` Show the room name and room number (if debug mode is set to 1)
ShowText(Room$(Player(1),0)+Debug$)
` If the room has not been visited show the room description
if Room(Player(1),13)=0
` Send all the lines that have text in the room description to the text scroller
for t=1 to 10
if Room$(Player(1),t)>" "
ShowText(Room$(Player(1),t))
endif
next t
endif
` Go through all items
for t=0 to 20
` Check if the items location is the same as the room number
` and if the item is moveable
if Item(t,0)=Player(1) and Item(t,1)=1
` Send the item ground text to the text scroller
ShowText(Item$(t,2))
endif
next t
` Set the map to show the room has been visited
Room(Player(1),13)=1
endfunction
` Get the user input and take out first and last words
function GetCommand()
` Show a blank command line to have a space between the last text block and the next one
ShowText(">")
` Put input at the bottom of the screen
set cursor 0,464
` Get input from the user
input "> ",c$
` Send user input to the text scroller
ShowText("> "+c$)
` Make sure the user input is lowercase
c$=lower$(c$)
` Create a switch ( 0 = no spaces found 1 = space found)
Space=0
` Check for any spaces
for t=1 to len(c$)
if mid$(c$,t)=" " then Space=1
next t
` Add a space if there is none
` Without this a single word won't be seen
if Space=0 then c$=c$+" "
` Cut off the first word and store it as v$
for t=1 to len(c$)
` Check for the first space
if mid$(c$,t)=" "
` Make v$ equal the first word
v$=left$(c$,t-1)
` Exit the for/next loop
exit
endif
next t
` Cut off the last word and store it as n$
for t=len(c$) to 1 step -1
` Check for the first space
if mid$(c$,t)=" "
` Make n$ equal the last word
n$=right$(c$,len(c$)-t)
` Exit the for/next loop
exit
endif
next t
` Clear the noun if there is only a single word
` If this isn't done both the verb and the noun are
` the same. The noun needs to be empty for other checks.
if Space=0 then n$=""
` Show the verb and noun if debug mode is set to 2
if Player(0)=2
ShowText("Verb = "+v$)
ShowText("Noun = "+n$)
endif
` Call the function to check the command entered by the user
DoCommand(v$,n$)
endfunction
` Do the command of the user
function DoCommand(verb$,noun$)
` Increase player moves (this is easier than adding
` this to every single word... decrease when a move
` isn't done)
Player(3)=Player(3)+1
` Make verb$ = noun$ if "go" "run" or "walk" is used
if verb$="go" or verb$="run" or verb$="walk"
verb$=noun$
endif
` Set the current word to a word that won't be in
` the list (this is in case the word is not found
` so it'll go to default)
CWord=500
` Go through all the words
for t=0 to 50
` If verb$ equals the word stored in Words$(t)
if verb$>"" and verb$=Words$(t)
` Make CWord = the word number in Words(t)
CWord=Words(t)
` Exit the for/next loop
exit
endif
next t
` Find the word number
select CWord
` North, N
case 0
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` South, S
case 1
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` West, W
case 2
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` East, E
case 3
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Northwest, NW
case 4
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Northeast, NE
case 5
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Southwest, SW
case 6
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Southeast, SE
case 7
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Up, U
case 8
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Down, D
case 9
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` In, Enter
case 10
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Out, Exit
case 11
` Check if the north direction is more than zero
if Room(Player(1),CWord)>0
` If yes change the current room number to the room number
` stored in the north direction
Player(1)=Room(Player(1),CWord)
` Show the new current room
ShowRoom()
else
` If it's anything else call the blocked movement function
` with the number in the north direction
BlockMovement(Room(Player(1),CWord))
endif
endcase
` Look
case 12
` Change current room to show as unvisited
Room(Player(1),13)=0
` Show the room
ShowRoom()
endcase
` Break, destroy, or hit
case 13
` Check if there is a noun
if noun$=""
ShowText("Since you didn't say what you want to "+verb$+" I'll assume you mean your own arm.")
ShowText("What's that? You don't want me to do that? You're no fun! <hrumph>")
` Decrease moves to negate added move at top of function
Player(3)=Player(3)-1
endif
` Create a switch to check if the nouns have been found
FoundNoun=0
` Check if the current room is outside of the car (room number 4)
if Player(1)=4
` Check the noun for "window"
if noun$="window"
` Turn on the switch
FoundNoun=1
` Check if the window is already broken
if Room(4,10)=5
ShowText("Your hand hurts too much to try to break anymore windows.")
endif
` Check if the window has not been broken
if Room(4,10)=-1
ShowText("Your hand goes straight though the window... ouch! A horrible stench bellows")
ShowText("from the car.")
` Change the map to open up a way into the car
Room(4,10)=5
` Change the last lines in the room description of room 4
Room$(4,2)="covered windows all closed except a broken driver side window. Just inside"
Room$(4,3)="the car is the corpse of the cars last driver. The exits are down the vine"
Room$(4,4)="and into the car."
` Increase the score for breaking the window
Player(2)=Player(2)+5
endif
endif
` Check the noun for "car" or "truck"
if noun$="car" or noun$="truck"
` Turn on the switch
FoundNoun=1
ShowText("Bam! You hit car door with your fist. Your hand really hurts and nothing is")
ShowText("accomplished. You should try to control your anger.")
endif
endif
` If no noun is found and a noun was actually written do this
` This assures that this verb will always show some kind of results if it's used
` with a noun.
if FoundNoun=0 and noun$>""
ShowText("I don't know how to "+verb$+" that.")
endif
endcase
` Open
case 14
` Check if there is a noun
if noun$=""
ShowText("Am I a mind reader? Tell me that again with what you actually want to open.")
` Decrease moves to negate added move at top of function
Player(3)=Player(3)-1
endif
` Create a switch to check if the nouns have been found
FoundNoun=0
` Check the noun "door" and if the current room is room number 4
if noun$="door" and Player(1)=4
` Turn on the switch
FoundNoun=1
ShowText("You try as hard as you can but the door doesn't budge. I doubt even Arnold")
ShowText("Schwarzenegger could do it either. The door is rusted shut.")
endif
` If no noun is found and a noun was actually written do this
` This assures that this verb will always show some kind of results if it's used
` with a noun.
if FoundNoun=0 and noun$>""
ShowText("I don't know how to open that.")
endif
endcase
` Quit
case 15
` Decrease moves to negate added move at top of function
Player(3)=Player(3)-1
ShowText("You managed to get "+str$(Player(2))+" out of a possible 500 points in "+str$(Player(3))+" moves.")
` Check the rankings
if Player(2)=0 then Rank$="Pathetic Looser"
if Player(2)=>5 then Rank$="Village Bum"
` Print the rank
ShowText("You achieved the rank of "+Rank$+".")
ShowText("")
ShowText("Press any key to quit.")
wait key
end
endcase
` Inventory or I
case 16
` Check if the players current weight is more than zero
if Player(4)>0
` If it is send this message to the text scroller
ShowText("You are carrying:")
` Then go through all the items
for t=0 to 20
` If the item is in the inventory (room number = 1000)
if Item(t,0)=1000
` Send the inventory text to the text scroller
ShowText(" "+Item$(t,1))
endif
next t
else
` If the players current weight is zero then send this message to the text scroller
ShowText("You're not carrying anything.")
endif
endcase
` Take
case 17
` Set FoundItem at -1 (because there is an item 0) and Item count at zero
FoundItem=-1
Items=0
` If the player didn't type a noun
if noun$=""
` Count the items in the room
for t=0 to 20
if Item(t,0)=Player(1)
` Make FoundItem = item in the room
FoundItem=t
` Increase item count
inc Items
endif
next t
` Check if there is at least 1 item in the room
if FoundItem>-1
` If there is only one item assume thats what the player wants
if Items=1
` Create a switch
Err=0
` Check if the item is already in the inventory
if Item(FoundItem,0)=1000
ShowText("You already have it.")
Err=1
endif
` Check if the item is in the room
if Item(FoundItem,0)<>Player(1) and Err=0
ShowText("I don't see that here.")
Err=1
endif
` Check if the item is movable
if Item(FoundItem,1)=0
ShowText("You can't take that.")
Err=1
endif
` Check if the players current weight + item weight is more than the players max weight
if Player(4)+Item(FoundItem,2)>Player(5)
ShowText("You can't carry anymore.")
Err=1
endif
` If no error above take the item
if Err=0
ShowText("("+Item$(FoundItem,0)+")")
ShowText("Taken.")
` Change item location to the players inventory
Item(FoundItem,0)=1000
` Add weight to players weight
Player(4)=Player(4)+Item(FoundItem,2)
endif
else
` Send this message if there are more than 1 item in the room
if Items>1 then ShowText("I can't make up your mind for you! Choose an item to pick up.")
endif
else
` If there are no items in the room
ShowText("You reach down to pick up nothing... your hand goes right though it.")
endif
else
` If a noun is typed by the player
` Go through all the items
for t=0 to 20
` Check if the noun equals the item name
if noun$=Item$(t,0)
` If it does make FoundItem equal the item number
FoundItem=t
` Exit the for/next loop (no need to go through the rest)
exit
endif
next t
if FoundItem>-1
` Reset the error switch
Err=0
` Check if the item is already in the inventory
if Item(FoundItem,0)=1000
ShowText("You already have it.")
Err=1
endif
` Check if the item is in the room
if Item(FoundItem,0)<>Player(1) and Err=0
ShowText("I don't see that here.")
Err=1
endif
` Check if the found item is non-moveable
if Item(FoundItem,1)=0
ShowText("You can't take that.")
Err=1
endif
` Check if the players current weight + item weight is more than the players max weight
if Player(4)+Item(t,2)>Player(5)
ShowText("You can't carry anymore.")
Err=1
endif
` Check the switch to see if it's still zero
if Err=0
` Send the taken message to the text scroller
ShowText("Taken.")
` Change the item found location to 1000 (the players inventory)
Item(FoundItem,0)=1000
` Add the items weight to the players current weight
Player(4)=Player(4)+Item(FoundItem,2)
endif
endif
` If a noun is there but not found in the list send this message to the text scroller
if FoundItem=-1
ShowText("You can't take that.")
endif
endif
endcase
` Drop
case 18
` Set FoundItem to -1 (because there is an item 0)
FoundItem=-1
` If a noun has been typed
if noun$>""
` Go through all items
for t=0 to 20
` Check if the noun equals the item name
if noun$=Item$(t,0)
` If it does make FoundItem equal the item number
FoundItem=t
` Exit the for/next loop (no need to go through the rest)
exit
endif
next t
if FoundItem>-1
` Create a switch
Err=0
` Check if the item is not in the players inventory
if Item(FoundItem,0)<1000
ShowText("You aren't carrying that.")
Err=1
endif
` Drop the item
if Err=0
ShowText("Dropped.")
` Make the items location the current room number
Item(FoundItem,0)=Player(1)
` Take away the items weight from the players weight
Player(4)=Player(4)-Item(FoundItem,2)
endif
else
` If a noun is used but not found in the item list send this message to the text scroller
ShowText("I don't even know what that is.")
endif
else
` If no noun is used send this message to the text scroller
ShowText("You have to be more specific on what you want to drop.")
endif
endcase
` If a word was not found above do this
case default
` Pick a random number
a=rnd(5)
if a=0 then ShowText("What?")
if a=1 then ShowText("That's illogical captain.")
if a=2 then ShowText("I don't know the word "+verb$+".")
if a=3 then ShowText("What planet are you from again?")
if a=4 then ShowText("That's disgusting!")
if a=5 then ShowText("Does your mother know you talk like that?")
` Decrease moves to negate added move at top of function
Player(3)=Player(3)-1
endcase
endselect
` Add a space to make it look better
ShowText("")
endfunction
` Show blocked movement
function BlockMovement(Num)
select Num
` Normal block
case 0
ShowText("You can't go that way.")
endcase
` Special block number 1 (outside of car before window broken)
case -1
ShowText("There doesn't appear to be a way inside the car.")
endcase
` Special block number 2
case -2
ShowText("A huge tree suddenly sprouts up and blocks your way.")
endcase
endselect
endfunction
` Show all the text on the screen (after adding a new line)
function ShowText(NewString$)
` Create a switch ( 0 = off 1 = on )
Replace=0
` Check the new line to see if it's a command line
if left$(NewString$,1)=">" and len(NewString$)>1
` Turn the switch on
Replace=1
` Replace the blank command line with the command line with user input
Tex$(29)=NewString$
endif
` If the new line is not a command line scroll up
if Replace=0
` Redefine each line to equal the one before it
for t=1 to 29
Tex$(t-1)=Tex$(t)
next t
` Add the last line
Tex$(29)=NewString$
endif
` Clear the screen
cls
y=0
` Rewrite all the text
for t=0 to 29
text 0,y,Tex$(t)
inc y,16
next t
` Show the status bar at the top
ink 0,rgb(200,200,200)
` Show blank bar
text 0,0," "
` Show the current room name
text 5,0,Room$(Player(1),0)
` Show current score
text 430,0,"Score: "+str$(Player(2))
` Show current moves
text 530,0,"Moves: "+str$(Player(3))
` Reset ink color to normal
ink rgb(255,255,255),0
sync
endfunction
