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.

levelgeneral.lua 4.8 KiB

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