Hi guys…
Following on from thread on text input, this is where I’m up to with a ‘very’ basic adventure game. Atm it just has a working map and location descriptions. I want to introduce objects next and this is my query.
It seems logical to put them in the room tables, but I also want to give them attributes e.g. certain objects can’t be taken, some are initially hidden until discovered and so on… I’m not sure I can do this within the room table.
So next thought was an objects table… objects={lamp=3, key=9… etc} where the number is the initial location, but again I can’t have more than the one attribute can I?
So then I considered objects={lamp,key,rope…} objRooms={3,9,5…} objHidden={0,0,1…} This latter choice is harder to keep track of but seems more flexible.
I’m sure there is an ideal way of dealing with this, so before I get completely lost, any ideas?
Thanks!
--# Main
-- Adventure 2.1
function setup()
displayMode(FULLSCREEN)
font("Courier")
textWrapWidth(WIDTH-50)
strTab={"WELCOME to Islands of Adventure v2.1, an interactive adventure game. This is a basic framework with a simple working map, but you can only type in simple direction commands, n,s,e,w,u,d.\
\
FOREST\
You are deep inside a dark forest. The undergrowth makes it very difficult to wander off a path that leads to the North.\
There appears to be something hidden in the bushes to your left."}
buffer=""
showKeyboard()
textMode(CORNER)
str=0
map()
end
function draw()
background(30,30,0,255)
fill(255)
text(">",30,400)
if buffer~="" then
text(buffer,45,400)
end
lineSize=0
for z=#strTab,1,-1 do
if (z+1)%2==0 then
fill(255,255,0)
text(strTab[z],30,465+lineSize)
else
fill(255)
text("> "..strTab[z],30,465+lineSize)
end
w,h=textSize(strTab[z])
lineSize=lineSize+h
end
end
function touched()
showKeyboard()
end
function keyboard(key)
if key == RETURN then
table.insert(strTab,buffer)
buffer=""
input=strTab[2*(str+1)]
parse(input)
elseif key==BACKSPACE then
buffer=string.sub(buffer,1,string.len(buffer)-1)
else
buffer=buffer..key
end
end
--# Map
function map()
room={}
myLoc=1
room[1]={n=4,s=0,e=2,w=0,u=0,d=0,name="FOREST",desc="#1 You are lost in a dark, dense forest."}
room[2]={n=5,s=0,e=3,w=1,u=10,d=0,name="CLEARING",desc="#2 You are standing in a clearing. There is a large oak tree in the middle."}
room[3]={n=6,s=0,e=0,w=2,u=0,d=0,name="CAVE",desc="#3 You are in a cold damp cave."}
room[4]={n=7,s=1,e=5,w=0,u=0,d=0,name="BEACH",desc="#4 You are on a warm sandy beach."}
room[5]={n=8,s=2,e=6,w=4,u=0,d=0,name="HUT",desc="#5 You are stood inside a small beach hut."}
room[6]={n=9,s=3,e=0,w=5,u=0,d=0,name="WATERFALL",desc="#6 You are standing under a waterfall. There is a small opening behind you."}
room[7]={n=0,s=4,e=8,w=0,u=0,d=0,name="CLIFF",desc="#7 You are standing at the base of a steep cliff."}
room[8]={n=0,s=5,e=9,w=7,u=0,d=0,name="SEA",desc="#8 You are splashing around in the sea."}
room[9]={n=0,s=6,e=0,w=8,u=0,d=0,name="BOAT",desc="#9 You are in a small rowing boat."}
room[10]={n=0,s=0,e=0,w=0,u=0,d=2,name="TREE TOP",desc="#10 Wow... a wonderful view of the entire island. It's not very big."}
end
--# Parser
function parse(input)
print(strTab[2*(str+1)])
if input~="n" and input~="s" and input~="e" and input~="w" and input~="u" and input~="d" then
table.insert(strTab, "Sorry, but I don't understand what you mean? For now just stick with basic directions.")
elseif room[myLoc][input]==0 then
table.insert(strTab, "You can't go in that direction")
else myLoc=(room[myLoc][input])
table.insert(strTab,room[myLoc].name.."\
"..room[myLoc].desc)
end
str=str+1
end