Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

139 рядки
3.9 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 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. love.filesystem.write("save", serialize(saveData))
  26. levelgeneral.goBack()
  27. end
  28. end
  29. camera:update(dt)
  30. if lvlbase ~= nil then
  31. lvlbase:update(dt)
  32. end
  33. --print(camera.x .. " " .. camera.y)
  34. for i, explosion in ipairs(explosions) do
  35. explosion:update(dt)
  36. if explosion.killed then
  37. table.remove(explosions, i)
  38. gameStatus = "setup"
  39. levelgeneral.reset()
  40. end
  41. end
  42. if gameStatus == "play" then
  43. camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width
  44. --print(camera.x .. firstShip.x)
  45. if shipIsHit then
  46. if #explosions == 0 then
  47. table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}))
  48. end
  49. end
  50. firstShip:update(dt)
  51. for i in ipairs(planets) do
  52. planets[i]:update(dt)
  53. end
  54. else
  55. camera:follow(VCAM.x, VCAM.y)
  56. end
  57. levelgeneral.GUIControl()
  58. end
  59. function levelgeneral.draw()
  60. love.graphics.setColor(1,1,1,1)
  61. camera:attach()
  62. if lvlbase ~= nil then
  63. lvlbase:draw()
  64. end
  65. for i in ipairs(planets) do
  66. planets[i]:draw(dt)
  67. end
  68. --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
  69. if shipIsHit then
  70. for i, explosion in ipairs(explosions) do
  71. explosion:render()
  72. --print("exploding")
  73. end
  74. end
  75. if reachedGoal then
  76. love.graphics.clear(0,0,0,1)
  77. love.graphics.setColor(30/255, 30/255, 30/255, 1)
  78. if frame < WINDOW_WIDTH then
  79. sounds["finish"]:play()
  80. love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - frame)
  81. end
  82. frame = frame + 20
  83. end
  84. firstShip:draw()
  85. camera:detach()
  86. camera:draw()
  87. if reachedGoal then
  88. love.graphics.setColor(1,1,1,1-1/frame)
  89. love.graphics.setFont(smallfont)
  90. love.graphics.printf("Press Enter to continue",0, 600, WINDOW_WIDTH, "center")
  91. end
  92. if gameStatus == "setup" and not reachedGoal then
  93. level.hint()
  94. elseif gameStatus == "play" then
  95. if not reachedGoal then
  96. love.graphics.printf("[W] Thrusters: ", 0, WINDOW_HEIGHT-100, 300, "center")
  97. local m = smallfont:getWidth("[W] Thrusters: ")
  98. local n = smallfont:getHeight("[W] Thrusters: ")
  99. love.graphics.setColor(1,0,0,1)
  100. love.graphics.rectangle("fill",0, WINDOW_HEIGHT-50, thrusterMax/2, n)
  101. love.graphics.setColor(0,1,0,1)
  102. love.graphics.rectangle("fill",0, WINDOW_HEIGHT-50, firstShip.fuel/2, n)
  103. love.graphics.setColor(1,1,1,1)
  104. guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
  105. love.keyboard.mouseisReleased = false
  106. end
  107. end
  108. end
  109. function levelgeneral.goBack()
  110. levelgeneral.reset()
  111. lvlbase = nil
  112. gameStatus = "setup"
  113. firstShip.path = {}
  114. levelLoaded = false
  115. for k in pairs(planets) do
  116. planets[k] = nil
  117. end
  118. gameState = "selectlv"
  119. end
  120. function levelgeneral.reset()
  121. level.reset()
  122. end
  123. function levelgeneral.GUIControl()
  124. level.GUIControl()
  125. end
  126. return levelgeneral