Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y = term.getSize()
- local currentX = 8
- local currentY = 9
- local char = "v"
- local debugging = false
- local hasSword = false
- local usingSword = false
- local killedGuard = false
- local function cPrint(text)
- x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- write(text.. "\n")
- end
- local drawingBoard = {
- ["A"] = colors.white,
- ["B"] = colors.orange,
- ["C"] = colors.magenta,
- ["D"] = colors.lightBlue,
- ["E"] = colors.yellow,
- ["F"] = colors.lime,
- ["G"] = colors.pink,
- ["H"] = colors.gray,
- ["I"] = colors.lightGray,
- ["J"] = colors.cyan,
- ["K"] = colors.purple,
- ["L"] = colors.blue,
- ["M"] = colors.brown,
- ["N"] = colors.green,
- ["O"] = colors.red,
- ["P"] = colors.black,
- ["."] = colors.black,
- }
- function advWrite( pos1, pos2, str )
- for i=1,#str do
- if pos1 + (i-1) < x-6 then
- term.setCursorPos( pos1 + (i-1) , pos2 )
- local symb = string.sub( str, i, i)
- if maps[ currentMap ]["NPCs"][ symb ] then
- local npcData = maps[ currentMap ]["NPCs"][ symb ]
- if npcData[ "Message" ] == "This area is too dangerous!" and killedGuard then
- term.setBackgroundColour( colors.orange )
- write(" ")
- else
- term.setBackgroundColour( npcData["Background"] )
- write( npcData[ "Symbol" ] )
- if currentX == pos1 + (i-1) then
- if currentY == pos2 then
- if char == "^" then --Collision Detection
- currentY = currentY +1
- elseif char == "v" then
- currentY = currentY -1
- elseif char == ">" then
- currentX = currentX -1
- elseif char == "<" then
- currentX = currentX +1
- end
- term.setCursorPos(1,y)
- term.setBackgroundColour( colors.black )
- write( npcData[ "Message" ] )
- repeat
- local event, key = os.pullEvent( "key" )
- until key ~= 1
- if npcData[ "Message" ] == "Here, take this..." and hasSword ~= true then
- term.setCursorPos(1,y)
- term.setBackgroundColour( colors.black )
- write( "You received the..." )
- sleep(0.5)
- term.setTextColour( colors.red )
- write( " Sword!" )
- term.setTextColour( colors.white )
- hasSword = true
- repeat
- local event, key = os.pullEvent( "key" )
- until key ~= 1
- term.setCursorPos(1,y)
- term.clearLine()
- term.setBackgroundColour( colors.black )
- write( "Press the space bar to attack." )
- repeat
- local event, key = os.pullEvent( "key" )
- until key ~= 1
- end
- animation = os.startTimer( 0.7 )
- redraw()
- end
- end
- end
- elseif drawingBoard[ symb ] then
- term.setBackgroundColour( drawingBoard[ symb ] )
- local x1 = pos1 + (i-1)
- local y1 = pos2
- if currentX == x1 and currentY == y1 then
- local mapWarps = (maps[ currentMap ])["Warps"]
- for i=1,#mapWarps do
- if currentX == mapWarps[i]["X"] and currentY == mapWarps[i]["Y"] then
- currentMap = mapWarps[i]["To"]
- currentX = mapWarps[i]["pX"]
- currentY = mapWarps[i]["pY"]
- redraw()
- end
- end
- local colz = drawingBoard[ string.sub( str, i, i) ]
- if colz == colors.gray or colz == colors.green or colz == colors.cyan or symb == "." then
- if char == "^" then --Collision Detection
- currentY = currentY +1
- elseif char == "v" then
- currentY = currentY -1
- elseif char == ">" then
- currentX = currentX -1
- elseif char == "<" then
- currentX = currentX +1
- end
- redraw()
- else
- write( char )
- end
- else
- if debugging then
- local colz = drawingBoard[ string.sub( str, i, i) ]
- if colz == colors.black then
- term.setTextColour( colors.lime )
- write("D")
- term.setTextColour( colors.white )
- elseif colz == colors.gray or colz == colors.green or colz == colors.cyan then
- term.setTextColour( colors.purple )
- write("W")
- term.setTextColour( colors.white )
- else
- term.setTextColour( colors.red )
- write("P")
- term.setTextColour( colors.white )
- end
- else
- if usingSword then
- if char == "^" and x1 == currentX and y1 == currentY -1 then
- write("|")
- elseif char == "v" and x1 == currentX and y1 == currentY +1 then
- write("|")
- elseif char == ">" and x1 == currentX +1 and y1 == currentY then
- write("-")
- elseif char == "<" and x1 == currentX -1 and y1 == currentY then
- write("-")
- else
- if symb == "O" and math.random(1,3) == 3 then
- write( "~" )
- else
- write( " " )
- end
- end
- else
- if symb == "O" and math.random(1,3) == 3 then
- write( "~" )
- else
- write( " " )
- end
- end
- end
- end
- end
- end
- end
- end
- currentMap = "Room"
- maps = {
- ["Room"] = {
- "NNNNNNNNNNNNNNNNNNNNNN",
- "NFFFHHFFFFFNFHFFFFFFHF",
- "NFHHPHHFFFFNFFFFFHHFFF",
- "NFFFBFFFFBBzBBBHHOOHHF",
- "NFFFBBBBBBFHHHBHOOOOHH",
- "NFFFFFFBFFHHHHBBBBHOOH",
- "NFFFFHHPHHHHHHHHHBBBBP",
- "NFFFFHHHHHHOHHHOOHHHHH",
- "NFFHHHHHHOOHHHHHOOOOOO",
- ["MapLength"] = 9,
- ["Offset_X"] = 4,
- ["Offest_Y"] = 6,
- ["Warps"] = {
- [1] = {
- ["To"] = "Cave",
- ["X"] = 8,
- ["Y"] = 8,
- ["pX"] = 8,
- ["pY"] = 9,
- },
- [2] = {
- ["To"] = "Cave_1",
- ["X"] = 11,
- ["Y"] = 12,
- ["pX"] = 10,
- ["pY"] = 7,
- },
- [3] = {
- ["To"] = "Volcano",
- ["X"] = 25,
- ["Y"] = 12,
- ["pX"] = 5,
- ["pY"] = 8,
- },
- },
- ["NPCs"] = {
- ["z"] = {
- ["Symbol"] = "A",
- ["Background"] = colors.orange,
- ["Message"] = "This area is too dangerous!",
- },
- },
- },
- ["Cave"] = {
- "HHHHHHHHHHH",
- "HHHHHHHHIII",
- "HIHHPHHIJJI",
- "HIIIMIJJJJI",
- "HIHIMIIIMJI",
- "HIIIMMMMMII",
- ["MapLength"] = 6,
- ["Offset_X"] = 4,
- ["Offest_Y"] = 6,
- ["Warps"] = {
- [1] = {
- ["To"] = "Room",
- ["X"] = 8,
- ["Y"] = 8,
- ["pX"] = 8,
- ["pY"] = 9,
- },
- },
- ["NPCs"] = {
- },
- },
- ["Cave_1"] = {
- "HHHHHHPHHHHH",
- "HIIIIIMIIIII",
- "HIIIIIMIIIII",
- "HIIIIImIIIII",
- "HIOIOIOIOIOI",
- "HIIIIIIIIIII",
- ["MapLength"] = 6,
- ["Offset_X"] = 4,
- ["Offest_Y"] = 6,
- ["Warps"] = {
- [1] = {
- ["To"] = "Room",
- ["X"] = 10,
- ["Y"] = 6,
- ["pX"] = 11,
- ["pY"] = 11,
- },
- },
- ["NPCs"] = {
- ["m"] = {
- ["Symbol"] = "@",
- ["Background"] = colors.lightGray,
- ["Message"] = "Here, take this...",
- },
- },
- },
- ["Volcano"] = {
- "HHH",
- "HH........HHH",
- ".IIIIIIIIIIOH",
- "HH........HHH",
- "HHH",
- ["MapLength"] = 5,
- ["Offset_X"] = 4,
- ["Offest_Y"] = 6,
- ["Warps"] = {
- },
- ["NPCs"] = {
- },
- },
- }
- local stats = {
- ["XP"] = 0,
- ["$$"] = 25,
- ["LVL"] = 1,
- }
- function drawGUI()
- for i=1,y do
- term.setCursorPos(x-6, i)
- write("|")
- end
- term.setCursorPos(x-5,2)
- write("Stats")
- term.setCursorPos(x-5,4)
- write("XP:")
- term.setCursorPos(x-5,5)
- write("[ ]")
- if stats["XP"] == 5 then
- stats["XP"] = 1
- stats["LVL"] = stats["LVL"] +1
- end
- for i=1,stats["XP"] do
- term.setCursorPos(x-5+i,5)
- write("|")
- end
- term.setCursorPos( x-5, 6 )
- local level = stats["LVL"]
- if level < 10 then
- write(" >0" ..level.. "< ")
- else
- write(" >" ..level.. "< ")
- end
- term.setCursorPos( x-5, 8 )
- write("Money:")
- term.setCursorPos( x-5, 9 )
- write("$" ..stats["$$"])
- if debugging then
- term.setCursorPos( x-5, y-1 )
- write("X: " ..currentX)
- term.setCursorPos( x-5, y )
- write("Y: " ..currentY)
- end
- end
- function drawMAP()
- local offsetX = maps[ currentMap ]["Offset_X"]
- local offsetY = maps[ currentMap ]["Offest_Y"]
- local mapLength = maps[ currentMap ]["MapLength"]
- for i=1,mapLength do
- advWrite( offsetX, offsetY + (i-1), maps[ currentMap ][i] )
- end
- end
- function redraw()
- term.setBackgroundColour( colors.black )
- term.clear()
- term.setCursorPos(currentX,currentY)
- write( char )
- drawGUI()
- drawMAP()
- return start()
- end
- function start()
- --while true do
- term.setBackgroundColour( colors.black )
- term.clear()
- term.setCursorPos(currentX,currentY)
- write( char )
- drawGUI()
- drawMAP()
- local event, key = os.pullEvent()
- if event == "key" then
- if key == keys.up then
- currentY = currentY -1
- char = "^"
- elseif key == keys.down then
- currentY = currentY +1
- char = "v"
- elseif key == keys.left then
- currentX = currentX -1
- char = "<"
- elseif key == keys.right then
- currentX = currentX +1
- char = ">"
- elseif key == keys.enter then
- if debugging then
- debugging = false
- else
- debugging = true
- end
- elseif key == keys.space and hasSword then
- usingSword = true
- swordSwing = os.startTimer( 0.3 )
- if currentX == 14 and currentY == 9 and currentMap == "Room" and char == ">" then
- killedGuard = true
- end
- end
- elseif event == "timer" then
- if key == animation then
- animation = os.startTimer( 0.7 )
- elseif key == swordSwing then
- usingSword = false
- end
- end
- return redraw()
- --end
- end
- animation = os.startTimer( 0.7 )
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement