59 lines
1.3 KiB
Lua
59 lines
1.3 KiB
Lua
|
local pd <const> = playdate
|
||
|
local gfx <const> = playdate.graphics
|
||
|
|
||
|
class('Baleba').extends(AnimatedSprite)
|
||
|
|
||
|
function randomFloat(lower, greater)
|
||
|
return lower + math.random() * (greater - lower);
|
||
|
end
|
||
|
|
||
|
function Baleba:init(x, y, player)
|
||
|
local balebaImageTable = gfx.imagetable.new("sprites/baleba")
|
||
|
Baleba.super.init(self, balebaImageTable)
|
||
|
|
||
|
self:moveTo(x, y)
|
||
|
|
||
|
self:addState("run", 1,4, {tickStep = 2})
|
||
|
|
||
|
self:setDefaultState("run")
|
||
|
|
||
|
self:playAnimation()
|
||
|
|
||
|
self:setZIndex(11)
|
||
|
self:setCollideRect(3, 25, 40, 15)
|
||
|
|
||
|
self:setTag(154)
|
||
|
|
||
|
self.standrate = randomFloat(0.3, 2)
|
||
|
self.xVelocity = Baleba.standrate
|
||
|
self.player = player
|
||
|
|
||
|
|
||
|
self.danger = Danger(366, y, self)
|
||
|
self.danger:add()
|
||
|
end
|
||
|
|
||
|
function Baleba:update()
|
||
|
self:updateAnimation()
|
||
|
if self.player.isMovingRight() == false then
|
||
|
self.xVelocity = self.standrate
|
||
|
else
|
||
|
self.xVelocity = 2 + self.standrate
|
||
|
end
|
||
|
|
||
|
if self.x < 430 and self.danger ~= nil then
|
||
|
self.danger:remove()
|
||
|
self.danger = nil
|
||
|
elseif self.danger == nil and self.x > 430 then
|
||
|
self.danger = Danger(366, self.y, self)
|
||
|
self.danger:add()
|
||
|
end
|
||
|
|
||
|
if self.x < 0 then
|
||
|
self.standrate = randomFloat(0.5, 6)
|
||
|
self:moveTo(math.random(450, 600), math.random(50, 200))
|
||
|
end
|
||
|
|
||
|
self:moveTo(self.x-self.xVelocity, self.y)
|
||
|
end
|