No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

52 líneas
1.5 KiB

  1. enemy = Class{}
  2. G = 6.67e-5
  3. function enemy:init(x, y, del, tm, atm, adst)
  4. self.x = x
  5. self.y = y
  6. self.image = love.graphics.newImage("entities/enemy/enemy.png")
  7. self.cannon = love.graphics.newImage("entities/enemy/cannon.png")
  8. self.w = self.image:getWidth()
  9. self.h = self.image:getHeight()
  10. self.cannonw = self.cannon:getWidth()
  11. self.cannonh = self.cannon:getHeight()
  12. self.angle = 0
  13. self.deletable = del
  14. self.maxtimer = tm
  15. self.destX = x
  16. self.otimer = tm
  17. self.timer = tm
  18. self.color = {1,1,1,1}
  19. self.appeared = false
  20. self.actualdest = adst
  21. self.appeartimer = atm
  22. end
  23. function enemy:update(dt)
  24. self.timer = self.timer - dt
  25. if self.timer <= 0 then
  26. self.timer = self.maxtimer
  27. self:shoot()
  28. end
  29. local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
  30. self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x))
  31. if self.x < firstShip.x then
  32. self.angle = self.angle - 3.14159
  33. end
  34. end
  35. function enemy:time(dt)
  36. self.appeartimer = self.appeartimer - dt
  37. end
  38. function enemy:draw()
  39. love.graphics.setColor(unpack(self.color))
  40. love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, self.w/2, self.w/2)
  41. love.graphics.draw(self.cannon, self.x, self.y, self.angle-1.57, 1, 1, self.cannonw/2, self.cannonh/2)
  42. end
  43. function enemy:shoot()
  44. table.insert(projectiles, projectile(self.x, self.y, 0.5, self.angle+3.14, 5))
  45. sounds["launch"]:stop()
  46. sounds["launch"]:play()
  47. end