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