Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Map making
- Map = {}
- term.setCursorPos(1,1)
- termx = 1
- termy = 1
- function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function CreateEmpty()
- termx = 1
- termy = 1
- for n=1,18 do
- Map[n] = string.rep(" ", 50)
- end
- for n=1,4 do
- Map[n] = string.sub(Map[n], 14, string.len(Map[n]))
- end
- Map[1] = "Press Ctrl |"..Map[1]
- Map[2] = "To go to the|"..Map[2]
- Map[3] = "Menu.DontEdit"..Map[3]
- Map[4] = "This._NoUse_|"..Map[4]
- end
- function EditMap(Get)
- local sMap = Map[y]
- Map[y] = string.sub(sMap, 1, x-1)..Get..string.sub(sMap, x+1)
- DrawLine()
- if x == 49 then
- term.setCursorPos(x,y)
- end
- DrawLine()
- end
- function Draw()
- Clear()
- for n=1,#Map do
- term.write(Map[n])
- term.setCursorPos(1,n+1)
- end
- term.setCursorPos(termx, termy)
- end
- function DrawLine()
- term.setCursorPos(1, termy)
- term.clearLine()
- term.write(Map[termy])
- term.setCursorPos(termx, termy)
- end
- function Menu()
- Clear()
- print("1. Save")
- print("2. Discard and redo")
- print("3. Resume")
- print("4. Quit")
- print("5. Map Options")
- print("6. Load Map")
- while true do
- term.setCursorPos(1,8)
- event,param1 = os.pullEvent()
- if event == "char" then
- if param1 == "1" then
- if Dir then
- Save()
- Draw()
- Move()
- else
- term.setCursorPos(1,7)
- write("Please run options first")
- term.setCursorPos(1,8)
- end
- elseif param1 == "2" then
- CreateEmpty()
- Draw()
- Move()
- elseif param1 == "3" then
- Draw()
- Move()
- elseif param1 == "4" then
- Clear()
- print("You quit the Map Program!")
- error()
- elseif param1 == "5" then
- Options()
- Clear()
- Menu()
- elseif param1 == "6" then
- write("Load Map: ")
- if not Load(read()) then term.setCursorPos(1,7) write("Please choose a proper file name") sleep(4) Menu() else
- Clear()
- Draw()
- Move()
- end
- end
- end
- end
- end
- function Options()
- Clear()
- repeat
- Clear()
- write("X Cord to start the player at: ")
- xCord = read()
- if not tonumber(xCord) then xCord = 22222222 end
- if string.len(xCord) == 1 then
- xCord = "0"..xCord
- end
- until tonumber(xCord) > 0 and tonumber(xCord) < 49
- repeat
- Clear()
- write("Y Cord to start the player at: ")
- yCord = read()
- if not tonumber(yCord) then yCord = 22222222 end
- if string.len(yCord) == 1 then
- yCord = "0"..yCord
- end
- until tonumber(yCord) > 0 and tonumber(yCord) < 19
- repeat
- Clear()
- write("Direction to start player 1-left, 2-right, 3-up, 4-down: ")
- if not tonumber(Dir) then Dir = 22222222 end
- Dir = read()
- until tonumber(Dir) > 0 and tonumber(Dir) < 5
- Poopbear = xCord..yCord..Dir
- end
- function Load()
- if fs.exists("Maps/"..Name) then
- FP = io.open(Name, "r")
- for line in FP:lines() do
- Map[#Map+1] = line
- end
- Poopbear = Map[1]
- table.remove(Map, 1)
- FP:close()
- return true
- else
- return false
- end
- end
- function Save()
- if not Name then
- Clear()
- write("Name of file: ")
- Name = read()
- end
- if not fs.isDir("Maps") then fs.makeDir("Maps") end
- table.insert(Map, 1, Poopbear)
- local pi = io.open("Maps/"..Name, "w")
- for n=1,#Map do
- pi:write(Map[n].."\n")
- end
- pi:close()
- table.remove(Map, 1)
- end
- function Move()
- term.setCursorBlink(true)
- while true do
- event,param1,param2 = os.pullEvent()
- if event == "char" then
- local sMap = Map[termy]
- Map[termy] = string.sub(sMap, 1, termx-1)..param1..string.sub(sMap, termx+1)
- DrawLine()
- if termx < 50 then
- term.setCursorPos(termx+1, termy)
- termx = termx+1
- end
- elseif event == "key" then
- if param1 == 208 then-- Down
- if termy < 18 then
- term.setCursorPos(termx, termy+1)
- termy = termy+1
- end
- elseif param1 == 203 then -- Left
- if termx > 1 then
- term.setCursorPos(termx-1, termy)
- termx = termx-1
- end
- elseif param1 == 205 then -- right
- if termx < 50 then
- term.setCursorPos(termx+1, termy)
- termx = termx+1
- end
- elseif param1 == 200 then -- up
- if termy > 1 then
- term.setCursorPos(termx, termy-1)
- termy = termy-1
- end
- elseif param1 == 14 then -- Backspace
- local sMap = Map[termy]
- Map[termy] = string.sub(sMap, 1, termx-1).." "..string.sub(sMap, termx+1)
- DrawLine()
- if termx > 1 then
- term.setCursorPos(termx-1, termy)
- termx = termx-1
- end
- elseif param1 == 29 then --ctrl
- Menu()
- break
- end
- end
- end
- end
- Clear()
- CreateEmpty()
- Draw()
- Move()
Advertisement
Add Comment
Please, Sign In to add comment