You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 line
1.6 KiB

  1. projectile = Class{}
  2. G = 6.67e-5
  3. function projectile:init(x, y, v, angle, timer)
  4. self.x = x
  5. self.y = y
  6. self.dx = 0
  7. self.dy = 0
  8. self.image = love.graphics.newImage("entities/enemy/missile-01.png")
  9. self.w = self.image:getWidth()
  10. self.h = self.image:getHeight()
  11. self.angle = angle
  12. self.v = v
  13. self.timer = timer
  14. self.killed = false
  15. self.dx = math.cos(self.angle) * self.v
  16. self.dy = math.sin(self.angle) * self.v
  17. self.vx = 0
  18. self.vy = 0
  19. end
  20. function projectile:update(dt)
  21. local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
  22. self.timer = self.timer - dt
  23. if self.timer <= 0 then
  24. self.killed = true
  25. end
  26. self.vx = self.vx + self.dx
  27. self.vy = self.vy + self.dy
  28. self.x = self.x + self.vx
  29. self.y = self.y + self.vy
  30. if distanceToShip < firstShip.width/2 then
  31. shipIsHit = true
  32. sounds["close"]:stop()
  33. sounds["boom"]:play()
  34. sounds["boom"]:setVolume(1)
  35. end
  36. for i in ipairs(planets) do
  37. if planets[i].deletable == false then
  38. distanceToShip = math.sqrt((planets[i].x - self.x)^2 + (planets[i].y - self.y)^2)
  39. if distanceToShip < planets[i].w/4 then
  40. sounds["boom"]:play()
  41. sounds["boom"]:setVolume(0.4)
  42. local q = #explosions
  43. table.insert(explosions, explosion(self.x, self.y, 10, {1,1,1,1}))
  44. explosions[q+1].type = 2
  45. table.remove(planets, i)
  46. self.killed = true
  47. end
  48. end
  49. end
  50. end
  51. function projectile:draw()
  52. love.graphics.draw(self.image, self.x, self.y, self.angle, 1, 1, self.w/2, self.w/2)
  53. end