SHOW:
|
|
- or go back to the newest paste.
1 | term.redirect(peripheral.wrap("top")) | |
2 | local speaker = peripheral.wrap("right") | |
3 | local nSize, bNew, nBase, stack, maxx, maxy = 8, true, 0, {}, term.getSize() | |
4 | ||
5 | stack[ 0 ] = { math.floor( maxx/2 ) - 4, math.floor( maxx/2 ) + 4, bReverse = false } | |
6 | ||
7 | local function gameOver() | |
8 | term.clear() | |
9 | local str = "Game Over! Your Score: " .. #stack - 1 | |
10 | term.setCursorPos( math.floor( (maxx - #str) / 2 ), maxy / 2 ) | |
11 | print( str ) | |
12 | term.setCursorPos( 1, 1 ) | |
13 | error() | |
14 | end | |
15 | ||
16 | local function renderStack() | |
17 | if #stack - nBase > maxy / 2 then | |
18 | nBase = nBase + 1 | |
19 | end | |
20 | term.setBackgroundColor( colors.red ) | |
21 | for i = 0, #stack do | |
22 | if i + nBase > #stack then | |
23 | break | |
24 | end | |
25 | term.setCursorPos( stack[ i + nBase ][ 1 ], maxy - i ) | |
26 | term.write( string.rep( " ", stack[ i + nBase ][2] - stack[ i + nBase ][1] ) ) | |
27 | end | |
28 | term.setBackgroundColor( colors.black ) | |
29 | ||
30 | end | |
31 | speaker.playSound("minecraft:music_disc.pigstep",.7) | |
32 | ||
33 | local function getInput() | |
34 | local new = bNew and { 1, nSize + 1, bReverse = false } or stack[ #stack ] | |
35 | local id = os.startTimer( 0.1 * (0.99^#stack) ) | |
36 | while true do | |
37 | local event, side, x, y = { os.pullEvent() } | |
38 | if event[ 1 ] == "timer" and event[ 2 ] == id then | |
39 | if not new.bReverse then | |
40 | new[ 1 ] = new[ 1 ] + 1 | |
41 | new[ 2 ] = new[ 2 ] + 1 | |
42 | if new[ 2 ] > maxx then | |
43 | new.bReverse = true | |
44 | end | |
45 | else | |
46 | new[ 1 ] = new[ 1 ] - 1 | |
47 | new[ 2 ] = new[ 2 ] - 1 | |
48 | if new[ 1 ] <= 1 then | |
49 | new.bReverse = false | |
50 | end | |
51 | end | |
52 | if bNew then | |
53 | stack[ #stack + 1 ] = new | |
54 | bNew = false | |
55 | end | |
56 | break | |
57 | elseif event[ 1 ] == "monitor_touch" then | |
58 | if new[ 1 ] < ( bNew and stack[ #stack ][ 1 ] or stack[ #stack - 1 ][ 1 ] ) then | |
59 | new[ 1 ] = ( bNew and stack[ #stack ][ 1 ] or stack[ #stack - 1 ][ 1 ] ) | |
60 | end | |
61 | if new[ 2 ] > ( bNew and stack[ #stack ][ 2 ] or stack[ #stack - 1 ][ 2 ] ) then | |
62 | new[ 2 ] = ( bNew and stack[ #stack ][ 2 ] or stack[ #stack - 1 ][ 2 ] ) | |
63 | end | |
64 | if new[ 2 ] - new[ 1 ] <= 0 then | |
65 | speaker.playSound("minecraft:entity.chicken.death",.3) | |
66 | gameOver() | |
67 | end | |
68 | nSize = new[ 2 ] - new[ 1 ] | |
69 | if bNew then | |
70 | stack[ #stack + 1 ] = new | |
71 | else | |
72 | stack[ #stack ] = new | |
73 | bNew = true | |
74 | end | |
75 | break | |
76 | end | |
77 | end | |
78 | end | |
79 | ||
80 | while true do | |
81 | term.clear() | |
82 | renderStack() | |
83 | getInput() | |
84 | end |