75 rader
2.6 KiB

  1. menu = Class{}
  2. menuMode = "main"
  3. local M = {}
  4. menuLoaded = false
  5. function menu.update(dt)
  6. if not menuLoaded then
  7. startTime = os.time(os.date("*t"))
  8. firstShip.x = -100
  9. menuLoaded = true
  10. planets = {}
  11. table.insert(planets, planet(love.math.random(100, WINDOW_WIDTH-100), love.math.random(100, WINDOW_HEIGHT-100), 90000000, 0.3, love.graphics.newImage("entities/planet/planet.png")))
  12. if (planets[1].y < WINDOW_HEIGHT/2) then
  13. firstShip.y = planets[1].y + love.math.random(300, 500)
  14. else
  15. firstShip.y = planets[1].y - love.math.random(300, 500)
  16. end
  17. end
  18. for i in ipairs(planets) do
  19. planets[i]:update(dt)
  20. end
  21. if animationSecsLeft > 0 then
  22. animationSecsLeft = animationSecsLeft - dt
  23. end
  24. firstShip:update(dt)
  25. if shipIsHit then
  26. shipIsHit = false
  27. firstShip:reset()
  28. firstShip.x = -100
  29. if (planets[1].y < WINDOW_HEIGHT/2) then
  30. firstShip.y = love.math.random(WINDOW_HEIGHT/2, WINDOW_HEIGHT)
  31. else
  32. firstShip.y = love.math.random(0, WINDOW_HEIGHT/2)
  33. end
  34. --print("ship is hit")
  35. end
  36. if menuMode == "settings" then
  37. local mx, my = love.mouse.getPosition()
  38. local vmx, vmy = camera:getMousePosition()
  39. local vmx = vmx * DIFFERENCE_X
  40. local vmy = vmy * DIFFERENCE_Y
  41. local mx = mx * DIFFERENCE_X
  42. local my = my * DIFFERENCE_Y
  43. volumeSlider:update(mx, my)
  44. end
  45. end
  46. function menu.draw(dt)
  47. firstShip:draw()
  48. for i in ipairs(planets) do
  49. planets[i]:draw(dt)
  50. end
  51. if animationSecsLeft > 0 then
  52. love.graphics.setColor(1,1,1,1-1/(animationSecsLeft+0.000001))
  53. love.graphics.draw(logo, 0,0)
  54. else
  55. love.graphics.setFont(titlefont)
  56. love.graphics.printf("NuclearGravity", 0, 20, WINDOW_WIDTH, "center")
  57. if menuMode == "main" then
  58. menu:butt(buttons, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3)
  59. elseif menuMode == "settings" then
  60. menu:butt(mainsettings, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3)
  61. love.graphics.setColor(254, 67, 101)
  62. love.graphics.setFont(tinyfont)
  63. love.graphics.printf("Sound volume:", 0, WINDOW_HEIGHT/2-140, WINDOW_WIDTH, "center")
  64. -- draw slider, set color and line style before calling
  65. volumeSlider:draw()
  66. else
  67. print("[EE]No menu found! " .. menu.mode)
  68. end
  69. love.keyboard.mouseisReleased = false
  70. end
  71. end
  72. return menu