LDDestroier

Megaman X intro screen COMPUTERCRAFT

Mar 8th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.59 KB | None | 0 0
  1. -- pastebin get YugF1mqx startup
  2.  
  3. local pullEvent = os.pullEvent
  4. os.pullEvent = os.pullEventRaw
  5.  
  6. local skip = false
  7.  
  8. term.setTextColor(colors.lightBlue)
  9. term.setBackgroundColor(colors.black)
  10. term.clear()
  11.  
  12. local beep = function()
  13.     rs.setOutput("bottom",true)
  14.     sleep(0)
  15.     rs.setOutput("bottom",false)
  16. end
  17.  
  18. local funcread = function(repchar,rHistory,doFunc,noNewLine)
  19.     local scr_x,scr_y = term.getSize()
  20.     local sx,sy = term.getCursorPos()
  21.     local cursor = 1
  22.     local rCursor = #rHistory+1
  23.     local output = ""
  24.     term.setCursorBlink(true)
  25.     while true do
  26.         local evt,key = os.pullEvent()
  27.         local cx,cy = term.getCursorPos()
  28.         if evt == "key" then
  29.             if key == keys.enter then
  30.                 if not noNewLine then
  31.                     write("\n")
  32.                 end
  33.                 term.setCursorBlink(false)
  34.                 return output
  35.             elseif key == keys.left then
  36.                 if cursor-1 >= 1 then
  37.                     cursor = cursor - 1
  38.                 end
  39.             elseif key == keys.right then
  40.                 if cursor <= #output then
  41.                     cursor = cursor + 1
  42.                 end
  43.             elseif key == keys.up then
  44.                 if rCursor > 1 then
  45.                     rCursor = rCursor - 1
  46.                     term.setCursorPos(sx,sy)
  47.                     term.write((" "):rep(#output))
  48.                     output = rHistory[rCursor] or ""
  49.                     cursor = #output+1
  50.                     pleaseDoFunc = true
  51.                 end
  52.             elseif key == keys.down then
  53.                 term.setCursorPos(sx,sy)
  54.                 term.write((" "):rep(#output))
  55.                 if rCursor < #rHistory then
  56.                     rCursor = rCursor + 1
  57.                     output = rHistory[rCursor] or ""
  58.                     cursor = #output+1
  59.                     pleaseDoFunc = true
  60.                 else
  61.                     rCursor = #rHistory+1
  62.                     output = ""
  63.                     cursor = 1
  64.                 end
  65.             elseif key == keys.backspace then
  66.                 if cursor > 1 and #output > 0 then
  67.                     output = output:sub(1,cursor-2)..output:sub(cursor)
  68.                     cursor = cursor - 1
  69.                     pleaseDoFunc = true
  70.                 end
  71.             elseif key == keys.delete then
  72.                 if #output:sub(cursor,cursor) == 1 then
  73.                     output = output:sub(1,cursor-1)..output:sub(cursor+1)
  74.                     pleaseDoFunc = true
  75.                 end
  76.             end
  77.         elseif evt == "char" or evt == "paste" then
  78.             output = output:sub(1,cursor-1)..key..output:sub(cursor+(#key-1))
  79.             cursor = cursor + #key
  80.             pleaseDoFunc = true
  81.         end
  82.         if pleaseDoFunc then
  83.             pleaseDoFunc = false
  84.             if type(doFunc) == "function" then
  85.                 doFunc(output)
  86.             end
  87.             term.setCursorPos(sx,sy)
  88.             local pOut = output
  89.             if #output >= scr_x-(sx-2) then
  90.                 pOut = output:sub((#output+(sx))-scr_x)
  91.             end
  92.             if repchar then
  93.                 term.write(repchar:sub(1,1):rep(#pOut).." ")
  94.             else
  95.                 term.write(pOut.." ")
  96.             end
  97.             local cx,cy = term.getCursorPos()
  98.         end
  99.         term.setCursorPos(sx+cursor-1,cy)
  100.     end
  101. end
  102.  
  103. local loginPrompt = function()
  104.     local tries = 0
  105.     while true do
  106.         write(" login: ")
  107.         local name = funcread(nil,{},beep)
  108.         beep()
  109.         if name ~= "Dr.CAIN" then
  110.             tries = tries + 1
  111.             print("No such user registered\n")
  112.         else
  113.             write(" code : ")
  114.             local code = funcread("*",{},beep)
  115.             beep()
  116.             if code ~= "wanker" then
  117.                 sleep(2)
  118.                 tries = tries + 1
  119.                 print("Pass code rejected\n")
  120.             else
  121.                 sleep(1)
  122.                 return true
  123.             end
  124.         end
  125.         if tries >= 5 then
  126.             print("System locked")
  127.             while true do
  128.                 beep()
  129.                 sleep(0)
  130.             end
  131.         end
  132.     end
  133. end
  134.  
  135. local slowWrite = function(txt,delay,doBeep)
  136.     if delay == 0 then
  137.         return write(txt)
  138.     else
  139.         for a = 1, #txt do
  140.             write(txt:sub(a,a))
  141.             if doBeep then
  142.                 beep()
  143.             end
  144.             sleep(delay)
  145.         end
  146.     end
  147. end
  148.  
  149. local function explode(div,str)
  150.     if (div=='') then return false end
  151.     local pos,arr = 0,{}
  152.     for st,sp in function() return string.find(str,div,pos,true) end do
  153.         table.insert(arr,string.sub(str,pos,st-1))
  154.         pos = sp + 1
  155.     end
  156.     table.insert(arr,string.sub(str,pos))
  157.     return arr
  158. end
  159.  
  160. if not skip then
  161.  
  162. local script = [[
  163.  
  164. NOM ENGINEERING WORK SYSTEM
  165. Model CPS-9204
  166.  
  167. Copywright (c) 2105, 2109, 2114
  168. NOM Corporation
  169. All Rights Reserved]]
  170.  
  171. local script = explode("\n",script)
  172. for a = 1, #script do
  173.     sleep(0.4)
  174.     term.setCursorPos(2,a)
  175.     slowWrite(script[a],0,true)
  176. end
  177.  
  178. sleep(0.3)
  179.  
  180. for a = 1024, 8192, 1024 do
  181.     term.setCursorPos(2,#script+2)
  182.     term.write("real  mem = "..a)
  183.     term.setCursorPos(19,#script+2)
  184.     term.write("TB")
  185.     sleep(0.5)
  186. end
  187. sleep(0.5)
  188. for a = 4096, 32768, 4096 do
  189.     term.setCursorPos(2,#script+3)
  190.     term.write("avail mem = "..a)
  191.     term.setCursorPos(20,#script+3)
  192.     term.write("TB")
  193.     sleep(0.5)
  194. end
  195. term.setCursorPos(1,#script+5)
  196. print(" primary data cache : 512KB")
  197. sleep(0.3)
  198. print(" primary inst.cache : 768KB")
  199. sleep(0.3)
  200. print(" secondary cache    : 32768KB")
  201. sleep(0.4)
  202.  
  203. loginPrompt()
  204.  
  205. end
  206.  
  207. read = function(repchar,tHistory)
  208.     return funcread(repchar,tHistory,beep)
  209. end
  210. _G.read = read
  211. os.pullEvent = pullEvent
Add Comment
Please, Sign In to add comment