juju.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Juju = class()
  2. Juju.maxHealth = 100
  3. Juju.moveSpeed = 10
  4. Juju.depth = -6
  5. Juju.image = love.graphics.newImage('media/graphics/juju-icon.png')
  6. function Juju:init(data)
  7. -- Data = ({amount, x, y, velocity,speed})
  8. --self.amount = 20
  9. self.x = 100
  10. self.y = 100
  11. self.prevx = self.x
  12. self.prevy = self.y
  13. self.angle = love.math.random() * 2 * math.pi
  14. self.depth = self.depth + love.math.random()
  15. self.vy = love.math.random(-300, -100)
  16. self.scale = 0
  17. self.alpha = 0
  18. self.dead = false
  19. table.merge(data, self)
  20. for i = 1, 15 do
  21. ctx.particles:add(JujuSex, {x = self.x, y = self.y})
  22. end
  23. ctx.view:register(self)
  24. end
  25. function Juju:update()
  26. self.prevx = self.x
  27. self.prevy = self.y
  28. if self.dead then
  29. local tx, ty = 52, 52
  30. self.x, self.y = math.lerp(self.x, tx, 10 * tickRate), math.lerp(self.y, ty, 10 * tickRate)
  31. self.scale = math.lerp(self.scale, .1, 5 * tickRate)
  32. if math.distance(self.x, self.y, tx, ty) < 16 then
  33. ctx.jujus:remove(self)
  34. ctx.player.juju = ctx.player.juju + self.amount
  35. ctx.hud.jujuIconScale = 1
  36. for i = 1, 20 do
  37. ctx.particles:add(JujuSex, {x = tx, y = ty})
  38. end
  39. end
  40. for i = 1, 2 do
  41. ctx.particles:add(JujuSex, {x = self.x, y = self.y})
  42. end
  43. return
  44. end
  45. self.vx = math.lerp(self.vx, 0, tickRate)
  46. self.vy = math.lerp(self.vy, 0, 2 * tickRate)
  47. self.x = self.x + self.vx * tickRate
  48. self.y = self.y + self.vy * tickRate
  49. if self.vy > -.1 then
  50. self.y = self.y - 10 * tickRate
  51. end
  52. if love.math.random() < 2 * tickRate then
  53. ctx.particles:add(JujuSex, {x = self.x, y = self.y, vy = love.math.random(-150, -75), vx = love.math.random(-100, 100), alpha = .35})
  54. end
  55. if ctx.player.jujuRealm > 0 then
  56. local ghost = ctx.player.ghost
  57. if ctx.upgrades.muju.absorb.level > 0 then
  58. local distance, direction = math.vector(self.x, self.y, ghost.x, ghost.y)
  59. local threshold = self.amount + 75 + 50 * ctx.upgrades.muju.absorb.level
  60. local factor = math.clamp((threshold - distance) / threshold, 0, 1)
  61. local speed = threshold * factor * tickRate
  62. self.x = self.x + math.dx(speed, direction)
  63. self.y = self.y + math.dy(speed, direction)
  64. end
  65. if math.distance(ghost.x, ghost.y, self.x, self.y) < self.amount + ghost.radius then
  66. ctx.sound:play({sound = ctx.sounds['juju1']})
  67. self.dead = true
  68. end
  69. end
  70. if self.y < -50 then
  71. ctx.jujus:remove(self)
  72. end
  73. self.angle = self.angle + (math.sin(tick * tickRate) * math.cos(tick * tickRate)) / love.math.random(9, 11)
  74. self.scale = math.lerp(self.scale, math.clamp(self.amount / 50, .25, .6), 2 * tickRate)
  75. self.alpha = math.lerp(self.alpha, 1, 2 * tickRate)
  76. self.x = math.clamp(self.x, self.amount, love.graphics.getWidth() - self.amount)
  77. end
  78. function Juju:draw()
  79. local g = love.graphics
  80. local x, y = math.lerp(self.prevx, self.x, tickDelta / tickRate), math.lerp(self.prevy, self.y, tickDelta / tickRate)
  81. local wave = math.sin(tick * tickRate * 4)
  82. g.setBlendMode('additive')
  83. g.setColor(255, 255, 255, 30 * self.alpha)
  84. g.draw(self.image, self.x, self.y + 5 * wave, self.angle, self.scale * (1.6 + wave / 12), self.scale * (1.6 + wave / 12), self.image:getWidth() / 2, self.image:getHeight() / 2)
  85. g.setBlendMode('alpha')
  86. g.setColor(255, 255, 255, 255 * self.alpha)
  87. g.draw(self.image, self.x, self.y + 5 * wave, self.angle, self.scale, self.scale, self.image:getWidth() / 2, self.image:getHeight() / 2)
  88. end