Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local file = fs.open("lgame/lgame","r")
- if file then
- file.close()
- os.loadAPI('/lg/lg')
- lg.setup('term')
- os.loadAPI("uap")
- os.loadAPI("/lgame/lgame")
- lgame.setup("term")
- lg.fillScreen(colors.black)
- local im1 = fs.open("/pong/ball.nfp","r")
- if im1 then
- im1.close()
- else
- shell.run("pastebin","get","cnJQa66z","/pong/wall.nfp")
- shell.run("pastebin","get","sJBDTsfR","/pong/ball.nfp")
- lg.drawText(1,1,colors.white,colors.black,"Downloading sprites...")
- os.sleep(1)
- lg.fillScreen(colors.black)
- end
- lgame.lggSetDefBG(colors.black)
- local lefty = 1
- lgame.drawSprite('left',2,2,'/pong/wall.nfp')
- local spwx = math.random (10, lgame.getSize().x-2)
- local spwy = math.random (3, lgame.getSize().y-1)
- lgame.drawSprite("ball",spwx,spwy,"/pong/ball.nfp")
- local px = spwx
- local py = spwy
- local dir = math.random (1, 4)
- colided = false
- local ly = 1
- local speed = 0.2
- local c = 0
- local d = false
- os.sleep(0.1)
- local function dt(text)
- lgame.fill(1,lgame.getSize().x,lgame.getSize().y,lgame.getSize().y,colors.black)
- lgame.drawText(1,lgame.getSize().y,colors.white,colors.black,text)
- end
- dt("3")
- os.sleep(1)
- dt("2")
- os.sleep(1)
- dt("1")
- os.sleep(1)
- --lgame.drawText(1,10,colors.white,colors.black,"SIZE: "..lgame.getSize().x.." "..lgame.getSize().y)
- function click()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.w then
- if ly ~= 1 then
- ly = ly - 1
- end
- elseif key == keys.s then
- if lgame.getSpriteColider("left").y2 ~= lgame.getSize().y then
- ly = ly + 1
- end
- elseif key == keys.e then
- os.reboot()
- end
- lgame.moveSprite("left",2,ly)
- end
- end
- function game()
- local i = 1
- while true do
- d = false
- --local bal = lgame.getSpriteColider("ball").x
- if lgame.getSpriteColider('ball').x == 1 then
- lg.fillScreen(colors.black)
- lg.drawText(9,9,colors.white,colors.black, 'You lose! R: '..c)
- break
- end
- i = i + 1
- if not (px == lgame.getSize().x + 1 and py == lgame.getSize().y+1) then
- if px <= lgame.getSize().x and px > 0 then
- if py <= lgame.getSize().y and py > 0 then
- if lgame.getSpriteColider("ball").x == lgame.getSize().x and dir == 1 then
- dir = 3
- elseif lgame.getSpriteColider("ball").x == lgame.getSize().x and dir == 2 then
- dir = 4
- elseif lgame.getSpriteColider("ball").x == 1 and dir == 4 then
- dir = 2
- elseif lgame.getSpriteColider("ball").x == 1 and dir == 3 then
- dir = 4
- elseif lgame.getSpriteColider("ball").y == lgame.getSize().y and dir == 1 then
- dir = 2
- elseif lgame.getSpriteColider("ball").y == lgame.getSize().y and dir == 3 then
- dir = 4
- elseif lgame.getSpriteColider("ball").y == 1 and dir == 2 then
- dir = 1
- elseif lgame.getSpriteColider("ball").y == 1 and dir == 4 then
- dir = 3
- end
- elseif py == 0 then
- d = true
- if (dir == 4) then
- dir = 3
- else
- dir = 1
- end
- elseif py == lgame.getSize().y+1 then
- d = true
- if (dir == 3) then
- dir = 4
- else
- dir = 2
- end
- end
- elseif px < 1 then
- d = true
- if (dir == 4) then
- dir = 2
- else
- dir = 1
- end
- elseif px == lgame.getSize().x+1 then
- d = true
- if (dir == 1) then
- dir = 3
- else
- dir = 4
- end
- end
- if dir == 1 then
- px = px + 1
- py = py + 1
- elseif dir == 2 then
- px = px + 1
- py = py - 1
- elseif dir == 3 then
- px = px - 1
- py = py + 1
- elseif dir == 4 then
- px = px - 1
- py = py - 1
- end
- if not d then
- lgame.moveSprite("ball",px,py)
- end
- os.sleep(speed)
- dt("Score: "..c.." | EXIT - E")
- else
- break
- end
- if colided == false and lgame.isColiding("ball","left") then
- lgame.moveSprite("ball",lgame.getSpriteColider("ball").x+2,lgame.getSpriteColider("ball").y)
- speed = speed - 0.01
- colided = true
- c = c + 1
- if dir == 4 then
- dir = 2
- elseif dir == 3 then
- dir = 1
- end
- else
- colided = false
- end
- end
- end
- parallel.waitForAny(click,game)
- lg.drawBT('end',1,4,19,19,colors.white,colors.black,'exit')
- while true do
- local event, button, x, y = os.pullEvent( "mouse_click" )
- if (lg.isButton(x,y) == "end") then
- os.reboot()
- end
- end
- lg.exit()
- lgame.exit()
- else
- term.clear()
- term.setCursorPos(1,2)
- term.write("Install lgame from updater!")
- uap.upd()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement