Advertisement
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()
- -- Player 1
- if (redstone.getAnalogInput("back") > 0) then --P1 left
- x1=x1+2
- end
- if (redstone.getAnalogInput("left") > 0) then --P1 right
- x1=x1-2
- end
- if (x1<1) then x1=1 end
- if (x1>29-width1) then x1=29-width1 end
- -- Player 2
- if (redstone.getAnalogInput("right") > 0) then --P2 left
- x2=x2+2
- end
- if (redstone.getAnalogInput("front") > 0) then --P2 right
- x2=x2-2
- end
- 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 or bx>=29)then
- sx=sx*-1
- end
- 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
- end
- -- Player 2 collision
- if (bx>=x2 and bx<=x2+width2 and by>=31)then
- sy=sy*-1
- end
- -- Random movement
- if (math.random(0,50) == 0) then
- bx=bx+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
- 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
- Movement()
- Paint()
- sleep(0.2)
- if(p1>10 or p2>10) then
- loop=false
- p1,p2 = 0,0
- end
- end
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement