Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

levelgeneral.lua 4.6 KiB

3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 and explosion.type == 0 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 and not firstShip.exploded then
  49. table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}, 0))
  50. firstShip.exploded = true
  51. end
  52. firstShip:update(dt)
  53. for i in ipairs(planets) do
  54. planets[i]:update(dt)
  55. end
  56. if currentLevel > 5 then
  57. level.bonusUpdate(dt)
  58. end
  59. else
  60. camera:follow(VCAM.x, VCAM.y)
  61. end
  62. levelgeneral.GUIControl()
  63. end
  64. function levelgeneral.draw()
  65. love.graphics.setColor(1,1,1,1)
  66. camera:attach()
  67. if lvlbase ~= nil then
  68. lvlbase:draw()
  69. end
  70. for i in ipairs(planets) do
  71. planets[i]:draw(dt)
  72. end
  73. --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
  74. for i in ipairs(cannons) do
  75. cannons[i]:draw(dt)
  76. end
  77. for i in ipairs(projectiles) do
  78. projectiles[i]:draw(dt)
  79. end
  80. if reachedGoal then
  81. if frame <= WINDOW_WIDTH*1.1 then
  82. stopMusic()
  83. sounds["finish"]:play()
  84. love.graphics.setColor(1,1,1,1)
  85. love.graphics.circle("fill", firstShip.x, firstShip.y, frame)
  86. end
  87. if frame > WINDOW_WIDTH*1.1 then
  88. love.graphics.clear(0,0,0,1)
  89. love.graphics.setColor(1, 1, 1, 1)
  90. if frame-WINDOW_WIDTH*1.1 < WINDOW_WIDTH then
  91. love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - (frame - WINDOW_WIDTH*1.1))
  92. end
  93. end
  94. frame = frame + 40
  95. end
  96. firstShip:draw()
  97. for i, explosion in ipairs(explosions) do
  98. explosion:render()
  99. --print("exploding")
  100. end
  101. camera:detach()
  102. camera:draw()
  103. if reachedGoal then
  104. love.graphics.setColor(1,1,1,1-1/frame)
  105. love.graphics.setFont(smallfont)
  106. love.graphics.printf("Press Enter to continue",0, 600, WINDOW_WIDTH, "center")
  107. end
  108. if gameStatus == "setup" and not reachedGoal then
  109. level.hint()
  110. elseif gameStatus == "play" then
  111. if not reachedGoal then
  112. love.graphics.printf("[W] Thrusters: ", 0, WINDOW_HEIGHT-100, 300, "center")
  113. local m = smallfont:getWidth("[W] Thrusters: ")
  114. local n = smallfont:getHeight("[W] Thrusters: ")
  115. love.graphics.setColor(1,0,0,1)
  116. love.graphics.rectangle("fill",0, WINDOW_HEIGHT-50, thrusterMax/2, n)
  117. love.graphics.setColor(0,1,0,1)
  118. love.graphics.rectangle("fill",0, WINDOW_HEIGHT-50, firstShip.fuel/2, n)
  119. love.graphics.setColor(1,1,1,1)
  120. guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
  121. love.keyboard.mouseisReleased = false
  122. end
  123. end
  124. end
  125. function levelgeneral.goBack()
  126. levelgeneral.reset()
  127. lvlbase = nil
  128. gameStatus = "setup"
  129. cameraControl = false
  130. firstShip.path = {}
  131. cannons = {}
  132. levelLoaded = false
  133. for k in pairs(planets) do
  134. planets[k] = nil
  135. end
  136. gameState = "selectlv"
  137. end
  138. function levelgeneral.reset()
  139. level.reset()
  140. end
  141. function levelgeneral.GUIControl()
  142. level.GUIControl()
  143. end
  144. return levelgeneral