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.

108 rivejä
3.0 KiB

  1. level6 = Class{}
  2. local levelLoaded = false
  3. local M = {}
  4. function level6.load()
  5. shipsleft = 1
  6. local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
  7. planetsleft = 3
  8. gameStatus = "setup"
  9. playbutts = {}
  10. thrusterMax = 0
  11. firstShip.fuel = 0
  12. guibutts = {}
  13. VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2
  14. explosions = {}
  15. shipIsHit = false
  16. guimenu = mainMenu()
  17. reachedGoal = false
  18. lvlbase = base(1600, 400)
  19. levelLoaded = true
  20. attackTimer = 5
  21. table.insert(playbutts, menu:addButton("Return to setup", function()
  22. gameStatus = "setup"
  23. levelgeneral.reset()
  24. end ))
  25. table.insert(guibutts, menu:addButton("Release brake!", function ()
  26. if shipsleft == 0 then
  27. selectedItem = "none"
  28. gameStatus = "play"
  29. end
  30. end
  31. ))
  32. table.insert(guibutts, menu:addButton("To menu", function ()
  33. levelgeneral.goBack()
  34. end))
  35. table.insert(cannons, enemy(10000, 400, false, 3))
  36. table.insert(planets, planet(1600, 250, 50, 0.3, asteroidImage, "nodelete"))
  37. table.insert(planets, planet(1600, 550, 50, 0.3, asteroidImage, "nodelete"))
  38. end
  39. function level6.hint()
  40. GUIDraw("left")
  41. love.graphics.setFont(tinyfont)
  42. if (VCAM.x > WINDOW_WIDTH/2) then
  43. if love.keyboard.isDown('a') then
  44. love.graphics.setColor(1,0,0,1)
  45. end
  46. love.graphics.print("←[A]",10,50)
  47. love.graphics.setColor(1,1,1,1)
  48. end
  49. if (VCAM.x < WINDOW_WIDTH*2) then
  50. if love.keyboard.isDown('d') then
  51. love.graphics.setColor(1,0,0,1)
  52. end
  53. love.graphics.print("[D]→",100,50)
  54. love.graphics.setColor(1,1,1,1)
  55. end
  56. end
  57. function level6.reset()
  58. firstShip:reset()
  59. local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
  60. shipsleft = 1
  61. projectiles = {}
  62. cannons[1].x = 100000
  63. cannons[1].destX = 100000
  64. firstShip.fuel = 0
  65. shipIsHit = false
  66. attackTimer = 5
  67. cannons[1].appeared = false
  68. end
  69. function level6.bonusUpdate(dt)
  70. if not reachedGoal then
  71. if attackTimer >= 0 then
  72. attackTimer = attackTimer - dt
  73. else
  74. cannons[1].destX = 1200
  75. cannons[1]:update(dt)
  76. if not cannons[1].appeared then
  77. sounds["appear"]:stop()
  78. sounds["appear"]:play()
  79. if #explosions == 0 then
  80. table.insert(explosions, explosion(1400, 400, 100, {1,40/255,40/255,1}))
  81. explosions[1].type = 1
  82. end
  83. cannons[1].appeared = true
  84. end
  85. end
  86. for i in ipairs(projectiles) do
  87. projectiles[i]:update(dt)
  88. end
  89. cannons[1].x = cannons[1].x - (math.abs(cannons[1].destX-cannons[1].x)/5)
  90. end
  91. end
  92. function level6.GUIControl()
  93. if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then
  94. VCAM.x = VCAM.x - 10
  95. end
  96. if (love.keyboard.isDown('d')) then
  97. VCAM.x = VCAM.x + 10
  98. end
  99. end
  100. function level6.goBack()
  101. levelgeneral.goBack()
  102. end
  103. return level6