Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("top")
- mon.setBackgroundColor(colors.black)
- mon.setTextScale(0.5)
- mon.setCursorPos(1,1)
- mon.clear()
- --mon.write(x.." "..y)
- --variables
- x,y = mon.getSize() --5x2 screen: x = 100, y = 38 | non scalable on this alpha
- score1 = 0 --P1's score
- score2 = 0 --P2's score
- dy = nil
- dx = nil
- y1 = 19
- y2 = 19
- pos = {} --pos of the ball
- --functions
- function updater(y1,y2,score1,score2,dx,dy,pos)
- mon.clear()
- local i = -2
- local j = 0
- while(i<=3) do
- mon.setCursorPos(3,y1+i)
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- mon.setCursorPos(4,y1+i)
- mon.write(" ")
- i = i + 1
- mon.setBackgroundColor(colors.black)
- end
- i = -2
- while(i<=3) do
- mon.setCursorPos(97,y2+i)
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- mon.setCursorPos(98,y2+i)
- mon.write(" ")
- i = i + 1
- mon.setBackgroundColor(colors.black)
- end
- i = 3
- mon.setCursorPos(50,i)
- while (i<=38) do
- if(j==0) then
- mon.setCursorPos(50,i)
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- j = 1
- else
- mon.setCursorPos(50,i)
- mon.setBackgroundColor(colors.black)
- j = 0
- end
- i = i+1
- end
- mon.setBackgroundColor(colors.gray)
- i = 1
- while(i<=100) do
- mon.setCursorPos(i,1)
- mon.write(" ")
- i = i + 1
- end
- i = 1
- while(i<=100) do
- mon.setCursorPos(i,38)
- mon.write(" ")
- i = i + 1
- end
- --affichage
- mon.setBackgroundColor(colors.black)
- if(score1==nil) then score1 = 0 end
- mon.setCursorPos(40,3)
- if(score1<10) and (score1>=0) then mon.write("0"..score1) else mon.write(""..score1) end
- if(score2==nil) then score2 = 0 end
- mon.setCursorPos(59,3)
- if(score2<10) and (score2>=0) then mon.write("0"..score2) else mon.write(""..score2) end
- if(dx == nil) then dx = 0 end
- if(dy == nil) then dy = 0 end
- --if pos == nil then pos = {} end
- if(pos[1] == nil) then pos[1] = 50 end
- if(pos[2] == nil) then pos[2] = 19 end
- return y1, y2, score1, score2, dx,dy,pos
- end
- function updateBall(dx,dy,pos)
- return dx, dy, pos
- end
- --initialisation
- --start of the game
- --function initBall(dx,dy)
- --pos[1] = 50
- --pos[2] = 19
- --pos[1] = pos[1]+ dx
- --pos[2] = pos[2]+ dy *(39/100)
- --end
- function processBall(dx,dy,pos,y1,y2)
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(pos[1],pos[2])
- mon.write("()")
- mon.setTextColor(colors.white)
- if(pos[2]==37 or pos[2]==2) then
- dy = - dy
- end
- if(pos[1]+1 >=95) then
- print("sup") end
- pos[1] = pos[1]+ dx
- pos[2] = pos[2]+ dy --*(39/100)
- print(pos[1] .. " "..pos[2])
- end
- --updater()
- --main loop
- function main_loop()
- dx=1
- dy=0
- while true do
- --test
- y1,y2,score1,score2,dx,dy,pos = updater(y1,y2,score1,score2,dx,dy,pos)
- processBall(dx,dy,pos,y1,y2)
- os.sleep(0.1)
- end
- end
- function touch()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if xPos<50 then
- if yPos<19 then
- if y1>=6 then
- y1 = y1-2
- end
- else
- if y1<=32 then
- y1 = y1+2
- end
- end
- elseif xPos>50 then
- if yPos<19 then
- if y2>=6 then
- y2 = y2-2
- end
- else
- if y2<=32 then
- y2 = y2+2
- end
- end
- end
- end
- end
- --main call
- parallel.waitForAny(main_loop,touch)
- --copyright appollon41 v1.0
Add Comment
Please, Sign In to add comment