Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game.toggleNoclip(false)
- local pccDir = "/pokecc"--shell.getDir()
- local args = {...}
- args[1] = args[1] or "mainMap"
- local mainMap = game.loadMap(fs.combine(pccDir,args[1]),0,0,false,colors.green,colors.lime,"T")
- local player = game.addPlayer(colors.orange,colors.black,"~",26,10,mainMap,false) -- Orange player with black ~, at 26,10 on screen, on map mainMap, and if he walks into nothing, no collison.
- local cMap = mainMap--Always update this viariable to be the current map's table
- local config = { -- Controls for are always in key(number), not char events.
- cPlayer={--the c -prefix means controls for
- forward = 17,--W
- back = 31, --D
- left = 30,--A
- right = 32,--D
- sprint = 42,--Shift/The answer to life, the universe, and everything.
- },
- cGeneral = {
- console = 41,--" ~ "
- menu = 29,--ctrl
- menuUp = 17, -- w
- menuDown = 31, --d
- menuSel = 57, --space
- },
- moveSpeed = {
- walk = 0.20,
- sprint = 0.1 ,
- },
- }
- local gamestate = {}
- local whitespace = ""
- for i = 1,term.getSize() do
- whitespace = whitespace.." "
- end
- local function render(tMap)--Render the current map & player
- tMap:render(player.x,player.y)
- player:draw()
- end
- local function pauseMenuDraw()
- local tx,ty = term.getSize()
- --paintutils.drawFilledBox(tx-9,1,tx,9,colors.white)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(tx-9,1)
- term.write"/--------\\"
- term.setCursorPos(tx-9,2)
- term.write"|>Pokemon|"
- term.setCursorPos(tx-9,3)
- term.write"| Pack |"
- term.setCursorPos(tx-9,4)
- term.write"| Pokedex|"
- term.setCursorPos(tx-9,5)
- term.write"| Stats |"
- term.setCursorPos(tx-9,6)
- term.write"| Save |"
- term.setCursorPos(tx-9,7)
- term.write"| Options|"
- term.setCursorPos(tx-9,8)
- term.write"\\--------/"
- end
- local function guiDlg(txt)
- local tx,ty = term.getSize()
- local startLoc = ty-7
- local borderLine = ""
- for i = 1,tx-2 do
- borderLine = borderLine.."-"
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,startLoc)
- term.write("/"..borderLine.."\\")
- term.setCursorPos(1,ty)
- term.write("\\"..borderLine.."/")
- local pos,scrPos,str,continue = 1,ty-6,"",true
- txt=" "..txt
- tx = tx-2
- --Start by setting the variables to what they need to be
- while true do
- lastPos,noDo = pos,false
- local nL
- pos,nL = txt:find(" ",lastPos+1),txt:find("\n",lastPos+1)
- if (not pos) and ( not nL) then
- --[[term.setCursorPos(1,scrPos)
- term.write("|"..str.."|")
- break]]
- continue = false
- pos = #txt
- nL = 0
- end
- --pos = math.min(a,b)
- game.l"~-"
- game.l(pos)
- game.l(nL)
- game.l"=="
- if --[[(not ( (nL or pos) < pos)) and]] #str+((pos-lastPos)-1) <=tx then
- str = str..txt:sub(lastPos+1,pos)
- term.setCursorPos(1,scrPos)
- if not continue then
- term.write("|"..str..whitespace:sub(#str,#whitespace-3).."|")
- break
- end
- else
- term.setCursorPos(1,scrPos)
- term.write("|"..str..whitespace:sub(#str,#whitespace-3).."|")
- scrPos,str = scrPos+1,""
- pos = lastPos
- -- noDo = true
- if scrPos == ty then
- term.setCursorPos(tx+2,ty-1)
- term.setTextColor(colors.red)
- term.write"V"
- return pos
- end
- end
- game.l(str)
- game.l(scrPos)
- game.l"~"
- game.l(continue)
- game.l(noDo)
- game.l"------"
- --[[if( not continue) and noDo then
- break
- end ]]
- end
- end
- local function inGame()
- render(cMap)--firstime
- --player:draw()
- local moveF, moveB, moveL,moveR,sprint,paused
- while true do
- --Queue timers, put their IDs in the appriopriate move value.
- local evts={os.pullEvent()}
- if evts[1]=="key" and (not (paused)) then
- if evts[2] == config.cPlayer.forward and( not moveF) then
- moveF = os.startTimer(0)
- elseif evts[2]==config.cPlayer.back and (not moveB) then
- moveB = os.startTimer(0)
- elseif evts[2]==config.cPlayer.left and (not moveL) then
- moveL = os.startTimer(0)
- elseif evts[2]==config.cPlayer.right and (not moveR) then
- moveR = os.startTimer(0)
- elseif evts[2]==config.cPlayer.sprint then
- sprint=true
- elseif evts[2]==config.cGeneral.console then
- game.openConsole()
- elseif evts[2]==config.cGeneral.menu then
- pauseMenuDraw()
- paused = 1
- end
- elseif evts[1]=="key_up" and (not (paused)) then
- if evts[2] == config.cPlayer.forward then
- moveF = false
- elseif evts[2]==config.cPlayer.back then
- moveB = false
- elseif evts[2]==config.cPlayer.left then
- moveL = false
- elseif evts[2]==config.cPlayer.right then
- moveR =false
- elseif evts[2]==config.cPlayer.sprint then
- sprint=false
- end
- elseif evts[1]=="key" and paused then
- if evts[2]==config.cGeneral.menu then
- paused = false
- render(cMap)
- elseif evts[2]==config.cGeneral.menuUp or evts[2]==config.cGeneral.menuDown then
- local tx=term.getSize()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(tx-8,paused+1)
- term.write" "
- if evts[2]==config.cGeneral.menuUp and paused > 1 then
- paused=paused-1
- elseif evts[2]==config.cGeneral.menuDown and paused < 6 then
- paused = paused + 1
- end
- term.setCursorPos(tx-8,paused+1)
- term.write">"
- elseif evts[2]==config.cGeneral.menuSel then
- guiDlg("This text serves the purpose of a placeholder. Placeholders are often used to test parts of GUIs or as test character dialog in games. They generally are Lorem Ipsum, however, this placeholder is unique. Lorem Ipsum can be troublesome to use to test word wrapping, as it is not in english.")
- end
- elseif evts[1]=="timer" then
- doRender = false
- if not paused then
- if evts[2]==moveF then
- player:moveUp()
- if sprint then
- moveF = os.startTimer(config.moveSpeed.sprint)
- else
- moveF=os.startTimer(config.moveSpeed.walk)
- end
- doRender=true
- elseif evts[2]==moveB then
- player:moveDown()
- if sprint then
- moveB=os.startTimer(config.moveSpeed.sprint)
- else
- moveB=os.startTimer(config.moveSpeed.walk)
- end
- doRender=true
- elseif evts[2]==moveL then
- player:moveLeft()
- if sprint then
- moveL = os.startTimer(config.moveSpeed.sprint)
- else
- moveL=os.startTimer(config.moveSpeed.walk)
- end
- doRender=true
- elseif evts[2]==moveR then
- player:moveRight()
- if sprint then
- moveR = os.startTimer(config.moveSpeed.sprint)
- else
- moveR=os.startTimer(config.moveSpeed.walk)
- end
- doRender=true
- end
- if doRender then
- render(cMap)
- end
- end
- end
- end
- end
- inGame()
Advertisement
Add Comment
Please, Sign In to add comment