5bitesofcookies

pokecc-executable-cc

Oct 21st, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.68 KB | None | 0 0
  1. game.toggleNoclip(false)
  2. local pccDir = "/pokecc"--shell.getDir()
  3. local args = {...}
  4. args[1] = args[1] or "mainMap"
  5. local mainMap = game.loadMap(fs.combine(pccDir,args[1]),0,0,false,colors.green,colors.lime,"T")
  6. 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.
  7. local cMap = mainMap--Always update this viariable to be the current map's table
  8. local config = { -- Controls for are always in key(number), not char events.
  9.     cPlayer={--the c -prefix means controls for
  10.         forward = 17,--W
  11.         back = 31,  --D
  12.         left = 30,--A
  13.         right = 32,--D
  14.         sprint = 42,--Shift/The answer to life, the universe, and everything.
  15.        
  16.     },
  17.     cGeneral = {
  18.         console = 41,--" ~ "
  19.         menu = 29,--ctrl
  20.         menuUp = 17, -- w
  21.         menuDown = 31, --d
  22.         menuSel = 57, --space
  23.     },
  24.     moveSpeed = {
  25.         walk = 0.20,
  26.         sprint = 0.1 ,
  27.     },
  28.    
  29.  
  30. }
  31. local gamestate = {}
  32.  
  33. local whitespace = ""
  34. for i = 1,term.getSize() do
  35.     whitespace = whitespace.." "
  36. end
  37. local function render(tMap)--Render the current map & player
  38.     tMap:render(player.x,player.y)
  39.     player:draw()
  40. end
  41. local function pauseMenuDraw()
  42.     local tx,ty = term.getSize()
  43.     --paintutils.drawFilledBox(tx-9,1,tx,9,colors.white)
  44.     term.setTextColor(colors.black)
  45.     term.setBackgroundColor(colors.white)
  46.     term.setCursorPos(tx-9,1)
  47.     term.write"/--------\\"
  48.     term.setCursorPos(tx-9,2)
  49.     term.write"|>Pokemon|"
  50.     term.setCursorPos(tx-9,3)
  51.     term.write"| Pack   |"
  52.     term.setCursorPos(tx-9,4)
  53.     term.write"| Pokedex|"
  54.     term.setCursorPos(tx-9,5)
  55.     term.write"| Stats  |"
  56.     term.setCursorPos(tx-9,6)
  57.     term.write"| Save   |"
  58.     term.setCursorPos(tx-9,7)
  59.     term.write"| Options|"
  60.     term.setCursorPos(tx-9,8)
  61.     term.write"\\--------/"
  62. end
  63. local function guiDlg(txt)
  64.     local tx,ty = term.getSize()
  65.     local startLoc = ty-7
  66.     local borderLine = ""
  67.     for i = 1,tx-2 do
  68.         borderLine = borderLine.."-"
  69.     end
  70.     term.setBackgroundColor(colors.white)
  71.     term.setTextColor(colors.black)
  72.     term.setCursorPos(1,startLoc)
  73.     term.write("/"..borderLine.."\\")
  74.     term.setCursorPos(1,ty)
  75.     term.write("\\"..borderLine.."/")
  76.     local pos,scrPos,str,continue = 1,ty-6,"",true
  77.     txt=" "..txt
  78.     tx = tx-2
  79.     --Start by setting the variables to what they need to be
  80.     while true do
  81.         lastPos,noDo = pos,false
  82.         local nL
  83.         pos,nL = txt:find(" ",lastPos+1),txt:find("\n",lastPos+1)  
  84.         if (not pos)  and ( not nL) then
  85.             --[[term.setCursorPos(1,scrPos)
  86.             term.write("|"..str.."|")
  87.             break]]
  88.             continue = false
  89.             pos = #txt
  90.             nL = 0
  91.         end
  92.         --pos = math.min(a,b)
  93.         game.l"~-"
  94.         game.l(pos)
  95.         game.l(nL)
  96.         game.l"=="
  97.         if --[[(not ( (nL or pos) < pos))  and]]  #str+((pos-lastPos)-1) <=tx then
  98.             str = str..txt:sub(lastPos+1,pos)
  99.             term.setCursorPos(1,scrPos)
  100.             if not continue then
  101.                 term.write("|"..str..whitespace:sub(#str,#whitespace-3).."|")
  102.                 break
  103.             end
  104.         else
  105.             term.setCursorPos(1,scrPos)
  106.             term.write("|"..str..whitespace:sub(#str,#whitespace-3).."|")
  107.             scrPos,str = scrPos+1,""
  108.             pos = lastPos
  109.         --  noDo = true
  110.             if scrPos == ty then
  111.                 term.setCursorPos(tx+2,ty-1)
  112.                 term.setTextColor(colors.red)
  113.                 term.write"V"
  114.                 return pos
  115.             end
  116.         end
  117.         game.l(str)
  118.         game.l(scrPos)
  119.         game.l"~"
  120.         game.l(continue)
  121.         game.l(noDo)
  122.         game.l"------"
  123.         --[[if( not continue) and noDo then
  124.             break
  125.         end ]]
  126.            
  127.     end
  128. end
  129. local function inGame()
  130.     render(cMap)--firstime
  131.     --player:draw()
  132.     local moveF, moveB, moveL,moveR,sprint,paused
  133.     while true do
  134.         --Queue timers, put their IDs in the appriopriate move value.
  135.         local evts={os.pullEvent()}
  136.         if evts[1]=="key" and (not (paused)) then
  137.             if evts[2] == config.cPlayer.forward and( not moveF) then
  138.                 moveF = os.startTimer(0)   
  139.             elseif evts[2]==config.cPlayer.back and (not moveB) then
  140.                 moveB = os.startTimer(0)
  141.             elseif evts[2]==config.cPlayer.left and (not moveL) then
  142.                 moveL = os.startTimer(0)
  143.             elseif evts[2]==config.cPlayer.right and (not moveR) then
  144.                 moveR = os.startTimer(0)
  145.             elseif evts[2]==config.cPlayer.sprint then
  146.                 sprint=true
  147.             elseif evts[2]==config.cGeneral.console then
  148.                 game.openConsole()
  149.             elseif evts[2]==config.cGeneral.menu then
  150.                 pauseMenuDraw()
  151.                 paused = 1
  152.             end
  153.         elseif evts[1]=="key_up" and (not (paused)) then
  154.             if evts[2] == config.cPlayer.forward then
  155.                 moveF = false
  156.             elseif evts[2]==config.cPlayer.back  then
  157.                 moveB = false
  158.             elseif evts[2]==config.cPlayer.left  then
  159.                 moveL = false  
  160.             elseif evts[2]==config.cPlayer.right  then
  161.                 moveR =false  
  162.             elseif evts[2]==config.cPlayer.sprint then
  163.                 sprint=false
  164.             end
  165.         elseif evts[1]=="key" and paused then
  166.             if evts[2]==config.cGeneral.menu then
  167.                 paused = false
  168.                 render(cMap)
  169.             elseif evts[2]==config.cGeneral.menuUp or evts[2]==config.cGeneral.menuDown then
  170.                 local tx=term.getSize()
  171.                 term.setBackgroundColor(colors.white)
  172.                 term.setTextColor(colors.black)
  173.                 term.setCursorPos(tx-8,paused+1)
  174.                 term.write" "
  175.                 if evts[2]==config.cGeneral.menuUp and paused > 1 then
  176.                     paused=paused-1
  177.                 elseif evts[2]==config.cGeneral.menuDown and paused < 6 then
  178.                     paused = paused + 1
  179.                 end
  180.                    
  181.                    
  182.                 term.setCursorPos(tx-8,paused+1)
  183.                 term.write">"
  184.             elseif evts[2]==config.cGeneral.menuSel then
  185.                 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.")
  186.             end    
  187.         elseif evts[1]=="timer" then
  188.             doRender = false
  189.             if not paused then
  190.                 if evts[2]==moveF then
  191.                     player:moveUp()
  192.                     if sprint then
  193.                         moveF = os.startTimer(config.moveSpeed.sprint)
  194.                     else
  195.                         moveF=os.startTimer(config.moveSpeed.walk)
  196.                     end
  197.                     doRender=true
  198.                 elseif evts[2]==moveB then
  199.                     player:moveDown()
  200.                     if sprint then
  201.                         moveB=os.startTimer(config.moveSpeed.sprint)
  202.                     else
  203.                         moveB=os.startTimer(config.moveSpeed.walk)
  204.                     end
  205.                     doRender=true
  206.                 elseif evts[2]==moveL then
  207.                     player:moveLeft()
  208.                     if sprint then
  209.                         moveL = os.startTimer(config.moveSpeed.sprint)
  210.                     else
  211.                         moveL=os.startTimer(config.moveSpeed.walk)
  212.                     end
  213.                     doRender=true
  214.                 elseif evts[2]==moveR then
  215.                     player:moveRight()
  216.                     if sprint then
  217.                         moveR = os.startTimer(config.moveSpeed.sprint)
  218.                     else
  219.                         moveR=os.startTimer(config.moveSpeed.walk)
  220.                     end
  221.                     doRender=true
  222.                 end
  223.                 if doRender then
  224.                     render(cMap)
  225.                 end        
  226.             end
  227.         end
  228.     end
  229. end
  230. inGame()
Advertisement
Add Comment
Please, Sign In to add comment