Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hs=0
- cash=0
- shell.run("clear")
- if os.loadAPI(shell.resolve("").."/".."gc") == false then
- print("Unable to load GC api")
- if http then
- write("Install for you? (y/n): ")
- response = read()
- if response == "y" then
- gcapi = http.get("http://pastebin.com/raw.php?i=K7k6MLds")
- if gcapi == nil then
- print("Unable to connect, make sure you are connected to the internet.")
- error()
- end
- gcapitxt = gcapi.readAll()
- gcf = fs.open(shell.resolve("").."/".."gc","w")
- gcf.write(gcapitxt)
- gcf.close()
- print("Done! Please restart now.")
- error()
- else
- print("OK, please install to continue.")
- error()
- end
- else
- print("HTTP API is not enabled, please install gc api manually")
- error()
- end
- end
- termx,termy = term.getSize()
- gameRunning = true
- objects = {}
- gameWidth = 20
- gameHeight = termy-3
- gameX = termx/2-gameWidth/2
- gameY = 1
- pathing = 4
- cpath = 1
- paused = false
- function rep(str,nm)
- for i=1,nm do
- write(str)
- end
- end
- function clearsc(x1,x2,y1,y2)
- for i=1,y2-y1 do
- rep(" ",x2-x1)
- term.setCursorPos(x1,y1+i)
- end
- end
- function draw()
- term.setBackgroundColor(colors.black)
- clearsc(gameX,gameY,gameX+gameWidth-1,gameY+gameHeight-1)
- shell.run("clear")
- term.setTextColor(colors.blue)
- text("SCORE: "..scr,termx/2,gameY+gameHeight,"middle")
- text("CASH: "..cash,termx/2,gameY+gameHeight+1,"middle")
- text("HIGH SCORE: "..hs,termx/2,gameY+gameHeight+2,"middle")
- term.setBackgroundColor(colors.black)
- term.setCursorPos(gameX + objects.ball.x - 1,gameY + objects.ball.y - 1)
- term.setTextColor(colors.blue)
- write("O")
- for v,k in pairs(objects.blocks) do
- if k.y == gameHeight + gameY - 1 then
- else
- if k.y <= gameY then
- else
- term.setCursorPos(gameX + k.x - 1,gameY + k.y - 1)
- term.setBackgroundColor(colors.yellow)
- write(" ")
- end
- end
- end
- for v,k in pairs(objects.coins) do
- if k.y == gameHeight + gameY - 1 then
- else
- if k.y <=gameY then
- else
- term.setCursorPos(gameX + k.x - 1,gameY + k.y - 1)
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- write("o")
- end
- end
- end
- gc.drawBoxOutlineBackColor(gameX,gameY,gameWidth,gameHeight,colors.green)
- end
- function initvars()
- objects.ball = {}
- objects.blocks = {}
- objects.coins = {}
- objects.ball.x = math.ceil(gameWidth/2)
- objects.ball.y = 2
- objects.ball.v = 1
- lost = false
- scr = 0
- time = 0
- end
- function slp()
- while time ~= 5 do
- sleep(0.1)
- time = time + 1
- end
- time = 0
- return
- end
- function runActions()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- text("SCORE: "..scr,termx/2,gameY+gameHeight,"middle")
- text("CASH: "..cash,termx/2,gameY+gameHeight+1,"middle")
- text("HIGH SCORE: "..hs,termx/2,gameY+gameHeight+2,"middle")
- if objects.ball.y == gameY then
- gameRunning = false
- lost = true
- end
- local dest = nil
- local dest = {}
- for v,k in pairs(objects.blocks) do
- if k ~= nil then
- if k.x == objects.ball.x then
- if k.y == objects.ball.y + 1 then
- objects.ball.y = objects.ball.y - 2
- end
- end
- k.y = k.y - 1
- end
- if k.y < gameY then
- table.insert(dest,k)
- end
- end
- for i=1,#dest do
- objects.blocks[dest[i]]=nil
- end
- if objects.ball.y ~= gameHeight - 1 then
- objects.ball.y = objects.ball.y + objects.ball.v
- end
- local dest=nil
- for v,k in pairs(objects.coins) do
- k.y=k.y-1
- if k ~= nil then
- if k.x == objects.ball.x then
- if k.y == objects.ball.y then
- cash=cash+1
- dest=v
- end
- end
- end
- end
- if dest~=nil then
- objects.coins[dest]=nil
- end
- if cpath == pathing then
- scr = scr+10
- if scr>hs then
- hs=scr
- end
- open = math.random(1,gameWidth-2)
- coin = math.random(1,gameWidth-2)
- table.insert(objects.coins,{["x"]=coin,["y"]=gameHeight-1})
- for i=1,gameWidth-2 do
- if i ~= open then
- table.insert(objects.blocks,{})
- for v,k in ipairs(objects.blocks) do
- if k.x == nil then
- k.x = i+1
- k.y = gameHeight
- break
- end
- end
- for v,k in pairs(objects.blocks) do
- if k.y < gameY then
- v = nil
- k = nil
- end
- end
- cpath = 1
- end
- end
- else
- cpath = cpath + 1
- end
- end
- function text(txt,x,y,format)
- format=foramt or "normal"
- formats={
- ["normal"]=function()
- term.setCursorPos(x,y)
- end,
- ["middle"]=function()
- term.setCursorPos(termx/2-(#txt/2),y)
- end,
- }
- formats["middle"]()
- write(txt)
- end
- function key()
- e,par1 = os.pullEvent("key")
- if tonumber(par1) == 203 then
- if objects.ball.x > 2 then
- objects.ball.x = objects.ball.x - 1
- end
- sleep(0.1)
- elseif tonumber(par1) == 205 then
- if objects.ball.x < gameWidth-1 then
- objects.ball.x = objects.ball.x + 1
- end
- sleep(0.1)
- elseif tonumber(par1) == 25 then
- paused = true
- end
- local dest=nil
- for v,k in pairs(objects.coins) do
- if k ~= nil then
- if k.x == objects.ball.x then
- if k.y == objects.ball.y then
- cash=cash+1
- dest=v
- end
- end
- end
- end
- if dest~=nil then
- objects.coins[dest]=nil
- end
- end
- initvars()
- draw()
- runActions()
- while gameRunning do
- action = 2
- action = parallel.waitForAny(slp,key)
- if paused then
- term.setCursorPos(gameX+(gameWidth/2)-3,gameY+gameHeight/2-1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- write("Paused")
- while true do
- e,p1 = os.pullEvent("key")
- if p1 == 25 then
- sleep(0.1)
- paused = false
- break
- end
- end
- end
- draw()
- if action == 1 then runActions() end
- end
- term.setCursorPos(1,gameY+gameHeight+2)
- term.setTextColor(colors.red)
- if lost then
- print("YOU LOST! D:")
- local fil=fs.open(shell.dir().."/"..shell.getRunningProgram(),"r")
- local prgm = {}
- while true do
- local ln=fil.readLine()
- if ln==nil then break end
- table.insert(prgm,ln)
- end
- fil.close()
- local fil=fs.open(shell.dir().."/"..shell.getRunningProgram(),"w")
- fil.writeLine("hs="..hs)
- fil.writeLine("cash="..cash)
- for i=3,#prgm do
- fil.writeLine(prgm[i])
- end
- fil.close()
- else
- print("Hmm. I think I just crashed, oh well.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement