Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [SublimeLinter luacheck-globals:term,colours,textutils,keys,blittle,shell,sleep,fs,window]
- -- The Zombease installer, by viluon (Andrew Kvapil) http://viluon.me
- --[[
- Arguments:
- dont Don't actually run the install coroutine
- update Set the message to the update version
- no-msg Don't display a result message
- --]]
- if not term.isColour or not term.isColour() then
- print( "It appears that your computer does not support colours."
- .. "Zombies love colours, especially green, the colour of a rotting body, or blue, the colour of your brain."
- .. "Please get yourself an advanced computer before inviting zombies for a feast." )
- end
- local args = { ... }
- local old_term = term.current()
- local w, h = old_term.getSize()
- local main_win = window.create( old_term, 1, 1, w, h, false )
- local nil_win = window.create( old_term, 1, 1, w, h, false )
- term.redirect( nil_win )
- local running = true
- local greens = {
- colours.green, colours.green, colours.green, colours.lime, colours.lightGrey
- }
- local arguments = {}
- for _, v in ipairs( args ) do
- arguments[ v ] = true
- end
- local heading = arguments.update and "Zombease is updating" or "Zombease will infect your computer"
- local time = arguments.update and "please wait" or "in a few moments"
- --- Install Zombease
- -- @return nil
- local function install()
- if not arguments.dont then
- shell.run( "pastebin", "run", "W5ZkVYSi", "viluon", "Zombease" )
- end
- sleep( 0 )
- end
- --- Write something in fancy zombie-like colours.
- -- @param target description
- -- @param text description
- -- @return nil
- local function fancy_write( target, text )
- for i = 1, #text do
- target.setTextColour( greens[ math.random( 1, #greens ) ] )
- target.write( text:sub( i, i ) )
- end
- end
- --- Draw the GUI
- -- @return nil
- local function redraw( dont, colour )
- colour = colour or colours.white
- repeat
- main_win.setVisible( false )
- main_win.setBackgroundColour( colours.black )
- main_win.setTextColour( colour )
- main_win.clear()
- main_win.setCursorPos( w / 2 - #heading / 2, h / 2 )
- if dont then
- main_win.write( heading )
- else
- fancy_write( main_win, heading )
- end
- main_win.setCursorPos( w / 2 - #time / 2, h / 2 + 1 )
- if dont then
- main_win.write( time )
- else
- fancy_write( main_win, time )
- end
- main_win.setVisible( true )
- sleep( 0.1 )
- until dont
- end
- local coroutines = {
- coroutine.create( install );
- coroutine.create( redraw );
- }
- redraw( true, colours.black )
- redraw( true, colours.grey )
- redraw( true, colours.lightGrey )
- -- First yield
- for i, coro in ipairs( coroutines ) do
- local ok, err = coroutine.resume( coro )
- if not ok then
- term.redirect( old_term )
- term.setTextColour( colours.lightGrey )
- term.clear()
- term.setCursorPos( 1, 1 )
- print( "Damn it! Zombies from the invasion tactics team " .. i
- .. " killed each other over some brain leftovers, before the invasion could start. "
- .. "The last one alive said it's because you" )
- error( err, 0 )
- end
- end
- local ok, err, source
- while running do
- local ev = { os.pullEvent() }
- for key, coro in ipairs( coroutines ) do
- ok, err = coroutine.resume( coro, unpack( ev ) )
- source = key
- if coroutine.status( coro ) == "dead" then
- running = false
- break
- end
- if not ok then
- running = false
- break
- end
- end
- end
- redraw( true, colours.lightGrey )
- redraw( true, colours.grey )
- redraw( true, colours.black )
- term.redirect( old_term )
- if arguments[ "no-msg" ] and ok then
- return
- end
- term.setBackgroundColour( colours.black )
- term.clear()
- term.setCursorPos( 1, 1 )
- if ok then
- term.setTextColour( colours.white )
- print( "Success! Run menu.lua to launch the game." )
- term.setCursorPos( 1, 2 )
- return
- else
- term.setTextColour( colours.lightGrey )
- print( "Crap! Zombies from the brain-eating team #" .. source .. " rot on their way. Their last words were" )
- error( err, 0 )
- end
Add Comment
Please, Sign In to add comment