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

levelgeneral.lua 4.0 KiB

3 年前
3 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. levelgeneral = Class{}
  2. local levelLoaded = false
  3. local M = {}
  4. local thrusterMax = 0
  5. local animationComplete = false
  6. local frame = 0
  7. asteroidImage = love.graphics.newImage("entities/planet/asteroid.png")
  8. function levelgeneral.update(dt)
  9. if not levelLoaded then
  10. level = require("levels/level" .. currentLevel)
  11. level.load()
  12. frame = 0
  13. animationComplete = false
  14. levelLoaded = true
  15. end
  16. if reachedGoal then
  17. if love.keyboard.isDown('return') then
  18. animationComplete = true
  19. end
  20. if saveData.levelsBeaten < currentLevel then
  21. saveData.levelsBeaten = currentLevel
  22. end
  23. --print("saveData.levelsBeaten is " .. saveData.levelsBeaten)
  24. if animationComplete then
  25. reachedGoal = false
  26. love.filesystem.write("save", serialize(saveData))
  27. levelgeneral.goBack()
  28. end
  29. end
  30. camera:update(dt)
  31. if lvlbase ~= nil then
  32. lvlbase:update(dt)
  33. end
  34. --print(camera.x .. " " .. camera.y)
  35. for i, explosion in ipairs(explosions) do
  36. explosion:update(dt)
  37. if explosion.killed then
  38. table.remove(explosions, i)
  39. if shipIsHit then
  40. gameStatus = "setup"
  41. levelgeneral.reset()
  42. end
  43. end
  44. end
  45. if gameStatus == "play" then
  46. camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width
  47. --print(camera.x .. firstShip.x)
  48. if shipIsHit then
  49. if #explosions == 0 then
  50. table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}))
  51. end
  52. end
  53. firstShip:update(dt)
  54. for i in ipairs(planets) do
  55. planets[i]:update(dt)
  56. end
  57. else
  58. camera:follow(VCAM.x, VCAM.y)
  59. end
  60. levelgeneral.GUIControl()
  61. end
  62. function levelgeneral.draw()
  63. love.graphics.setColor(1,1,1,1)
  64. camera:attach()
  65. if lvlbase ~= nil then
  66. lvlbase:draw()
  67. end
  68. for i in ipairs(planets) do
  69. planets[i]:draw(dt)
  70. end
  71. --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
  72. if shipIsHit then
  73. for i, explosion in ipairs(explosions) do
  74. explosion:render()
  75. --print("exploding")
  76. end
  77. end
  78. if reachedGoal then
  79. love.graphics.clear(0,0,0,1)
  80. love.graphics.setColor(30/255, 30/255, 30/255, 1)
  81. if frame < WINDOW_WIDTH then
  82. stopMusic()
  83. sounds["finish"]:play()
  84. love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - frame)
  85. end
  86. frame = frame + 20
  87. end
  88. firstShip:draw()
  89. camera:detach()
  90. camera:draw()
  91. if reachedGoal then
  92. love.graphics.setColor(1,1,1,1-1/frame)
  93. love.graphics.setFont(smallfont)
  94. love.graphics.printf("Press Enter to continue",0, 600, WINDOW_WIDTH, "center")
  95. end
  96. if gameStatus == "setup" and not reachedGoal then
  97. level.hint()
  98. elseif gameStatus == "play" then
  99. if not reachedGoal then
  100. love.graphics.printf("[W] Thrusters: ", 0, WINDOW_HEIGHT-100, 300, "center")
  101. local m = smallfont:getWidth("[W] Thrusters: ")
  102. local n = smallfont:getHeight("[W] Thrusters: ")
  103. love.graphics.setColor(1,0,0,1)
  104. love.graphics.rectangle("fill",0, WINDOW_HEIGHT-50, thrusterMax/2, n)
  105. love.graphics.setColor(0,1,0,1)
  106. love.graphics.rectangle("fill",0, WINDOW_HEIGHT-50, firstShip.fuel/2, n)
  107. love.graphics.setColor(1,1,1,1)
  108. guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
  109. love.keyboard.mouseisReleased = false
  110. end
  111. end
  112. end
  113. function levelgeneral.goBack()
  114. levelgeneral.reset()
  115. lvlbase = nil
  116. gameStatus = "setup"
  117. firstShip.path = {}
  118. levelLoaded = false
  119. for k in pairs(planets) do
  120. planets[k] = nil
  121. end
  122. gameState = "selectlv"
  123. end
  124. function levelgeneral.reset()
  125. level.reset()
  126. end
  127. function levelgeneral.GUIControl()
  128. level.GUIControl()
  129. end
  130. return levelgeneral