View difference between Paste ID: KQ9R83Te and msZviCm9
SHOW: | | - or go back to the newest paste.
1
term.redirect(peripheral.wrap("top"))
2-
local speaker = peripheral.wrap("right")
2+
3-
local speaker2 = peripheral.wrap("left")
3+
4
local w,h = term.getSize()
5
local score1 = 0
6
local score2 = 0
7-
local p1y = (h/2)-2
7+
8-
local p2y = (h/2)-2
8+
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-
function keyPress()
36+
37
function moveball()
38-
    event, side,x, y = os.pullEvent("monitor_touch")
38+
39-
    if (x >= 15  and y <= 10) then
39+
40-
	  speaker.playSound("quark:ambient.clock",.3)
40+
41-
      p2y = p2y-1
41+
42
    if bally > h-1 then
43-
    if (x >= 15 and y >= 10) then
43+
44-
      speaker.playSound("quark:ambient.clock",.3)
44+
45-
      p2y = p2y+1
45+
46
    if bally < 1 then
47-
    if (x <= 15 and y <= 10) then
47+
48-
      speaker.playSound("quark:ambient.clock", .3)
48+
49-
      p1y = p1y-1
49+
50
    if ballx > 2 and ballx < 3 and bally > p1y and bally < p1y+6 then
51-
    if (x <= 15 and y >= 10) then
51+
52-
      speaker.playSound("quark:ambient.clock", .3)
52+
53-
      p1y = p1y+1
53+
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()