Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- term.clear()
- --width = 51
- --height = 19
- local ballXPos = 19
- local ballYPos = 9
- local lPos = 9
- local rPos = 9
- local lScore = 0
- local rScore = 0
- local ballDir = 1
- local ballAngle = 1
- local waits = 0
- local game = true
- local monitor = nil
- local textSize = 1
- if args[1] == nil then
- maxScore = 15
- else
- maxScore = args[1]*1
- end
- if args[2] == "mon" or args[2] == "monitor" then
- textSize = args[3]
- monitor = peripheral.find("monitor")
- if not monitor then
- term.clear()
- term.setCursorPos(1, 1)
- print("No monitor found")
- error()
- end
- monitor.setTextScale(textSize)
- end
- local drawField = function()
- term.setCursorPos(1, 1)
- term.write("Bryceio Industries: PONG =======================================")
- term.setCursorPos(ballXPos, ballYPos)
- term.write("O")
- for i = (lPos-2),(lPos+2) do
- term.setCursorPos(4, i)
- term.write("|")
- end
- for i = (rPos-2),(rPos+2) do
- term.setCursorPos(36, i)
- term.write("|")
- end
- for i = 2, 18 do
- term.setCursorPos(39, i)
- term.write("||")
- end
- term.setCursorPos(41, 4)
- print("Left: "..lScore)
- term.setCursorPos(41, 6)
- print("Right: "..rScore)
- term.setCursorPos(41, 9)
- print("Max: "..maxScore)
- for i = 1, 51 do
- term.setCursorPos(i, 19)
- term.write("=")
- end
- end
- local controls = function()
- keytimer = os.startTimer(0.4)
- event, key = os.pullEvent()
- if event == "key" then
- sleep(0.2)
- if key == 200 and (lPos > 4)then
- lPos = lPos - 1
- end
- if key == 208 and (lPos < 16) then
- lPos = lPos + 1
- end
- elseif event == "timer" and key == keytimer then
- end
- end
- local drawFieldMonitor = function()
- monitor.setCursorPos(1, 1)
- monitor.write("Bryceio Industries: PONG =======================================")
- monitor.setCursorPos(ballXPos, ballYPos)
- monitor.write("O")
- for i = (lPos-2),(lPos+2) do
- monitor.setCursorPos(4, i)
- monitor.write("|")
- end
- for i = (rPos-2),(rPos+2) do
- monitor.setCursorPos(36, i)
- monitor.write("|")
- end
- for i = 2, 18 do
- monitor.setCursorPos(39, i)
- monitor.write("||")
- end
- monitor.setCursorPos(41, 4)
- monitor.write("Left: "..lScore)
- monitor.setCursorPos(41, 6)
- monitor.write("Right: "..rScore)
- monitor.setCursorPos(41, 9)
- monitor.write("Max: "..maxScore)
- for i = 1, 51 do
- monitor.setCursorPos(i, 19)
- monitor.write("=")
- end
- end
- while game do
- term.clear()
- drawField()
- if monitor ~= nil then
- drawFieldMonitor()
- end
- controls()
- ballXPos = ballXPos + ballDir
- ballYPos = ballYPos + ballAngle
- if ballYPos > 18 or ballYPos < 2 then
- ballYPos = ballYPos - ballAngle
- ballAngle = ballAngle * -1
- end
- if ballXPos == 4 then
- if ballYPos == lPos-3 then
- ballDir = 1
- ballAngle = -2
- ballXPos = ballXPos + 1
- elseif ballYPos >= lPos-2 and ballYPos <= lPos then
- ballDir = 1
- ballAngle = -1
- ballXPos = ballXPos + 1
- elseif ballYPos <= lPos+2 and ballYPos > lPos then
- ballDir = 1
- ballAngle = 1
- ballXPos = ballXPos + 1
- elseif ballYPos == lPos+3 then
- ballDir = 1
- ballAngle = 2
- ballXPos = ballXPos + 1
- end
- elseif ballXPos == 36 then
- if ballYPos == rPos-3 then
- ballDir = -1
- ballAngle = -2
- ballXPos = ballXPos - 1
- elseif ballYPos >= rPos-2 and ballYPos <= rPos then
- ballDir = -1
- ballAngle = -1
- ballXPos = ballXPos - 1
- elseif ballYPos <= rPos+2 and ballYPos > rPos then
- ballDir = -1
- ballAngle = 1
- ballXPos = ballXPos - 1
- elseif ballYPos == rPos+3 then
- ballDir = -1
- ballAngle = 2
- ballXPos = ballXPos - 1
- end
- end
- if rPos < ballYPos and waits > 5 then
- rPos = rPos + 1
- waits = 0
- elseif rPos > ballYPos and waits > 5 then
- rPos = rPos - 1
- waits = 0
- elseif waits <= 5 then
- waits = waits + 1
- end
- if ballXPos < 1 then
- ballXPos = 19
- rScore = rScore + 1
- lPos = 9
- rPos = 9
- end
- if ballXPos > 38 then
- ballXPos = 19
- ballYPos = 9
- lScore = lScore + 1
- lPos = 9
- rPos = 9
- end
- if rScore >= maxScore then
- term.setCursorPos(41, 12)
- term.write("Right Wins")
- term.setCursorPos(1, 19)
- game = false
- elseif lScore >= maxScore then
- term.setCursorPos(41, 12)
- term.write("Left Wins")
- term.setCursorPos(1, 19)
- game = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement