spuju.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. local spuju = {}
  2. function spuju:idle()
  3. self.target = self:closest('minion', 'shruju')
  4. if self.target then
  5. self.state = 'move'
  6. end
  7. end
  8. function spuju:move()
  9. self.target = self:closest('minion', 'shruju')
  10. local isInRange = self:isInRangeOf(self.target)
  11. local distanceToTarget = self:distanceTo(self.target) - self.config.radius - self.target.config.radius
  12. local directionToTarget = self:directionTo(self.target)
  13. if self.target.isShruju then
  14. self.animation:set('walk')
  15. self.targetDirection = directionToTarget
  16. self.direction = util.anglerp(self.direction, self.targetDirection, lib.tick.getLerpFactor(.05))
  17. self:moveInDirection(self.direction, self.config.speed)
  18. if distanceToTarget <= 0 then
  19. if self:pickupShruju(self.target) then
  20. self.state = 'run'
  21. end
  22. end
  23. return
  24. end
  25. if isInRange and love.math.random() < .25 / lib.tick.rate then
  26. if distanceToTarget < self.config.fearRange and love.math.random() < .25 and self.abilities.fear:canCast(self) then
  27. local x, y = self.target.position.x, self.target.position.y
  28. self.abilities.fear:cast(self, x, y)
  29. self.animation:set('fear')
  30. self.state = 'fear'
  31. elseif not self.lastAttack or (lib.tick.index - self.lastAttack) * lib.tick.rate >= self.config.attackCooldown then
  32. self.animation:set('attack')
  33. self.state = 'attack'
  34. end
  35. elseif not isInRange then
  36. self.animation:set('walk')
  37. self.targetDirection = directionToTarget
  38. self.direction = util.anglerp(self.direction, self.targetDirection, lib.tick.getLerpFactor(.05))
  39. self:moveInDirection(self.direction, self.config.speed)
  40. else
  41. local flip = (math.floor(lib.tick.index * lib.tick.rate / 2) % 2) == 0
  42. self.targetDirection = flip and (directionToTarget + math.pi * .5) or (directionToTarget - math.pi * .5)
  43. self.direction = util.anglerp(self.direction, self.targetDirection, lib.tick.getLerpFactor(.05))
  44. self:moveInDirection(self.direction, self.config.speed / 2)
  45. end
  46. if self:isEscaped() then
  47. self:enclose()
  48. end
  49. end
  50. function spuju:attack()
  51. self.lastAttack = lib.tick.index
  52. end
  53. function spuju:fear()
  54. -- wait for animation to complete
  55. end
  56. function spuju:run()
  57. local targetX, targetY
  58. if self.position.x < app.context.scene.width / 2 then
  59. targetX = 0
  60. targetY = app.context.scene.height / 2
  61. self.animation.flipped = false
  62. else
  63. targetX = app.context.scene.width
  64. targetY = app.context.scene.height / 2
  65. self.animation.flipped = true
  66. end
  67. local distance = self:distanceToPoint(targetX, targetY)
  68. local direction = self:directionToPoint(targetX, targetY)
  69. self.direction = util.anglerp(self.direction, direction, lib.tick.getLerpFactor(.05))
  70. self:moveInDirection(self.direction, self.config.speed / 3)
  71. if distance < 50 then
  72. self.target:die()
  73. self.state = 'idle'
  74. end
  75. end
  76. function spuju:hurt(...)
  77. if self.abilities.fear:isOnCooldown() and self.abilities.fear.lastCast then
  78. self.abilities.fear.lastCast = self.abilities.fear.lastCast + (1 / lib.tick.rate)
  79. end
  80. if self.lastAttack then
  81. self.lastAttack = self.lastAttack + (1 / lib.tick.rate)
  82. end
  83. return lib.unit.hurt(self, ...)
  84. end
  85. function spuju:draw()
  86. local image = app.art.shadow
  87. local scale = 60 / image:getWidth()
  88. g.white(70)
  89. g.draw(image, self.position.x, self.position.y, 0, scale, scale / 1.5, image:getWidth() / 2, image:getHeight() / 2)
  90. self:drawRing(255, 40, 40)
  91. self.animation:tick(lib.tick.delta)
  92. if util.timeSince(self.lastHurt) < self.config.damageFlashDuration then
  93. self.animation:draw(self.position.x, self.position.y)
  94. app.shaders.colorize:send('color', { 1, 1, 1, 1 - util.timeSince(self.lastHurt) / self.config.damageFlashDuration })
  95. g.setShader(app.shaders.colorize)
  96. self.animation:draw(self.position.x, self.position.y)
  97. g.setShader()
  98. else
  99. self.animation:draw(self.position.x, self.position.y)
  100. end
  101. return -self.position.y
  102. end
  103. return spuju