| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- local g = love.graphics
- ShrujuPatch = class()
- ShrujuPatch.width = 80
- ShrujuPatch.height = 40
- ShrujuPatch.depth = 1
- function ShrujuPatch:activate()
- self.y = ctx.map.height - ctx.map.groundHeight
- self.types = {}
- self.effects = {}
- for i = 1, #data.shruju do
- if not isa(data.shruju[i], Shruju) then
- table.insert(self.effects, data.shruju[i].code)
- end
- end
- for i = 1, #data.shruju do
- if isa(data.shruju[i], Shruju) then
- table.insert(self.types, data.shruju[i].code)
- end
- end
- self.timer = 0
- self.slot = nil
- self.highlight = 0
- self.prevHighlight = self.highlight
- self.animation = data.animation.shrujupatch()
- self.animation:on('complete', function(data)
- if data.state.name == 'spawn' then self.animation:set('idle') end
- end)
- self.shrujuAnimation = nil
- ctx.event:emit('view.register', {object = self})
- end
- function ShrujuPatch:deactivate()
- ctx.event:emit('view.unregister', {object = self})
- end
- function ShrujuPatch:update()
- self.timer = timer.rot(self.timer, function()
- do return end
- self:makeShruju()
- ctx.sound:play('shrujuSpawn')
- end)
- self.prevHighlight = self.highlight
- self.highlight = math.lerp(self.highlight, self:playerNearby() and 128 or 0, math.min(5 * ls.tickrate))
- end
- function ShrujuPatch:draw()
- self.animation:draw(self.x, self.y)
- local highlight = math.lerp(self.prevHighlight, self.highlight, ls.accum / ls.tickrate)
- table.each(self.animation.spine.skeleton.slots, function(slot)
- slot.a = highlight / 255
- slot.data.additiveBlending = true
- end)
- self.animation:draw(self.x, self.y)
- table.each(self.animation.spine.skeleton.slots, function(slot)
- slot.a = 1
- slot.data.additiveBlending = false
- end)
- g.setBlendMode('alpha')
- if self.shrujuAnimation then self.shrujuAnimation:draw(self.x, self.y + 15) end
- end
- function ShrujuPatch:grow(what)
- if not self:playerNearby() or not table.has(self.types, what) or self.growing or self.slot then return end
- self.timer = self:getGrowTime(what)
- self.growing = what
- end
- function ShrujuPatch:take()
- if not self:playerNearby() or not self.slot then return end
- local slot = self.slot
- self.slot = nil
- self.shrujuAnimation = nil
- return slot
- end
- function ShrujuPatch:playerNearby()
- local p = ctx.player
- return not p.dead and math.abs(p.x - self.x) <= self.width / 2 + p.width / 2
- end
- function ShrujuPatch:makeShruju()
- if self.growing and not self.slot then
- local shruju = data.shruju[self.growing]()
- -- Magic effect
- if love.math.random() < .25 then
- local effects = self.effects
- shruju.effect = setmetatable({timer = config.shruju.magicDuration}, {__index = data.shruju[effects[love.math.random(1, #effects)]]})
- end
- self.slot = shruju
- self.growing = nil
- self.shrujuAnimation = data.animation.shruju1()
- self.shrujuAnimation:on('complete', function(data)
- if data.state.name == 'spawn' then
- self.shrujuAnimation:set('idle')
- end
- end)
- end
- end
- function ShrujuPatch:getGrowTime(code)
- return math.max(config.shruju.growTime - (ctx.shrujuPatches.harvestLevel * config.shruju.harvestCooldownReduction), config.shruju.minGrowTime)
- end
- function ShrujuPatch:removeType(code)
- for i = 1, #self.types do
- if self.types[i] == code then table.remove(self.types, i) return end
- end
- end
|