I made this text adventure engine for the TACompetition ending in middle October. Now you can use it for the competition, or you can modify it for use in the competition.
I made it so that you can modify it entirely with a lua script outside the main engine. So you don't have to modify the engine at all, just start programming your incredible text game for the TACompetition!
Here is the code:
Rem Project: Text Adventure Engine
Rem Created: 6/20/2008 11:40:00 PM
Rem ***** Main Source File *****
remstart
Make it lua based so the game accesses a lua file for everything
LUA file should be called game.txt
write it out like:
game = {}
game[100] = {
howManyChoices = 2,
choices = {
200,
500
},
storyText = "You happen across a great tree that stands before an entrance, what do you do?",
choicesText {
"1) talk to tree",
"2) walk to the entrance ignoring tree"
},
points = 1
}
The engine would see that there are two choices. It would read the text on the screen
using a text parser for proper length on the screen then it would list the different
choices. Then the player chooses what they want to do and the engine reads the 'choices'
and knows where to go. If the player chooses to do 2, and walk to the entrance ignoring
the tree, then the engine would go to scene 500. But if the player chooses to talk to the
tree, then the engine would go to scene 200. This is a very simple engine requiring only
a great deal of text. Enjoy adventuring!
There is also a new feature I call the commands feature. You can script in special commands
that will activate when you reach a certain scene number, such as a sound or a graphic.
SendMessageS("22","sound")
SendMessageS("loud thump.wav","1")
SendMessageS("22","graphic")
SendMessageS("title screen.jpg","200")
Now these two strings will tell the engine to play 'loud thump.wav' at scene 22. All commands
have to be compiled, therefore no new commands may be written using the scripting language.
The second string text is the duration of the clip. This duration does not affect sound,
it determines how many frames a graphic stays on the screen. Please be aware of what order
you put these special commands. If you put the graphic before the sound, then the graphic
will display before the sound. But if the sound is before the graphic, then the sound will
play as soon as the graphic is played. All graphics fade in and out timed to 30 frames.
remend
sync on : sync rate 30
cls 0 : cls 0
r=load lua("game.txt")
global playerPoints = 0
dim playerPointsUndo(10000)
global sceneNum = 1
global howManyChoices = 0
dim choices(5)
global textVar$ = ""
dim choicesText$(5)
dim undoVar(10000)
global undoVarCounter = 0
global storyTextArrayVar
storyTextArrayVar = (screen height() / 15)-8
dim storyText$(storyTextArrayVar)
global storyTextLength = 0
global charactersAllowed
global keyPressedVar = 0
charactersAllowed = (screen width() / 9)
dim luaDescription$(10000) `is the scene number
dim luaMechanic$(10000) `is the special command, sound, graphic, etc.
dim luaSpecial$(10000) `is the text of the name of the special
dim luaDuration$(10000) `is the duration of the graphic, has no effect on sound
`LOAD MESSAGE QUEUE - PARSE THROUGH IT AND SAVE OUT VARIABLES
i = 0
while lua next()
inc i
luaDescription$(i) = lua message desc()
luaMechanic$(i) = lua message string()
r=lua next()
luaSpecial$(i) = lua message desc()
luaDuration$(i) = lua message string()
endwhile
gameMechanics()
do
cls 0
`remstart
newVar$ = inkey$()
select newVar$
case "1"
if howManyChoices >= 1 and keyPressedVar <> 1
keyPressedVar = 1
sceneNum = lua array int("game->#"+str$(sceneNum)+"->choices->#1")
playerPoints = playerPoints + lua array int("game->#"+str$(sceneNum)+"->points")
playerPointsUndo(undoVarCounter+1) = playerPoints
gameMechanics()
endif
endcase
case "2"
if howManyChoices >= 2 and keyPressedVar <> 1
keyPressedVar = 1
sceneNum = lua array int("game->#"+str$(sceneNum)+"->choices->#2")
playerPoints = playerPoints + lua array int("game->#"+str$(sceneNum)+"->points")
playerPointsUndo(undoVarCounter+1) = playerPoints
gameMechanics()
endif
endcase
case "3"
if howManyChoices >= 3 and keyPressedVar <> 1
keyPressedVar = 1
sceneNum = lua array int("game->#"+str$(sceneNum)+"->choices->#3")
playerPoints = playerPoints + lua array int("game->#"+str$(sceneNum)+"->points")
playerPointsUndo(undoVarCounter+1) = playerPoints
gameMechanics()
endif
endcase
case "4"
if howManyChoices >= 4 and keyPressedVar <> 1
keyPressedVar = 1
sceneNum = lua array int("game->#"+str$(sceneNum)+"->choices->#4")
playerPoints = playerPoints + lua array int("game->#"+str$(sceneNum)+"->points")
playerPointsUndo(undoVarCounter+1) = playerPoints
gameMechanics()
endif
endcase
case "5"
if howManyChoices >= 5 and keyPressedVar <> 1
keyPressedVar = 1
sceneNum = lua array int("game->#"+str$(sceneNum)+"->choices->#5")
playerPoints = playerPoints + lua array int("game->#"+str$(sceneNum)+"->points")
playerPointsUndo(undoVarCounter+1) = playerPoints
gameMechanics()
endif
endcase
case "q"
end
endcase
case "u"
if keyPressedVar <> 1
keyPressedVar = 1
dec undoVarCounter
if undoVarCounter <= 0 THEN undoVarCounter = 1
sceneNum = undoVar(undoVarCounter)
undoVar(undoVarCounter+1) = 0
`playerPoints = playerPoints - lua array int("game->#"+str$(sceneNum)+"->points")
playerPoints = playerPointsUndo(undoVarCounter)
dec undoVarCounter
gameMechanics()
endif
endcase
case ""
keyPressedVar = 0
endcase
case "s"
if keyPressedVar <> 1
keyPressedVar = 1
save array "savegame.txt",undoVar(10000)
endif
endcase
case "l"
if keyPressedVar <> 1
loadFunction()
endif
endcase
endselect
showText()
`remend
sync
loop
function loadFunction()
keyPressedVar = 1
if file exist("savegame.txt") = 0 then exitfunction
playerPoints = 0
undim undoVar(10000)
dim undoVar(10000)
undim playerPointsUndo(10000)
dim playerPointsUndo(10000)
undoVarCounter = 0
load array "savegame.txt",undoVar(10000)
for i = 1 to 10000
if undoVar(i) = 0
dec undoVarCounter
gameMechanics()
exitfunction
endif
inc undoVarCounter
sceneNum = undoVar(i)
playerPointsUndo(i) = lua array int("game->#"+str$(sceneNum)+"->points")
playerPoints = playerPoints + playerPointsUndo(i)
next i
gameMechanics()
endfunction
function gameMechanics()
`where it determines scene number and changes the variables accordingly
inc undoVarCounter
undoVar(undoVarCounter) = sceneNum
howManyChoices = lua array int("game->#"+str$(sceneNum)+"->howManyChoices")
for i = 1 to howManyChoices
`if howManyChoices <= i
choicesText$(i) = lua array string("game->#"+str$(sceneNum)+"->choicesText->#"+str$(i))
`endif
`if howManyChoices > i THEN choicesText$(i) = ""
next i
textVar$ = lua array string("game->#"+str$(sceneNum)+"->storyText")
storyTextLength = len(textVar$)
remstart
`****NEW CODE FOR PARSER TEXT****
for i = 1 to storyTextArrayVar
storyText$(i) = ""
next i
f = 1
c = 0
for i = 1 to storyTextLength
storyText$(f) = storyText$(f) + mid$(textVar$,i+c)
if mid$(textVar$,i) = "|"
c = c+(i-(charactersAllowed*f))
inc f
endif
if (i > c+(charactersAllowed*f)) and (mid$(textVar$,i) = " ")
inc f
endif
next i
remend
`****OLD CODE FOR PARSING TEXT****
`remstart
tempVar = ceil(storyTextLength/charactersAllowed)+1
if tempVar < 1
tempVar = 1
endif
for i = 1 to storyTextArrayVar
storyText$(i) = ""
next i
global zbuff = 0
c = 0
for i = 1 to tempVar
if i >= storyTextArrayVar then exit
for x = 1 to charactersAllowed
f = i
dec f
if (mid$(textVar$,x+(f*charactersAllowed)+zbuff) = "|") or (mid$(textVar$,x+(f*charactersAllowed)+zbuff) = " " and x > charactersAllowed-13)
zbuff = zbuff+(x - charactersAllowed)
storyTextLength = (-1*zbuff) + storyTextLength
tempVar = ceil(storyTextLength/charactersAllowed)+1
exit
endif
storyText$(i) = storyText$(i)+mid$(textVar$,x+(f*charactersAllowed)+zbuff)
next x
next i
`Next Parser Section
`for i = 1 to tempVar
` tempLengthVar = len(storyText$(i))
`if mid$(storyText$(i),tempLengthVar) <> " " and mid$(storyText$(i),tempLengthVar) <> "" and mid$(storyText$(i+1),1) <> " "
` storyText$(i) = storyText$(i) + "-"
`endif
` if mid$(storyText$(i),1) = " "
` storyText$(i) = right$(storyText$(i),tempLengthVar)
` endif
` if mid$(storyText$(i),1) = " " and mid$(storyText$(i),2) = " "
` storyText$(i) = right$(storyText$(i),tempLengthVar-1)
` endif
`next i
`remend
`****CALL IN THE SPECIAL COMMANDS ISSUE SO THAT IT DISPLAYS BEFORE TEXT
specialCommands()
endfunction
function specialCommands()
for i = 1 to 10000
if val(luaDescription$(i)) = sceneNum
if luaMechanic$(i) = "sound"
sound$ = luaSpecial$(i)
if file exist(sound$) = 0 then exitfunction
if sound exist(i) then exitfunction
load sound sound$,i
play sound i
endif
if luaMechanic$(i) = "graphic"
graphic$ = luaSpecial$(i)
if file exist(graphic$) = 0 then exitfunction
if image exist(i) then exitfunction
load image graphic$,i
for a = 1 to val(luaDuration$(i))
cls 0
sprite 1, screen width()/2,screen height()/2, i
offset sprite 1, sprite width(1)/2,sprite height(1)/2
if a <= 30 and spriteAlpha = 0
set sprite alpha 1,a*8.5
if sprite alpha(1) >= 250 then spriteAlpha = 1
endif
if a >= val(luaDuration$(i))-30 and spriteAlpha = 1
newAlpha = val(luaDuration$(i))-a
set sprite alpha 1,newAlpha*8.5
if sprite alpha(1) = 0 then spriteAlpha = 0
endif
sync
next a
cls 0 : cls 0
delete sprite 1
cls 0 : cls 0
endif
endif
next i
endfunction
function showText()
`where it does text wrap for the text, 1150 characters total allowed before things get screwy
`***OLD TEXT CODE***
storyTextLength = len(textVar$)+(-1*zBuff)
tempVar = ceil(storyTextLength/charactersAllowed)+1
if tempVar < 1
tempVar = 1
endif
for s = 1 to tempVar
if s >= storyTextArrayVar THEN exit
text 0,s*15, storyText$(s)
next s
for i = 1 to howManyChoices
text 0,(i*15)+(15*(s)), choicesText$(i)
next i
center text screen width()/2,screen height()-15,"Q) Quit Game U) Undo Last Move S) Save Game L) Load Game Player Points: "+str$(playerPoints)
endfunction
LICENSE: You may use my engine to make a game ONLY for the TACompetition. You may NOT use my engine for a commercial title or other competition entry. This license extends until the final deadline of the TACompetition. At that time this license will expire.
Here's a pic: