Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

45 строки
1.6 KiB

  1. planet = Class{}
  2. G = 6.67e-1
  3. function planet:init(x, y, mass, radius, img)
  4. self.x = x
  5. self.y = y
  6. self.mass = mass
  7. self.r = radius
  8. self.w = img:getWidth()
  9. self.image = img
  10. self.angle = 0
  11. self.color = {1,1,1,1}
  12. end
  13. function planet:update(dt)
  14. local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
  15. local gravitationalAttraction = G*self.mass/(distanceToShip^2)
  16. print((firstShip.x - self.x) .. " " .. (firstShip.y - self.y))
  17. self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x))
  18. if self.x < firstShip.x then
  19. self.angle = self.angle - 3.14159
  20. end
  21. --print("Angle is:" .. self.angle*57.29)
  22. self.attractionY = math.sin(self.angle) * gravitationalAttraction
  23. self.attractionX = math.cos(self.angle) * gravitationalAttraction
  24. love.window.setTitle(self.attractionX)
  25. firstShip.dx = firstShip.dx + self.attractionX
  26. firstShip.dy = firstShip.dy + self.attractionY
  27. if distanceToShip < self.w/4 then
  28. shipIsHit = true
  29. end
  30. end
  31. function planet:draw()
  32. --love.graphics.rectangle("fill", firstShip.x, firstShip.y, 30, 30)
  33. love.graphics.push()
  34. love.graphics.translate(firstShip.x, firstShip.y) -- move relative (0,0) to (x,y)
  35. love.graphics.rotate(self.angle) -- rotate coordinate system around relative (0,0) (absolute (x,y))
  36. --love.graphics.rectangle("fill", -(firstShip.x - self.x)/2, -20/2, (firstShip.x - self.x), 20) VECTOR
  37. love.graphics.pop()
  38. love.graphics.setColor(unpack(self.color))
  39. love.graphics.draw(self.image, self.x, self.y, 1.5708, self.r, self.r, self.w/2, self.w/2)
  40. end