Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- local width1,width2 = 5,5
- local x1,x2=13,12
- local bx,by,sx,sy = 15,17,2,1
- -- Score
- local p1,p2 = 0,0
- --Resolution x=29 y=33
- function Movement()
- if (x2<1) then x2=1 end
- if (x2>29-width2) then x2=29-width2 end
- -- Ball movement
- bx=bx+sx
- by=by+sy
- -- Wall collision
- if (bx<1) then
- sx=(sx*-1)
- bx = 2
- elseif (bx>29) then
- sx=(sx*-1)
- bx = 28
- end
- -- Score?
- if (by<=1)then
- bx,by = 15,17
- p2=p2+1
- sy=sy*-1
- elseif (by>=33) then
- bx,by = 15,17
- p1=p1+1
- sy=sy*-1
- end
- -- Player 1 collision
- if (bx>=x1 and bx<=x1+width1 and by<=3)then
- sy=(sy*-1) -- + math.random(-2,2)
- bx = bx + math.random(-1,1)
- end
- -- Player 2 collision
- if (bx>=x2 and bx<=x2+width2 and by>=31)then
- sy=(sy*-1) -- + math.random(-2,2)
- bx = bx + math.random(-1,1)
- end
- end
- function Paint()
- term.setBackgroundColor(colors.white)
- term.clear()
- -- Score
- term.setTextColor(colors.black)
- term.setCursorPos(13,20)
- term.write(tostring(p1) .. " - " .. tostring(p2))
- -- Middle bar
- paintutils.drawLine(1,17,12,17,colors.lightGray)
- paintutils.drawBox(13,15,17,19,colors.lightGray)
- paintutils.drawLine(18,17,29,17,colors.lightGray)
- -- Areas
- paintutils.drawBox(6,0,24,5,colors.lightGray)
- paintutils.drawBox(6,34,24,29,colors.lightGray)
- -- Player1 bar
- paintutils.drawLine(x1,2,x1+width1,2,colors.blue)
- -- Player2 bar
- paintutils.drawLine(x2,32,x2+width2,32,colors.red)
- -- Ball
- paintutils.drawPixel(bx,by,colors.green)
- end
- -- Main --
- term.redirect(monitor)
- while(true) do
- sx, sy = 2,1
- Paint()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.yellow)
- term.setCursorPos(10,22)
- term.write("INSERT COIN")
- if (redstone.getAnalogInput("bottom") > 0) then
- local loop = true
- while(loop) do
- parallel.waitForAny(function()
- local event, button, x, y = os.pullEvent("monitor_touch")
- if (y > 16) then
- x2 = x-2
- else
- x1 = x-2
- end
- end,
- function()
- Movement()
- Paint()
- sleep(0.2)
- if(p1>10 or p2>10) then
- loop=false
- p1,p2 = 0,0
- end
- end)
- end
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment