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.

50 regels
1.4 KiB

  1. enemy = Class{}
  2. G = 6.67e-5
  3. function enemy:init(x, y, del, tm, atm)
  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.timer = tm
  17. self.color = {1,1,1,1}
  18. self.appeared = false
  19. self.appeartimer = atm
  20. end
  21. function enemy:update(dt)
  22. self.timer = self.timer - dt
  23. if self.timer <= 0 then
  24. self.timer = self.maxtimer
  25. self:shoot()
  26. end
  27. local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
  28. self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x))
  29. if self.x < firstShip.x then
  30. self.angle = self.angle - 3.14159
  31. end
  32. end
  33. function enemy:time(dt)
  34. self.appeartimer = self.appeartimer - dt
  35. end
  36. function enemy:draw()
  37. love.graphics.setColor(unpack(self.color))
  38. love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, self.w/2, self.w/2)
  39. love.graphics.draw(self.cannon, self.x, self.y, self.angle-1.57, 1, 1, self.cannonw/2, self.cannonh/2)
  40. end
  41. function enemy:shoot()
  42. table.insert(projectiles, projectile(self.x, self.y, 0.5, self.angle+3.14, 5))
  43. sounds["launch"]:stop()
  44. sounds["launch"]:play()
  45. end