juju.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Juju = class()
  2. Juju.maxHealth = 100
  3. Juju.moveSpeed = 10
  4. Juju.depth = -6
  5. function Juju:init(data)
  6. self.x = 100
  7. self.y = 100
  8. self.prevx = self.x
  9. self.prevy = self.y
  10. self.angle = love.math.random() * 2 * math.pi
  11. self.depth = self.depth + love.math.random()
  12. self.vy = love.math.random(-300, -100)
  13. self.scale = 0
  14. self.alpha = 0
  15. self.dead = false
  16. table.merge(data, self)
  17. if ctx.tutorial.active then
  18. self.vx = 0
  19. self.vy = -300
  20. self.amount = 50
  21. end
  22. end
  23. function Juju:update()
  24. local p = ctx.player
  25. self.prevx = self.x
  26. self.prevy = self.y
  27. if self.dead then
  28. local tx, ty = 910, 18
  29. self.x, self.y = lume.lerp(self.x, tx, 10 * ls.tickrate), lume.lerp(self.y, ty, 10 * ls.tickrate)
  30. self.scale = lume.lerp(self.scale, .1, 5 * ls.tickrate)
  31. if lume.distance(self.x, self.y, tx, ty) < 16 or ctx.tutorial.active then
  32. ctx.jujus:remove(self)
  33. p:addJuju(self.amount)
  34. ctx.event:emit('juju.collected', {juju = self})
  35. ctx.hud.status.jujuScale = 2
  36. ctx.hud.status.jujuAngle = 0
  37. ctx.particles:emit('jujusex', self.x, self.y, 40)
  38. end
  39. local dis, dir = math.vector(self.x, self.y, self.prevx, self.prevy)
  40. for i = 1, 5 do
  41. local d = love.math.random() * dis
  42. ctx.particles:emit('jujudrop', self.x + math.dx(d, dir), self.y + math.dy(d, dir), 1)
  43. end
  44. return
  45. end
  46. self.vx = lume.lerp(self.vx, 0, ls.tickrate)
  47. self.vy = lume.lerp(self.vy, 0, 2 * ls.tickrate)
  48. self.x = self.x + self.vx * ls.tickrate
  49. self.y = self.y + self.vy * ls.tickrate
  50. if self.vy > -.1 and ctx.tutorial:shouldFloatJuju() then
  51. self.y = self.y - 12 * ls.tickrate
  52. end
  53. if love.math.random() < 3 * ls.tickrate then
  54. local sizes = love.math.random() < .5 and {.2, 0} or {.2, .4}
  55. ctx.particles:emit('jujudrop', self.x, self.y, 1, {sizes = sizes})
  56. end
  57. if p.deathTimer > 0 then
  58. local ghost = p.ghost
  59. local distance, direction = math.vector(self.x, self.y, ghost.x, ghost.y)
  60. local threshold = 100
  61. local exponent = ctx.player:hasShruju('absorb') and .5 or .1
  62. if ctx.player:hasShruju('absorb') then threshold = threshold * 2 end
  63. local factor = math.clamp((threshold - distance) / threshold, 0, 1)
  64. local speed = threshold * (factor ^ exponent) * ls.tickrate * 4
  65. self.x = self.x + math.dx(speed, direction)
  66. self.y = self.y + math.dy(speed, direction)
  67. if lume.distance(ghost.x, ghost.y, self.x, self.y) < ghost.radius then
  68. ctx.sound:play('juju1')
  69. self.dead = true
  70. end
  71. end
  72. if self.y < -300 then
  73. ctx.jujus:remove(self)
  74. end
  75. self.angle = self.angle + (math.sin(tick * ls.tickrate) * math.cos(tick * ls.tickrate)) / love.math.random(9, 11)
  76. self.scale = lume.lerp(self.scale, .15 + (math.min(self.amount, 150) / 250), 2 * ls.tickrate)
  77. self.alpha = lume.lerp(self.alpha, p.dead and 1 or .5, 10 * ls.tickrate)
  78. self.x = math.clamp(self.x, self.amount * 2, ctx.map.width - self.amount * 2)
  79. end
  80. function Juju:draw()
  81. local g = love.graphics
  82. local image = data.media.graphics.juju
  83. local x, y = lume.lerp(self.prevx, self.x, ls.accum / ls.tickrate), lume.lerp(self.prevy, self.y, ls.accum / ls.tickrate)
  84. local wave = math.sin(tick * ls.tickrate * 4)
  85. ctx.jujus.spriteBatch:setColor(255, 255, 255, 255 * self.alpha)
  86. ctx.jujus.spriteBatch:add(self.x, self.y + 3 * wave, self.angle, self.scale, self.scale, image:getWidth() / 2, image:getHeight() / 2)
  87. end