選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

130 行
3.2 KiB

  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. if shipsleft == 0 then
  22. selectedItem = "none"
  23. gameStatus = "play"
  24. end
  25. end
  26. ))
  27. table.insert(guibutts, menu:addButton("To menu", function ()
  28. practice.goBack()
  29. end
  30. ))
  31. levelLoaded = true
  32. end
  33. camera:update(dt)
  34. --print(camera.x .. " " .. camera.y)
  35. for i, explosion in ipairs(explosions) do
  36. explosion:update(dt)
  37. if explosion.killed then
  38. table.remove(explosions, i)
  39. gameStatus = "setup"
  40. practice.reset()
  41. end
  42. end
  43. if gameStatus == "play" then
  44. camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width
  45. --print(camera.x .. firstShip.x)
  46. if shipIsHit then
  47. if #explosions == 0 then
  48. table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}))
  49. end
  50. end
  51. firstShip:update(dt)
  52. for i in ipairs(planets) do
  53. planets[i]:update(dt)
  54. end
  55. else
  56. camera:follow(VCAM.x, VCAM.y)
  57. end
  58. practice.GUIControl()
  59. end
  60. function practice.draw()
  61. camera:attach()
  62. firstShip:draw()
  63. for i in ipairs(planets) do
  64. planets[i]:draw(dt)
  65. end
  66. --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
  67. if shipIsHit then
  68. for i, explosion in ipairs(explosions) do
  69. explosion:render()
  70. --print("exploding")
  71. end
  72. end
  73. camera:detach()
  74. camera:draw()
  75. if gameStatus == "setup" then
  76. GUIDraw("anywhere")
  77. elseif gameStatus == "play" then
  78. guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
  79. love.keyboard.mouseisReleased = false
  80. end
  81. end
  82. function practice.goBack()
  83. practice.reset()
  84. gameStatus = "setup"
  85. levelLoaded = false
  86. gameState = "menu"
  87. end
  88. function practice.reset()
  89. firstShip:reset()
  90. for k in pairs(planets) do
  91. planets[k] = nil
  92. end
  93. shipsleft = 1
  94. shipIsHit = false
  95. planetsleft = 10
  96. end
  97. function practice.GUIControl()
  98. if (love.keyboard.isDown('w')) then
  99. VCAM.y = VCAM.y - 10
  100. end
  101. if (love.keyboard.isDown('a')) then
  102. VCAM.x = VCAM.x - 10
  103. end
  104. if (love.keyboard.isDown('s')) then
  105. VCAM.y = VCAM.y + 10
  106. end
  107. if (love.keyboard.isDown('d')) then
  108. VCAM.x = VCAM.x + 10
  109. end
  110. end
  111. function practice.hint()
  112. love.graphics.setFont(tinyfont)
  113. love.graphics.print("↑[W]",50,10)
  114. love.graphics.print("↓[S]",50,100)
  115. love.graphics.print("←[A]",10,50)
  116. love.graphics.print("→[D]",100,50)
  117. end
  118. return practice