appollon41

Untitled

Apr 26th, 2022 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. mon.setBackgroundColor(colors.black)
  3. mon.setTextScale(0.5)
  4. mon.setCursorPos(1,1)
  5. mon.clear()
  6.  
  7. --mon.write(x.." "..y)
  8.  
  9. --variables
  10. x,y = mon.getSize() --5x2 screen: x = 100, y = 38 | non scalable on this alpha
  11.  
  12. score1 = 0 --P1's score
  13. score2 = 0 --P2's score
  14.  
  15. dy = nil
  16. dx = nil
  17.  
  18. y1 = 19
  19. y2 = 19
  20.  
  21. pos = {} --pos of the ball
  22.  
  23. --functions
  24.  
  25. function updater(y1,y2,score1,score2,dx,dy,pos)
  26. mon.clear()
  27. local i = -2
  28. local j = 0
  29.  
  30. while(i<=3) do
  31. mon.setCursorPos(3,y1+i)
  32. mon.setBackgroundColor(colors.white)
  33. mon.write(" ")
  34. mon.setCursorPos(4,y1+i)
  35. mon.write(" ")
  36. i = i + 1
  37. mon.setBackgroundColor(colors.black)
  38. end
  39.  
  40. i = -2
  41.  
  42. while(i<=3) do
  43. mon.setCursorPos(97,y2+i)
  44. mon.setBackgroundColor(colors.white)
  45. mon.write(" ")
  46. mon.setCursorPos(98,y2+i)
  47. mon.write(" ")
  48. i = i + 1
  49. mon.setBackgroundColor(colors.black)
  50. end
  51.  
  52. i = 3
  53.  
  54. mon.setCursorPos(50,i)
  55.  
  56. while (i<=38) do
  57. if(j==0) then
  58. mon.setCursorPos(50,i)
  59. mon.setBackgroundColor(colors.white)
  60. mon.write(" ")
  61. j = 1
  62. else
  63. mon.setCursorPos(50,i)
  64. mon.setBackgroundColor(colors.black)
  65. j = 0
  66. end
  67. i = i+1
  68. end
  69. mon.setBackgroundColor(colors.gray)
  70.  
  71. i = 1
  72.  
  73.  
  74. while(i<=100) do
  75. mon.setCursorPos(i,1)
  76. mon.write(" ")
  77. i = i + 1
  78. end
  79.  
  80. i = 1
  81.  
  82. while(i<=100) do
  83. mon.setCursorPos(i,38)
  84. mon.write(" ")
  85. i = i + 1
  86. end
  87.  
  88. --affichage
  89.  
  90. mon.setBackgroundColor(colors.black)
  91.  
  92. if(score1==nil) then score1 = 0 end
  93. mon.setCursorPos(40,3)
  94. if(score1<10) and (score1>=0) then mon.write("0"..score1) else mon.write(""..score1) end
  95. if(score2==nil) then score2 = 0 end
  96. mon.setCursorPos(59,3)
  97. if(score2<10) and (score2>=0) then mon.write("0"..score2) else mon.write(""..score2) end
  98.  
  99. if(dx == nil) then dx = 0 end
  100. if(dy == nil) then dy = 0 end
  101.  
  102. --if pos == nil then pos = {} end
  103.  
  104. if(pos[1] == nil) then pos[1] = 50 end
  105. if(pos[2] == nil) then pos[2] = 19 end
  106.  
  107. return y1, y2, score1, score2, dx,dy,pos
  108.  
  109. end
  110.  
  111.  
  112. function updateBall(dx,dy,pos)
  113.  
  114. return dx, dy, pos
  115. end
  116.  
  117. --initialisation
  118.  
  119.  
  120.  
  121. --start of the game
  122.  
  123. --function initBall(dx,dy)
  124. --pos[1] = 50
  125. --pos[2] = 19
  126. --pos[1] = pos[1]+ dx
  127. --pos[2] = pos[2]+ dy *(39/100)
  128. --end
  129.  
  130. function processBall(dx,dy,pos,y1,y2)
  131. mon.setTextColor(colors.yellow)
  132. mon.setCursorPos(pos[1],pos[2])
  133. mon.write("()")
  134. mon.setTextColor(colors.white)
  135.  
  136. if(pos[2]==37 or pos[2]==2) then
  137. dy = - dy
  138. end
  139.  
  140. if(pos[1]+1 >=95) then
  141. print("sup") end
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. pos[1] = pos[1]+ dx
  151. pos[2] = pos[2]+ dy --*(39/100)
  152. print(pos[1] .. " "..pos[2])
  153. end
  154.  
  155. --updater()
  156.  
  157.  
  158. --main loop
  159. function main_loop()
  160. dx=1
  161. dy=0
  162. while true do
  163. --test
  164.  
  165. y1,y2,score1,score2,dx,dy,pos = updater(y1,y2,score1,score2,dx,dy,pos)
  166.  
  167. processBall(dx,dy,pos,y1,y2)
  168.  
  169. os.sleep(0.1)
  170. end
  171. end
  172.  
  173. function touch()
  174.  
  175. while true do
  176.  
  177. event, side, xPos, yPos = os.pullEvent("monitor_touch")
  178.  
  179. if xPos<50 then
  180. if yPos<19 then
  181.  
  182. if y1>=6 then
  183. y1 = y1-2
  184. end
  185. else
  186. if y1<=32 then
  187. y1 = y1+2
  188. end
  189. end
  190. elseif xPos>50 then
  191. if yPos<19 then
  192. if y2>=6 then
  193. y2 = y2-2
  194. end
  195. else
  196. if y2<=32 then
  197. y2 = y2+2
  198. end
  199. end
  200.  
  201. end
  202.  
  203. end
  204.  
  205.  
  206. end
  207. --main call
  208.  
  209. parallel.waitForAny(main_loop,touch)
  210.  
  211. --copyright appollon41 v1.0
Add Comment
Please, Sign In to add comment