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 2.5 KiB

3 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. levelgeneral = Class{}
  2. local levelLoaded = false
  3. local M = {}
  4. function levelgeneral.update(dt)
  5. if not levelLoaded then
  6. level = require("levels/level" .. currentLevel)
  7. level.load()
  8. levelLoaded = true
  9. end
  10. if reachedGoal then
  11. if saveData.levelsBeaten < currentLevel then
  12. saveData.levelsBeaten = currentLevel
  13. end
  14. --print("saveData.levelsBeaten is " .. saveData.levelsBeaten)
  15. love.filesystem.write("save", serialize(saveData))
  16. levelgeneral.goBack()
  17. end
  18. camera:update(dt)
  19. if lvlbase ~= nil then
  20. lvlbase:update(dt)
  21. end
  22. --print(camera.x .. " " .. camera.y)
  23. for i, explosion in ipairs(explosions) do
  24. explosion:update(dt)
  25. if explosion.killed then
  26. table.remove(explosions, i)
  27. gameStatus = "setup"
  28. levelgeneral.reset()
  29. end
  30. end
  31. if gameStatus == "play" then
  32. camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width
  33. --print(camera.x .. firstShip.x)
  34. if shipIsHit then
  35. if #explosions == 0 then
  36. table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}))
  37. end
  38. end
  39. firstShip:update(dt)
  40. for i in ipairs(planets) do
  41. planets[i]:update(dt)
  42. end
  43. else
  44. camera:follow(VCAM.x, VCAM.y)
  45. end
  46. levelgeneral.GUIControl()
  47. end
  48. function levelgeneral.draw()
  49. love.graphics.setColor(1,1,1,1)
  50. camera:attach()
  51. firstShip:draw()
  52. if lvlbase ~= nil then
  53. lvlbase:draw()
  54. end
  55. for i in ipairs(planets) do
  56. planets[i]:draw(dt)
  57. end
  58. --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
  59. if shipIsHit then
  60. for i, explosion in ipairs(explosions) do
  61. explosion:render()
  62. --print("exploding")
  63. end
  64. end
  65. camera:detach()
  66. camera:draw()
  67. if gameStatus == "setup" then
  68. GUIDraw("left")
  69. elseif gameStatus == "play" then
  70. guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
  71. end
  72. end
  73. function levelgeneral.goBack()
  74. levelgeneral.reset()
  75. lvlbase = nil
  76. gameStatus = "setup"
  77. firstShip.path = {}
  78. levelLoaded = false
  79. for k in pairs(planets) do
  80. planets[k] = nil
  81. end
  82. gameState = "selectlv"
  83. end
  84. function levelgeneral.reset()
  85. level.reset()
  86. end
  87. function levelgeneral.GUIControl()
  88. level.GUIControl()
  89. end
  90. return levelgeneral