Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

53 rader
1.4 KiB

  1. selectlv = Class{}
  2. levels = {}
  3. table.insert(levels, menu:addButton("Level 1", function ()
  4. menuLoaded = false
  5. objReset()
  6. gameState = "level1"
  7. end ))
  8. table.insert(levels, menu:addButton("Level 2", function ()
  9. if saveData.levelsBeaten > 0 then
  10. menuLoaded = false
  11. objReset()
  12. gameState = "level2"
  13. end
  14. end ))
  15. table.insert(levels, menu:addButton("Go Back", function ()
  16. gameState = "menu"
  17. end ))
  18. local M = {}
  19. function selectlv.update(dt)
  20. if not menuLoaded then
  21. firstShip.x = -100
  22. firstShip.speed = 10
  23. firstShip.y = love.math.random(0, WINDOW_HEIGHT)
  24. menuLoaded = true
  25. table.insert(planets, planet(love.math.random(100, WINDOW_WIDTH-100), love.math.random(100, WINDOW_HEIGHT-100), 90000000, 0.3, love.graphics.newImage("entities/planet/planet.png")))
  26. end
  27. for i in ipairs(planets) do
  28. planets[i]:update(dt)
  29. end
  30. firstShip:update(dt)
  31. if shipIsHit then
  32. shipIsHit = false
  33. firstShip:reset()
  34. firstShip.x = -100
  35. firstShip.speed = 10
  36. firstShip.y = love.math.random(0, WINDOW_HEIGHT)
  37. print("ship is hit")
  38. end
  39. end
  40. function selectlv.draw(dt)
  41. firstShip:draw()
  42. for i in ipairs(planets) do
  43. planets[i]:draw(dt)
  44. end
  45. menu:butt(levels, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3, "beatenGreen")
  46. end
  47. return selectlv