Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.redirect(peripheral.wrap("top"))
- local speaker = peripheral.wrap("right")
- local speaker2 = peripheral.wrap("left")
- term.setBackgroundColor(colors.black)
- term.clear()
- local w,h = term.getSize()
- local p1y = (h/2)-2
- local p2y = (h/2)-2
- local score1 = 0
- local score2 = 0
- local ballx = w/2
- local bally = h/2
- local ballvx = -1
- local ballvy = 1
- function draw()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setBackgroundColor(colors.green)
- drawPaddle(2, p1y)
- drawPaddle(w-1, p2y)
- term.setCursorPos(ballx, bally)
- term.write(" ")
- term.setTextColor(colors.green)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(2, 1)
- term.write(score1)
- term.setCursorPos(w-1, 1)
- term.write(score2)
- end
- function drawPaddle(x, y)
- for i=y,y+5 do
- term.setCursorPos(x, i)
- term.write(" ")
- end
- end
- function keyPress()
- while true do
- event, side,x, y = os.pullEvent("monitor_touch")
- if (x >= 15 and y <= 10) then
- speaker.playSound("quark:ambient.clock",.3)
- p2y = p2y-1
- end
- if (x >= 15 and y >= 10) then
- speaker.playSound("quark:ambient.clock",.3)
- p2y = p2y+1
- end
- if (x <= 15 and y <= 10) then
- speaker.playSound("quark:ambient.clock", .3)
- p1y = p1y-1
- end
- if (x <= 15 and y >= 10) then
- speaker.playSound("quark:ambient.clock", .3)
- p1y = p1y+1
- end
- draw()
- end
- end
- function moveball()
- while true do
- sleep(0.1)
- ballx = ballx + ballvx
- bally = bally + ballvy
- if bally > h-1 then
- speaker2.playSound("quark:entity.pickarang.pickup",.5)
- ballvy = -ballvy
- end
- if bally < 1 then
- speaker2.playSound("quark:entity.pickarang.pickup",.5)
- ballvy = -ballvy
- end
- if ballx > 2 and ballx < 3 and bally > p1y and bally < p1y+6 then
- speaker2.playSound("quark:entity.pickarang.pickup")
- ballvx = -ballvx
- end
- if ballx > w-1 and ballx < w and bally > p2y and bally < p2y+6 then
- speaker2.playSound("quark:entity.pickarang.pickup",.5)
- ballvx = -ballvx
- end
- if ballx > w then
- speaker2.playSound("minecraft:entity.player.levelup",.5)
- score1 = score1+1
- ballx = w/2
- bally = h/2
- ballvx = -1
- ballvy = 1
- end
- if ballx < 1 then
- speaker2.playSound("minecraft:entity.player.levelup",.5)
- score2 = score2+1
- ballx = w/2
- bally = h/2
- ballvx = 1
- ballvy = 1
- end
- draw()
- end
- end
- parallel.waitForAll(keyPress, moveball)
Add Comment
Please, Sign In to add comment