SHOW:
|
|
- or go back to the newest paste.
1 | term.redirect(peripheral.wrap("top")) | |
2 | local speaker = peripheral.wrap("right") | |
3 | local speaker2 = peripheral.wrap("left") | |
4 | term.setBackgroundColor(colors.black) | |
5 | term.clear() | |
6 | local w,h = term.getSize() | |
7 | local p1y = (h/2)-2 | |
8 | local p2y = (h/2)-2 | |
9 | local score1 = 0 | |
10 | local score2 = 0 | |
11 | local ballx = w/2 | |
12 | local bally = h/2 | |
13 | local ballvx = -1 | |
14 | local ballvy = 1 | |
15 | function draw() | |
16 | - | term.setBackgroundColor(colors.white) |
16 | + | |
17 | term.clear() | |
18 | term.setBackgroundColor(colors.green) | |
19 | drawPaddle(2, p1y) | |
20 | drawPaddle(w-1, p2y) | |
21 | - | term.setTextColor(colors.white) |
21 | + | |
22 | term.write(" ") | |
23 | term.setTextColor(colors.green) | |
24 | term.setBackgroundColor(colors.black) | |
25 | term.setCursorPos(2, 1) | |
26 | term.write(score1) | |
27 | term.setCursorPos(w-1, 1) | |
28 | term.write(score2) | |
29 | end | |
30 | function drawPaddle(x, y) | |
31 | for i=y,y+5 do | |
32 | term.setCursorPos(x, i) | |
33 | term.write(" ") | |
34 | end | |
35 | end | |
36 | function keyPress() | |
37 | - | if (x >= 15 and y <= 5) then |
37 | + | |
38 | event, side,x, y = os.pullEvent("monitor_touch") | |
39 | if (x >= 15 and y <= 10) then | |
40 | - | if (x >= 15 and y >= 5) then |
40 | + | speaker.playSound("quark:ambient.clock",.3) |
41 | p2y = p2y-1 | |
42 | end | |
43 | - | if (x <= 5 and y <= 5) then |
43 | + | if (x >= 15 and y >= 10) then |
44 | speaker.playSound("quark:ambient.clock",.3) | |
45 | p2y = p2y+1 | |
46 | - | if (x <= 5 and y >= 5) then |
46 | + | |
47 | if (x <= 15 and y <= 10) then | |
48 | speaker.playSound("quark:ambient.clock", .3) | |
49 | p1y = p1y-1 | |
50 | end | |
51 | if (x <= 15 and y >= 10) then | |
52 | speaker.playSound("quark:ambient.clock", .3) | |
53 | p1y = p1y+1 | |
54 | end | |
55 | draw() | |
56 | end | |
57 | end | |
58 | function moveball() | |
59 | while true do | |
60 | sleep(0.1) | |
61 | ballx = ballx + ballvx | |
62 | bally = bally + ballvy | |
63 | - | if ballx > 2 and ballx < 3 and bally > p1y and bally < p1y+5 then |
63 | + | |
64 | speaker2.playSound("quark:entity.pickarang.pickup",.5) | |
65 | ballvy = -ballvy | |
66 | - | if ballx > w-1 and ballx < w and bally > p2y and bally < p2y+5 then |
66 | + | |
67 | if bally < 1 then | |
68 | speaker2.playSound("quark:entity.pickarang.pickup",.5) | |
69 | ballvy = -ballvy | |
70 | end | |
71 | if ballx > 2 and ballx < 3 and bally > p1y and bally < p1y+6 then | |
72 | speaker2.playSound("quark:entity.pickarang.pickup") | |
73 | ballvx = -ballvx | |
74 | end | |
75 | if ballx > w-1 and ballx < w and bally > p2y and bally < p2y+6 then | |
76 | speaker2.playSound("quark:entity.pickarang.pickup",.5) | |
77 | ballvx = -ballvx | |
78 | end | |
79 | if ballx > w then | |
80 | speaker2.playSound("minecraft:entity.player.levelup",.5) | |
81 | score1 = score1+1 | |
82 | ballx = w/2 | |
83 | bally = h/2 | |
84 | ballvx = -1 | |
85 | ballvy = 1 | |
86 | end | |
87 | if ballx < 1 then | |
88 | speaker2.playSound("minecraft:entity.player.levelup",.5) | |
89 | score2 = score2+1 | |
90 | ballx = w/2 | |
91 | bally = h/2 | |
92 | ballvx = 1 | |
93 | ballvy = 1 | |
94 | end | |
95 | draw() | |
96 | end | |
97 | end | |
98 | parallel.waitForAll(keyPress, moveball) |