您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

selectlv.lua 2.9 KiB

3 年前
3 年前
3 年前
3 年前
3 年前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. selectlv = Class{}
  2. levels = {}
  3. table.insert(levels, menu:addButton("Level 1", function ()
  4. menuLoaded = false
  5. objReset()
  6. gameState = "levelgeneral"
  7. currentLevel = 1
  8. end ))
  9. table.insert(levels, menu:addButton("Level 2", function ()
  10. if saveData.levelsBeaten > 0 then
  11. menuLoaded = false
  12. objReset()
  13. gameState = "levelgeneral"
  14. currentLevel = 2
  15. end
  16. end ))
  17. table.insert(levels, menu:addButton("Level 3", function ()
  18. if saveData.levelsBeaten > 1 then
  19. menuLoaded = false
  20. objReset()
  21. gameState = "levelgeneral"
  22. currentLevel = 3
  23. end
  24. end ))
  25. table.insert(levels, menu:addButton("Level 4", function ()
  26. if saveData.levelsBeaten > 2 then
  27. menuLoaded = false
  28. objReset()
  29. gameState = "levelgeneral"
  30. currentLevel = 4
  31. end
  32. end ))
  33. table.insert(levels, menu:addButton("Level 5", function ()
  34. if saveData.levelsBeaten > 3 then
  35. menuLoaded = false
  36. objReset()
  37. gameState = "levelgeneral"
  38. currentLevel = 5
  39. end
  40. end ))
  41. table.insert(levels, menu:addButton("Level 6", function ()
  42. if saveData.levelsBeaten > 4 then
  43. menuLoaded = false
  44. objReset()
  45. gameState = "levelgeneral"
  46. currentLevel = 6
  47. end
  48. end ))
  49. table.insert(levels, menu:addButton("Go Back", function ()
  50. gameState = "menu"
  51. end ))
  52. local M = {}
  53. function selectlv.update(dt)
  54. if not menuLoaded then
  55. firstShip.x = -100
  56. menuLoaded = true
  57. 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")))
  58. if (planets[1].y < WINDOW_HEIGHT/2) then
  59. firstShip.y = love.math.random(WINDOW_HEIGHT/2, WINDOW_HEIGHT)
  60. else
  61. firstShip.y = love.math.random(0, WINDOW_HEIGHT/2)
  62. end
  63. end
  64. for i in ipairs(planets) do
  65. planets[i]:update(dt)
  66. end
  67. firstShip:update(dt)
  68. if shipIsHit then
  69. shipIsHit = false
  70. firstShip:reset()
  71. firstShip.x = -100
  72. if (planets[1].y < WINDOW_HEIGHT/2) then
  73. firstShip.y = love.math.random(WINDOW_HEIGHT/2, WINDOW_HEIGHT)
  74. else
  75. firstShip.y = love.math.random(0, WINDOW_HEIGHT/2)
  76. end
  77. --print("ship is hit")
  78. end
  79. end
  80. function selectlv.draw(dt)
  81. firstShip:draw()
  82. for i in ipairs(planets) do
  83. planets[i]:draw(dt)
  84. end
  85. menu:butt(levels, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3, "beatenGreen")
  86. love.keyboard.mouseisReleased = false
  87. end
  88. return selectlv