Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

59 wiersze
1.9 KiB

  1. planet = Class{}
  2. G = 6.67e-1
  3. function planet:init(x, y, mass, radius, img, arg)
  4. self.x = x
  5. self.y = y
  6. self.mass = mass
  7. self.attractionX = 0
  8. self.attractionY = 0
  9. self.charge = 20
  10. self.r = radius
  11. self.w = img:getWidth()
  12. self.image = img
  13. self.angle = 0
  14. self.color = {1,1,1,1}
  15. if arg == "nodelete" then
  16. self.deletable = false
  17. else
  18. self.deletable = true
  19. end
  20. end
  21. function planet:update(dt)
  22. if not reachedGoal then
  23. local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
  24. --print("update")
  25. local gravitationalAttraction = G*self.mass/(distanceToShip^2)
  26. --print((firstShip.x - self.x) .. " " .. (firstShip.y - self.y))
  27. self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x))
  28. if self.x < firstShip.x then
  29. self.angle = self.angle - 3.14159
  30. end
  31. --print("Angle is:" .. self.angle*57.29)
  32. self.attractionY = math.sin(self.angle) * gravitationalAttraction
  33. self.attractionX = math.cos(self.angle) * gravitationalAttraction
  34. love.window.setTitle(self.attractionX)
  35. firstShip.dx = firstShip.dx + self.attractionX
  36. firstShip.dy = firstShip.dy + self.attractionY
  37. if distanceToShip < self.w/4 and not reachedGoal then
  38. shipIsHit = true
  39. sounds["close"]:stop()
  40. sounds["boom"]:play()
  41. sounds["boom"]:setVolume(1)
  42. end
  43. end
  44. end
  45. function planet:draw()
  46. --love.graphics.rectangle("fill", firstShip.x, firstShip.y, 30, 30)
  47. love.graphics.push()
  48. love.graphics.translate(firstShip.x, firstShip.y) -- move relative (0,0) to (x,y)
  49. love.graphics.rotate(self.angle) -- rotate coordinate system around relative (0,0) (absolute (x,y))
  50. --love.graphics.rectangle("fill", -(firstShip.x - self.x)/2, -20/2, (firstShip.x - self.x), 20) VECTOR
  51. love.graphics.pop()
  52. love.graphics.setColor(unpack(self.color))
  53. love.graphics.draw(self.image, self.x, self.y, 1.5708, self.r, self.r, self.w/2, self.w/2)
  54. end