main.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. objList = {}
  2. drawList = {}
  3. bpm = 0
  4. timeDiff = 0
  5. active = 1
  6. curTime = love.timer.getTime()
  7. nextTime = 0
  8. function love.load(arg)
  9. love.window.setTitle("Metronomo")
  10. if arg then
  11. bpm = arg[1] or 80
  12. print(bpm .. " BPM started")
  13. end
  14. for i = 1, 4 do
  15. local dot = createDots(340 + (i * 30), 300)
  16. table.insert(objList, dot)
  17. table.insert(drawList, dot)
  18. end
  19. objList[1].isActive = true
  20. timeDiff = 60 / bpm
  21. print("timeDiff is defined to be " .. timeDiff)
  22. nextTime = curTime + timeDiff
  23. source = love.audio.newSource("05 Be Alright.mp3", "static")
  24. if arg[2] then
  25. source:setVolume(tonumber(0.22))
  26. end
  27. source:play()
  28. end
  29. function love.update(dt)
  30. if love.keyboard.isDown("escape") then love.quit() end
  31. if nextTime <= love.timer.getTime() then
  32. if active == 4 then
  33. active = 1
  34. objList[4].isActive = false
  35. objList[1].isActive = true
  36. else
  37. objList[active].isActive = false
  38. objList[active + 1].isActive = true
  39. active = active + 1
  40. end
  41. nextTime = love.timer.getTime() + timeDiff
  42. end
  43. end
  44. function love.draw()
  45. for i = 1, #drawList do
  46. if drawList[i].isActive then
  47. love.graphics.setColor(drawList[i].activeColor)
  48. love.graphics.circle("fill", drawList[i].x, drawList[i].y, 10)
  49. else
  50. love.graphics.setColor(drawList[i].unactiveColor)
  51. love.graphics.circle("fill", drawList[i].x, drawList[i].y, 10)
  52. end
  53. end
  54. end
  55. function love.mousepressed(x, y)
  56. print("x: " .. x .. "\ny: " .. y)
  57. end
  58. function createDots(x, y)
  59. local dot = {}
  60. dot.x = x or 0
  61. dot.y = y or 0
  62. dot.isActive = false
  63. dot.unactiveColor = {1, 1, 1, 1}
  64. dot.activeColor = {0.86, 0.46, 0.12, 1}
  65. return dot
  66. end