Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

167 linhas
4.7 KiB

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