SteamPunkCherub

Angel Player Computercraft

Jul 26th, 2013 (edited)
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Angel Player by SteamPunkCherub
  2.  
  3. -- Variable Declare
  4. input = ""
  5. dtime = 0
  6. loop = false
  7. dtimer = 0
  8. playing = false
  9. ddisk = "bottom"
  10. diskname = disk.getAudioTitle(ddisk)
  11. event = ""
  12.  
  13. -- Function Creation
  14. local function getInput()
  15.   event, key = os.pullEvent()
  16.   if event == "char" then
  17.     key = string.upper(key)
  18.     if key == "P" or key == "S" then
  19.       input = key
  20.     end
  21.   elseif event == "timer" and key == dtimer then
  22.     loop = true
  23.     key = 0
  24.   end
  25. end
  26.  
  27. local function display()
  28.   term.clear()
  29.   term.setCursorPos(1,1)
  30.   print("Welcome to Angel Player!")
  31.   print("Insert a Music disk into the tray below")
  32.   print("and hit P to play")
  33.   print("hit S to stop.")
  34.   print("")
  35.   if disk.hasAudio(ddisk) and playing then
  36.     print("Now Playing: ", diskname)
  37.   elseif disk.hasAudio(ddisk) and playing == false then
  38.     print(diskname, " is currently paused.")
  39.   else
  40.     print("No music disk currently detected.")
  41.   end
  42. end
  43.  
  44. local function getDiskInfo()
  45.   diskname = disk.getAudioTitle(ddisk)
  46.   if diskname == "C418 - 13" then
  47.     dtime = 178
  48.   elseif diskname == "C418 - cat" then
  49.     dtime = 185
  50.   elseif diskname == "C418 - blocks" then
  51.     dtime = 345
  52.   elseif diskname == "C418 - chirp" then
  53.     dtime = 185
  54.   elseif diskname == "C418 - far" then
  55.     dtime = 174
  56.   elseif diskname == "C418 - mall" then
  57.     dtime = 197
  58.   elseif diskname == "C418 - mellohi" then
  59.     dtime = 96
  60.   elseif diskname == "C418 - stral" then
  61.     dtime = 150
  62.   elseif diskname == "C418 - strad" then
  63.     dtime = 188
  64.   elseif diskname == "C418 - ward" then
  65.     dtime = 251
  66.   elseif diskname == "C418 - 11" then
  67.     dtime = 71
  68.   elseif diskname == "C418 - wait" then
  69.     dtime = 236
  70.   elseif diskname == "portalgun:radioloop" then
  71.     dtime = 21
  72.   elseif diskname == "portalgun:wantyougone" then
  73.     dtime = 141
  74.   elseif diskname == "portalgun:stillalive" then
  75.     dtime = 176
  76.   elseif diskname == "Tim Rurkowski - wanderer" then
  77.     dtime = 289
  78.   elseif diskname == "???" then
  79.     dtime = 183
  80.   elseif diskname == "Lena Raine - Pigstep" then
  81.     dtime = 148
  82.   end
  83. end
  84.  
  85. --Main Loop
  86. while true do
  87.   getDiskInfo()
  88.   display()
  89.   getInput()
  90.   if disk.hasAudio(ddisk) then
  91.     if input == "P" or loop then
  92.       dtimer = os.startTimer(dtime)
  93.       playing = true
  94.       disk.playAudio(ddisk)
  95.       loop = false
  96.       input = ""
  97.     elseif input == "S"then
  98.       dtimer = 0
  99.       dtime = 0
  100.       playing = false
  101.       disk.stopAudio(ddisk)
  102.       input = ""
  103.     end
  104.   end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment