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.

levelgeneral.lua 4.3 KiB

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