Advertisement
ds84182

Listen to some damn source.

Jul 25th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. local src = {}
  2. src.lang = "java"
  3. src.mainclass = "Start"
  4. local soundQueue = {}
  5. local alreadImport = {}
  6.  
  7. function readImportsFromFile(data)
  8.     if src.lang == "java" then
  9.         local ilist = {}
  10.         for import in data:gmatch("import ([%d%w%._]+);") do
  11.             ilist[#ilist+1] = import:gsub("%.","/")..".java"
  12.         end
  13.         return ilist
  14.     end
  15. end
  16.  
  17. function readFile(file)
  18.     if not love.filesystem.exists(file) then return end
  19.     if alreadImport[file] then return end
  20.     local data = love.filesystem.read(file)
  21.     local imports = readImportsFromFile(data)
  22.     for i, v in pairs(imports) do
  23.         table.insert(fileQueue,1,"src/"..v)
  24.     end
  25.     for i=1,#data do
  26.         table.insert(soundQueue,data:byte(i)/(255/2))
  27.     end
  28.     alreadImport[file] = true
  29. end
  30.  
  31. function love.load()
  32.     SQ50 = love.sound.newSoundData( 16, 880*16, 16 )
  33.     for n = 0, 15 do SQ50:setSample( n , n%2 == 1 and 1 or -1 ) end
  34.     squ = love.audio.newSource("harp.ogg","static")
  35.     dta = 1/10
  36.     --squ:setLooping(true)
  37.     fileQueue = {"src/Start.java"}
  38. end
  39.  
  40. function love.update(dt)
  41.     if fileQueue[1] then
  42.         local f = fileQueue[1]
  43.         table.remove(fileQueue,1)
  44.         readFile(f)
  45.     end
  46.     if soundQueue[1] then
  47.         if dta-dt <= 0 then
  48.             squ:stop()
  49.             squ:setPitch(soundQueue[1])
  50.             squ:play()
  51.             table.remove(soundQueue,1)
  52.             dta = 1/10
  53.         else
  54.             dta = dta-dt
  55.         end
  56.     end
  57. end
  58.  
  59. function love.draw()
  60.     love.graphics.print((fileQueue[1] or "")..(soundQueue[1] or ""),0,0)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement