Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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