SHOW:
|
|
- or go back to the newest paste.
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 | term.setCursorPos(ballx, bally) | |
17 | term.write(" ") | |
18 | term.setTextColor(colors.green) | |
19 | term.setBackgroundColor(colors.black) | |
20 | term.setCursorPos(2, 1) | |
21 | term.write(score1) | |
22 | term.setCursorPos(w-1, 1) | |
23 | term.write(score2) | |
24 | end | |
25 | ||
26 | ||
27 | ||
28 | ||
29 | function moveball() | |
30 | while true do | |
31 | sleep(0.1) | |
32 | ballx = ballx + ballvx | |
33 | bally = bally + ballvy | |
34 | if bally > h-1 then | |
35 | ballvy = -ballvy | |
36 | end | |
37 | if bally < 1 then | |
38 | ||
39 | ballvy = -ballvy | |
40 | end | |
41 | if ballx > 2 and ballx < 3 then | |
42 | ballvx = -ballvx | |
43 | end | |
44 | if ballx > w-1 and ballx < w then | |
45 | ballvx = -ballvx | |
46 | end | |
47 | if ballx > w then | |
48 | score1 = score1+1 | |
49 | ballx = w/2 | |
50 | bally = h/2 | |
51 | ballvx = -1 | |
52 | ballvy = 1 | |
53 | end | |
54 | if ballx < 1 then | |
55 | score2 = score2+1 | |
56 | ballx = w/2 | |
57 | bally = h/2 | |
58 | ballvx = 1 | |
59 | ballvy = 1 | |
60 | end | |
61 | draw() | |
62 | end | |
63 | end | |
64 | moveball() |