You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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