Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

practice.lua 5.5 KiB

pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. practice = Class{}
  2. local levelLoaded = false
  3. local M = {}
  4. local currenctScore = 0
  5. function practice.update(dt)
  6. if not levelLoaded then
  7. shipsleft = 1
  8. planetsleft = 10
  9. cannonsleft = 10
  10. gameStatus = "setup"
  11. playbutts = {}
  12. guibutts = {}
  13. XCAM = 0
  14. currentScore = 0
  15. cameraControl = true
  16. thrusterMax = 0
  17. YCAM = 0
  18. firstShip.fuel = 0
  19. explosions = {}
  20. shipIsHit = false
  21. guimenu = mainMenu()
  22. table.insert(playbutts, menu:addButton("Return to setup", function()
  23. gameStatus = "setup"
  24. practice.reset()
  25. end ))
  26. table.insert(guibutts, menu:addButton("Release brake!", function ()
  27. if shipsleft == 0 then
  28. selectedItem = "none"
  29. gameStatus = "play"
  30. end
  31. end
  32. ))
  33. table.insert(guibutts, menu:addButton("To menu", function ()
  34. practice.goBack()
  35. end
  36. ))
  37. levelLoaded = true
  38. end
  39. camera:update(dt)
  40. --print(camera.x .. " " .. camera.y)
  41. for i, explosion in ipairs(explosions) do
  42. explosion:update(dt)
  43. -- print("1 update done")
  44. if explosion.killed then
  45. table.remove(explosions, i)
  46. if shipIsHit then
  47. gameStatus = "setup"
  48. practice.reset()
  49. end
  50. end
  51. end
  52. if gameStatus == "play" then
  53. camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width
  54. --print(camera.x .. firstShip.x)
  55. if shipIsHit and not firstShip.exploded then
  56. table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}))
  57. explosions[#explosions].type = 0
  58. firstShip.exploded = true
  59. end
  60. firstShip:update(dt)
  61. for i in ipairs(planets) do
  62. planets[i]:update(dt)
  63. if math.sqrt((firstShip.x - planets[i].x)^2 + (firstShip.y - planets[i].y)^2) > planets[i].w/3 then
  64. currentScore = currentScore + math.sqrt(planets[i].attractionX^2 + planets[i].attractionY^2)*100
  65. print(math.sqrt(planets[i].attractionX^2 + planets[i].attractionY^2))
  66. end
  67. end
  68. for i in ipairs(cannons) do
  69. cannons[i]:update(dt)
  70. end
  71. for i in ipairs(projectiles) do
  72. projectiles[i]:update(dt)
  73. end
  74. for i in ipairs(projectiles) do
  75. if projectiles[i].killed then
  76. table.remove(projectiles, i)
  77. --print("killing")
  78. end
  79. end
  80. else
  81. camera:follow(VCAM.x, VCAM.y)
  82. end
  83. practice.GUIControl()
  84. end
  85. function practice.draw()
  86. camera:attach()
  87. firstShip:draw()
  88. for i in ipairs(planets) do
  89. planets[i]:draw(dt)
  90. end
  91. for i in ipairs(cannons) do
  92. cannons[i]:draw(dt)
  93. end
  94. for i in ipairs(projectiles) do
  95. projectiles[i]:draw(dt)
  96. end
  97. --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
  98. for i, explosion in ipairs(explosions) do
  99. if shipIsHit then
  100. explosion:render()
  101. else
  102. explosion:render("special")
  103. end
  104. --print("exploding")
  105. end
  106. camera:detach()
  107. camera:draw()
  108. if gameStatus == "setup" then
  109. GUIDraw("anywhere")
  110. love.graphics.setFont(tinyfont)
  111. local textW = tinyfont:getWidth("Top score: " .. math.floor(saveData.score/100))
  112. love.graphics.print("Top score: " .. math.floor(saveData.score/100), WINDOW_WIDTH/2-textW/2, 10)
  113. practice.hint()
  114. elseif gameStatus == "play" then
  115. local textW = tinyfont:getWidth("Score: " .. math.floor(currentScore/100))
  116. love.graphics.setFont(tinyfont)
  117. love.graphics.print("Score: " .. math.floor(currentScore/100), WINDOW_WIDTH/2-textW/2, 10)
  118. guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3)
  119. love.keyboard.mouseisReleased = false
  120. end
  121. end
  122. function practice.goBack()
  123. practice.reset()
  124. cameraControl = false
  125. gameStatus = "setup"
  126. levelLoaded = false
  127. gameState = "menu"
  128. cannons = {}
  129. end
  130. function practice.reset()
  131. firstShip:reset()
  132. camera.scale = 1
  133. projectiles = {}
  134. shipsleft = 1
  135. if currentScore > saveData.score then
  136. saveData.score = currentScore
  137. love.filesystem.write("save", serialize(saveData))
  138. end
  139. currentScore = 0
  140. shipIsHit = false
  141. firstShip.fuel = 99999
  142. end
  143. function practice.GUIControl()
  144. if (love.keyboard.isDown('w')) then
  145. VCAM.y = VCAM.y - 10
  146. end
  147. if (love.keyboard.isDown('a')) then
  148. VCAM.x = VCAM.x - 10
  149. end
  150. if (love.keyboard.isDown('s')) then
  151. VCAM.y = VCAM.y + 10
  152. end
  153. if (love.keyboard.isDown('d')) then
  154. VCAM.x = VCAM.x + 10
  155. end
  156. end
  157. function practice.hint()
  158. love.graphics.setFont(tinyfont)
  159. if love.keyboard.isDown('w') then
  160. love.graphics.setColor(1,0,0,1)
  161. end
  162. love.graphics.print("↑[W]",80,10)
  163. love.graphics.setColor(1,1,1,1)
  164. if love.keyboard.isDown('s') then
  165. love.graphics.setColor(1,0,0,1)
  166. end
  167. love.graphics.print("↓[S]",80,100)
  168. love.graphics.setColor(1,1,1,1)
  169. if love.keyboard.isDown('a') then
  170. love.graphics.setColor(1,0,0,1)
  171. end
  172. love.graphics.print("←[A]",10,50)
  173. love.graphics.setColor(1,1,1,1)
  174. if love.keyboard.isDown('d') then
  175. love.graphics.setColor(1,0,0,1)
  176. end
  177. love.graphics.print("→[D]",150,50)
  178. love.graphics.setColor(1,1,1,1)
  179. end
  180. return practice