shrine.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Shrine = class()
  2. Shrine.width = 128
  3. Shrine.height = 128
  4. Shrine.maxHealth = 2500
  5. Shrine.depth = 5
  6. function Shrine:init()
  7. local w, h = love.graphics.getDimensions()
  8. self.x = w / 2
  9. self.y = h - ctx.environment.groundHeight - self.height - 7
  10. self.health = self.maxHealth
  11. self.healthDisplay = self.health
  12. self.image = love.graphics.newImage('media/graphics/shrine-v3.png')
  13. self.color = {255, 255, 255}
  14. self.highlight = 0
  15. ctx.view:register(self)
  16. end
  17. function Shrine:update()
  18. if self.health <= 0 then
  19. ctx.ded = true
  20. end
  21. self.health = math.min(self.maxHealth, self.health + (self.maxHealth * ctx.upgrades.muju.imbue.level * .005 * tickRate))
  22. self.color = table.interpolate(self.color, ctx.player.dead and {160, 100, 225} or {255, 255, 255}, .6 * tickRate)
  23. self.healthDisplay = math.lerp(self.healthDisplay, self.health, 20 * tickRate)
  24. self.highlight = math.lerp(self.highlight, math.abs(ctx.player.x - self.x) < ctx.player.width and 128 or 0, 5 * tickRate)
  25. end
  26. function Shrine:draw()
  27. local g = love.graphics
  28. local scale = self.width / self.image:getWidth()
  29. g.setColor(self.color)
  30. g.draw(self.image, self.x, self.y + self.height + 12, 0, scale, scale, self.image:getWidth() / 2, self.image:getHeight())
  31. g.setBlendMode('additive')
  32. g.setColor(255, 255, 255, self.highlight)
  33. g.draw(self.image, self.x, self.y + self.height + 12, 0, scale, scale, self.image:getWidth() / 2, self.image:getHeight())
  34. g.setColor(255, 255, 255, 255)
  35. g.setBlendMode('alpha')
  36. end
  37. function Shrine:hurt(value)
  38. self.health = self.health - value
  39. if self.health < 0 then
  40. ctx.sound:play({sound = ctx.sounds['youlose']})
  41. backgroundSound:stop()
  42. return true
  43. end
  44. end