Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sx, sy = term.getSize()
- local cx, cy = sx/2+1, sy/2+1
- local gx, gy = 20, sy-1
- local gameWindow
- local spaceWidth = 3
- local playerY = 3
- local emptyY = 3
- local playerSymbol = "&"
- local function randomObstacle( y )
- local x = math.random( 2, gx-1-spaceWidth )
- term.setCursorPos( 1, y )
- term.setBackgroundColor( colors.white )
- term.clearLine()
- paintutils.drawLine( x, y, x + spaceWidth, y, colors.black )
- return x
- end
- local function play()
- term.setBackgroundColor(colors.gray)
- term.clear()
- gameWindow = window.create( term.current(), cx-gx/2, 2, gx, gy )
- term.redirect(gameWindow)
- term.clear()
- local playerX = gx/2
- parallel.waitForAny( function()
- local i = -1
- local spaces = {}
- while true do
- while #spaces>7 do
- spaces[#spaces] = nil
- end
- i = i<emptyY and i+1 or 0
- if i == 0 then
- table.insert( spaces, 1, randomObstacle( gy ) )
- elseif i == 3 and #spaces > 3 and ( playerX < spaces[4] or playerX > spaces[4] + spaceWidth ) then
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.red)
- term.setCursorPos( playerX, playerY )
- term.write " "
- return
- end
- sleep(.5)
- term.setCursorPos( playerX, playerY )
- term.write " "
- gameWindow.scroll( 1 )
- term.setCursorPos( playerX, playerY )
- term.write "&"
- end
- end, function()
- while true do
- local _, key = os.pullEvent "key"
- if key == keys.a and playerW ~= 1 then
- playerX = playerX-1
- term.setCursorPos( playerX, playerY )
- term.write( playerSymbol .. " " )
- elseif key == keys.d and playerW ~= gx then
- playerX = playerX+1
- term.setCursorPos( playerX-1, playerY )
- term.write( " " .. playerSymbol )
- end
- end
- end )
- end
- play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement