Advertisement
arismoko

ball test

Oct 7th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. term.redirect(peripheral.wrap("top"))
  2. term.setBackgroundColor(colors.black)
  3. term.clear()
  4. local w,h = term.getSize()
  5. local score1 = 0
  6. local score2 = 0
  7. local ballx = w/2
  8. local bally = h/2
  9. local ballvx = -1
  10. local ballvy = 1
  11.  
  12. function draw()
  13.   term.setBackgroundColor(colors.black)
  14.   term.clear()
  15.   term.setBackgroundColor(colors.green)
  16.   drawPaddle(2, p1y)
  17.   drawPaddle(w-1, p2y)
  18.   term.setCursorPos(ballx, bally)
  19.   term.write(" ")
  20.   term.setTextColor(colors.green)
  21.   term.setBackgroundColor(colors.black)
  22.   term.setCursorPos(2, 1)
  23.   term.write(score1)
  24.   term.setCursorPos(w-1, 1)
  25.   term.write(score2)
  26. end
  27.  
  28. function drawPaddle(x, y)
  29.   for i=y,y+5 do
  30.     term.setCursorPos(x, i)
  31.     term.write(" ")
  32.   end
  33.  
  34.  
  35.  
  36.  
  37. function moveball()
  38.   while true do
  39.     sleep(0.1)
  40.     ballx = ballx + ballvx
  41.     bally = bally + ballvy
  42.     if bally > h-1 then
  43.       speaker2.playSound("quark:entity.pickarang.pickup",.5)
  44.       ballvy = -ballvy
  45.     end
  46.     if bally < 1 then
  47.       speaker2.playSound("quark:entity.pickarang.pickup",.5)
  48.       ballvy = -ballvy
  49.     end
  50.     if ballx > 2 and ballx < 3 and bally > p1y and bally < p1y+6 then
  51.       speaker2.playSound("quark:entity.pickarang.pickup")
  52.       ballvx = -ballvx
  53.     end
  54.     if ballx > w-1 and ballx < w and bally > p2y and bally < p2y+6 then
  55.       speaker2.playSound("quark:entity.pickarang.pickup",.5)
  56.       ballvx = -ballvx
  57.     end
  58.     if ballx > w then
  59.       speaker2.playSound("minecraft:entity.player.levelup",.5)
  60.       score1 = score1+1
  61.       ballx = w/2
  62.       bally = h/2
  63.       ballvx = -1
  64.       ballvy = 1
  65.     end
  66.     if ballx < 1 then
  67.       speaker2.playSound("minecraft:entity.player.levelup",.5)
  68.       score2 = score2+1
  69.       ballx = w/2
  70.       bally = h/2
  71.       ballvx = 1
  72.       ballvy = 1
  73.     end
  74.     draw()
  75.   end
  76. end
  77. moveball()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement