Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

135 righe
3.6 KiB

  1. level1 = Class{}
  2. local levelLoaded = false
  3. local M = {}
  4. function level1.update(dt)
  5. if not levelLoaded then
  6. shipsleft = 1
  7. local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
  8. planetsleft = 3
  9. gameStatus = "setup"
  10. playbutts = {}
  11. guibutts = {}
  12. VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2
  13. explosions = {}
  14. shipIsHit = false
  15. guimenu = mainMenu()
  16. reachedGoal = false
  17. lvlbase = base(900, 200)
  18. levelLoaded = true
  19. table.insert(playbutts, menu:addButton("Return to setup", function()
  20. gameStatus = "setup"
  21. level1.reset()
  22. end ))
  23. table.insert(guibutts, menu:addButton("Release brake!", function ()
  24. selectedItem = "none"
  25. gameStatus = "play"
  26. end
  27. ))
  28. table.insert(guibutts, menu:addButton("To menu", function ()
  29. level1.goBack()
  30. end))
  31. table.insert(planets, planet(700, 200, 50, 0.3, planetImage))
  32. end
  33. if reachedGoal then
  34. if saveData.levelsBeaten < 1 then
  35. saveData.levelsBeaten = 1
  36. end
  37. print("saveData.levelsBeaten is " .. saveData.levelsBeaten)
  38. love.filesystem.write("save", serialize(saveData))
  39. level1.goBack()
  40. end
  41. camera:update(dt)
  42. lvlbase:update(dt)
  43. --print(camera.x .. " " .. camera.y)
  44. for i, explosion in ipairs(explosions) do
  45. explosion:update(dt)
  46. if explosion.killed then
  47. table.remove(explosions, i)
  48. gameStatus = "setup"
  49. level1.reset()
  50. end
  51. end
  52. if gameStatus == "play" then
  53. camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width
  54. --print(camera.x .. firstShip.x)
  55. if shipIsHit then
  56. if #explosions == 0 then
  57. table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}))
  58. end
  59. end
  60. firstShip:update(dt)
  61. for i in ipairs(planets) do
  62. planets[i]:update(dt)
  63. end
  64. else
  65. camera:follow(VCAM.x, VCAM.y)
  66. end
  67. level1.GUIControl()
  68. end
  69. function level1.draw()
  70. love.graphics.setColor(1,1,1,1)
  71. camera:attach()
  72. firstShip:draw()
  73. lvlbase:draw()
  74. for i in ipairs(planets) do
  75. planets[i]:draw(dt)
  76. end
  77. --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
  78. if shipIsHit then
  79. for i, explosion in ipairs(explosions) do
  80. explosion:render()
  81. --print("exploding")
  82. end
  83. end
  84. camera:detach()
  85. camera:draw()
  86. if gameStatus == "setup" then
  87. GUIDraw("left")
  88. elseif gameStatus == "play" then
  89. guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
  90. end
  91. end
  92. function level1.goBack()
  93. level1.reset()
  94. gameStatus = "setup"
  95. firstShip.path = {}
  96. levelLoaded = false
  97. for k in pairs(planets) do
  98. planets[k] = nil
  99. end
  100. gameState = "selectlv"
  101. end
  102. function level1.reset()
  103. firstShip:reset()
  104. for k in pairs(planets) do
  105. planets[k] = nil
  106. end
  107. local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
  108. table.insert(planets, planet(700, 200, 50, 0.3, planetImage))
  109. shipsleft = 1
  110. shipIsHit = false
  111. planetsleft = 3
  112. end
  113. function level1.GUIControl()
  114. if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then
  115. VCAM.x = VCAM.x - 10
  116. end
  117. if (love.keyboard.isDown('d')) then
  118. VCAM.x = VCAM.x + 10
  119. end
  120. end
  121. return level1