Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("game")
- mode = {...}
- x = -1
- y = -1
- num2 = 0
- w,h = term.getSize()
- ball = game.createChar(26,8+math.random(4),"O")
- pad1 = game.createChar(1,10,"#")
- pad2 = game.createChar(w,10,"#")
- function bounce()
- time = 0.15
- sleep(time)
- cx,cy = ball:getPos() cx2,cy2 = pad1:getPos() cx3,cy3 = pad2:getPos()
- term.clear()
- for i = -2,2 do
- num1 = cy2 + i
- num2 = cy3 + i
- term.setCursorPos(1,num1)
- write("#")
- term.setCursorPos(w,num2)
- write("#")
- ball:draw()
- if cy == 1 then y = 1 end
- if cy == h then y = -1 end
- if cx == 2 and cy == num1 then x = 1 elseif cx == 1 then error("Right Side Won!",0) end
- if cx == w-1 and cy == num2 then x = -1 elseif cx == w then error("Left Side Won!",0) end
- end
- ball:move(x,y)
- if mode[1] == "single" then pad2:move(w,y) end
- end
- function move()
- _, k = os.pullEvent("key")
- cx1,cy1 = pad1:getPos() cx2,cy2 = pad2:getPos()
- if k == 31 and cy1 < h-2 then pad1:move(0,1) end
- if k == 17 and cy1 > 3 then pad1:move(0,-1) end
- if mode[1] ~= "single" then if k == 200 and cy2 > 3 then pad2:move(0,-1) end end
- if mode[1] ~= "single" then if k == 208 and cy2 < h - 2 then pad2:move(0,1) end end
- end
- while not pause do
- parallel.waitForAny(bounce,move)
- end
Advertisement
Add Comment
Please, Sign In to add comment