| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- Shrine = class()
- Shrine.code = 'shrine'
- Shrine.width = 144
- Shrine.height = 144
- Shrine.maxHealth = 5000
- Shrine.depth = -3.47
- function Shrine:init()
- self.x = ctx.map.width / 2
- self.y = ctx.map.height - ctx.map.groundHeight - self.height
- self.health = self.maxHealth
- self.healthDisplay = self.health
- self.lastHurt = -math.huge
- self.hurtFactor = 0
- self.highlight = 0
- self.regen = 0
- ctx.event:emit('view.register', {object = self})
- end
- function Shrine:update()
- self.healthDisplay = math.lerp(self.healthDisplay, self.health, math.min(math.lerp(2 * ls.tickrate, 1, 1 - (self.health / self.maxHealth)), 1))
- local p = ctx.player
- if ctx.tutorial:shouldHighlightShrine() then
- self.highlight = math.lerp(self.highlight, p:atShrine() and 1 or 0, math.min((p:atShrine() and 10 or 5) * ls.tickrate, 1))
- end
- self.hurtFactor = math.lerp(self.hurtFactor, (tick - self.lastHurt) * ls.tickrate < 5 and 1 or 0, math.min(4 * ls.tickrate, 1))
- if tick - self.lastHurt > 5 / ls.tickrate then
- self.health = math.min(self.health + (self.maxHealth * .003) * ls.tickrate, self.maxHealth)
- end
- self.health = math.min(self.health + math.max(self.regen, 0) * ls.tickrate, self.maxHealth)
- end
- function Shrine:draw()
- local g = love.graphics
- local image = data.media.graphics.shrine
- local scale = self.height / image:getHeight()
- g.setColor(255, 255, 255)
- g.draw(image, self.x + 10, self.y + self.height, 0, scale, scale, image:getWidth() / 2, image:getHeight())
- g.setBlendMode('additive')
- g.setColor(255, 255, 255, self.highlight * 100)
- g.draw(image, self.x + 10, self.y + self.height, 0, scale, scale, image:getWidth() / 2, image:getHeight())
- g.setColor(255, 255, 255, 255)
- g.setBlendMode('alpha')
- end
- function Shrine:getHealthbar()
- return self.x, self.y, self.healthDisplay / self.maxHealth, self.healthDisplay / self.maxHealth
- end
- function Shrine:hurt(amount, source, kind)
- self.health = math.max(self.health - amount, 0)
- self.lastHurt = tick
- if self.health <= 0 and not ctx.ded then
- ctx.event:emit('shrine.dead', {shrine = self})
- return true
- end
- if ctx.player:hasShruju('mirror') and source and kind and table.has(kind, 'attack') then
- source:hurt(amount)
- end
- end
- function Shrine:contains(x, y)
- return math.inside(x, y, self.width - self.width / 2, self.y, self.width, self.height)
- end
|