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.

practice.lua 2.9 KiB

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