shrine.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Shrine = class()
  2. Shrine.code = 'shrine'
  3. Shrine.width = 144
  4. Shrine.height = 144
  5. Shrine.maxHealth = 5000
  6. Shrine.depth = -3.47
  7. function Shrine:init()
  8. self.x = ctx.map.width / 2
  9. self.y = ctx.map.height - ctx.map.groundHeight - self.height
  10. self.health = self.maxHealth
  11. self.healthDisplay = self.health
  12. self.lastHurt = -math.huge
  13. self.hurtFactor = 0
  14. self.highlight = 0
  15. self.regen = 0
  16. ctx.event:emit('view.register', {object = self})
  17. end
  18. function Shrine:update()
  19. self.healthDisplay = math.lerp(self.healthDisplay, self.health, math.min(math.lerp(2 * ls.tickrate, 1, 1 - (self.health / self.maxHealth)), 1))
  20. local p = ctx.player
  21. if ctx.tutorial:shouldHighlightShrine() then
  22. self.highlight = math.lerp(self.highlight, p:atShrine() and 1 or 0, math.min((p:atShrine() and 10 or 5) * ls.tickrate, 1))
  23. end
  24. self.hurtFactor = math.lerp(self.hurtFactor, (tick - self.lastHurt) * ls.tickrate < 5 and 1 or 0, math.min(4 * ls.tickrate, 1))
  25. if tick - self.lastHurt > 5 / ls.tickrate then
  26. self.health = math.min(self.health + (self.maxHealth * .003) * ls.tickrate, self.maxHealth)
  27. end
  28. self.health = math.min(self.health + math.max(self.regen, 0) * ls.tickrate, self.maxHealth)
  29. end
  30. function Shrine:draw()
  31. local g = love.graphics
  32. local image = data.media.graphics.shrine
  33. local scale = self.height / image:getHeight()
  34. g.setColor(255, 255, 255)
  35. g.draw(image, self.x + 10, self.y + self.height, 0, scale, scale, image:getWidth() / 2, image:getHeight())
  36. g.setBlendMode('additive')
  37. g.setColor(255, 255, 255, self.highlight * 100)
  38. g.draw(image, self.x + 10, self.y + self.height, 0, scale, scale, image:getWidth() / 2, image:getHeight())
  39. g.setColor(255, 255, 255, 255)
  40. g.setBlendMode('alpha')
  41. end
  42. function Shrine:getHealthbar()
  43. return self.x, self.y, self.healthDisplay / self.maxHealth, self.healthDisplay / self.maxHealth
  44. end
  45. function Shrine:hurt(amount, source, kind)
  46. self.health = math.max(self.health - amount, 0)
  47. self.lastHurt = tick
  48. if self.health <= 0 and not ctx.ded then
  49. ctx.event:emit('shrine.dead', {shrine = self})
  50. return true
  51. end
  52. if ctx.player:hasShruju('mirror') and source and kind and table.has(kind, 'attack') then
  53. source:hurt(amount)
  54. end
  55. end
  56. function Shrine:contains(x, y)
  57. return math.inside(x, y, self.width - self.width / 2, self.y, self.width, self.height)
  58. end