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.

level6.lua 3.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. for i in ipairs(planets) do
  60. if not planets[i].deletable then
  61. table.remove(planets, i)
  62. end
  63. end
  64. table.insert(planets, planet(1600, 250, 50, 0.3, asteroidImage, "nodelete"))
  65. table.insert(planets, planet(1600, 550, 50, 0.3, asteroidImage, "nodelete"))
  66. local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
  67. shipsleft = 1
  68. projectiles = {}
  69. cannons[1].x = 100000
  70. cannons[1].destX = 100000
  71. firstShip.fuel = 0
  72. shipIsHit = false
  73. attackTimer = 5
  74. cannons[1].appeared = false
  75. end
  76. function level6.bonusUpdate(dt)
  77. if not reachedGoal then
  78. if attackTimer >= 0 then
  79. attackTimer = attackTimer - dt
  80. else
  81. cannons[1].destX = 1200
  82. cannons[1]:update(dt)
  83. if not cannons[1].appeared then
  84. sounds["appear"]:stop()
  85. sounds["appear"]:play()
  86. if #explosions == 0 then
  87. table.insert(explosions, explosion(1400, 400, 100, {1,1,1,1}))
  88. explosions[1].type = 1
  89. end
  90. camera:shake(8, 1, 60, 'X')
  91. cannons[1].appeared = true
  92. end
  93. end
  94. for i in ipairs(projectiles) do
  95. projectiles[i]:update(dt)
  96. end
  97. for i in ipairs(projectiles) do
  98. if projectiles[i].killed then
  99. table.remove(projectiles, i)
  100. --print("killing")
  101. end
  102. end
  103. cannons[1].x = cannons[1].x - (math.abs(cannons[1].destX-cannons[1].x)/5)
  104. end
  105. end
  106. function level6.GUIControl()
  107. if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then
  108. VCAM.x = VCAM.x - 10
  109. end
  110. if (love.keyboard.isDown('d')) then
  111. VCAM.x = VCAM.x + 10
  112. end
  113. end
  114. function level6.goBack()
  115. levelgeneral.goBack()
  116. end
  117. return level6