Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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