Advertisement
cc-editor

aufzug-stockwerk

Apr 8th, 2022 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. function play(name)
  2.     local dfpwm = require("cc.audio.dfpwm")
  3.     local speaker = peripheral.find("speaker")
  4.  
  5.     local decoder = dfpwm.make_decoder()
  6.     for chunk in io.lines("sound/"..name..".dfpwm", 16 * 1024) do
  7.         local buffer = decoder(chunk)
  8.  
  9.         while not speaker.playAudio(buffer, 100) do
  10.             os.pullEvent("speaker_audio_empty")
  11.         end
  12.     end
  13. end
  14.  
  15. function display()
  16.     local disp = peripheral.find("monitor")
  17.     disp.setTextScale(0.5)
  18.     disp.setBackgroundColor(colors.lightGray)
  19.     disp.clear()
  20.    
  21.     local termPc = term.redirect(disp)
  22.     term.redirect(termPc)
  23.     while true do
  24.         local id, mode = os.pullEvent("display")
  25.         term.redirect(disp)
  26.         count = 1
  27.         while displayActive do
  28.             paintutils.drawImage(paintutils.loadImage("bilder/plane.nfp"),1,1)
  29.             if mode == "hoch" then
  30.                 paintutils.drawImage(paintutils.loadImage("bilder/hoch"..count..".nfp"),1,1)
  31.             elseif mode == "runter" then
  32.                 paintutils.drawImage(paintutils.loadImage("bilder/runter"..count..".nfp"),1,1)
  33.             end
  34.             paintutils.drawImage(paintutils.loadImage("bilder/ebene"..currentLevel..".nfp"),1,1)
  35.             count = (count % 5) + 1
  36.             sleep(0.5)
  37.         end
  38.        
  39.         paintutils.drawImage(paintutils.loadImage("bilder/plane.nfp"),1,1)
  40.         if mode == "ooo" or mode == "techniker" then           
  41.             paintutils.drawImage(paintutils.loadImage("bilder/ooo.nfp"),1,1)
  42.         else
  43.             paintutils.drawImage(paintutils.loadImage("bilder/ebene"..currentLevel..".nfp"),1,1)
  44.         end
  45.         term.redirect(termPc)
  46.     end
  47. end
  48.  
  49. function control()
  50.     peripheral.find("modem", rednet.open)
  51.     while true do
  52.         local id, number, typ = rednet.receive()
  53.        
  54.         if typ == "ankunft" then
  55.             currentLevel = number
  56.             displayActive = false
  57.             play(number)
  58.         elseif typ == "abfahrt" then
  59.             play("tuer")
  60.         elseif typ == "hoch" or typ == "runter" then
  61.             currentLevel = number
  62.             displayActive = true
  63.             print("Aufzug faehrt los")
  64.             os.queueEvent("display", typ)
  65.         elseif typ == "stop" then
  66.             currentLevel = number
  67.             displayActive = false
  68.         elseif typ == "status" then
  69.             currentLevel = number
  70.         elseif typ == "startup" then
  71.             displayActive = false
  72.             currentLevel = number
  73.             print("Aufzug gestartet")
  74.             os.queueEvent("display", typ)
  75.         elseif typ == "ooo" then
  76.             displayActive = false
  77.             os.queueEvent("display", typ)
  78.             play("ooo")
  79.         elseif typ == "techniker" then
  80.             displayActive = false
  81.             os.queueEvent("display", typ)
  82.         end
  83.     end
  84. end
  85.  
  86. term.clear()
  87. term.setCursorPos(1,1)
  88. print("Warte auf Anweisungen des Zentralrechners")
  89. print("Lokale ID: "..os.getComputerID())
  90.  
  91. displayActive = false
  92. currentLevel = -1
  93.  
  94. parallel.waitForAny(control, display)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement