local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala

cacau={hab=-1,x=0,y=0,wait=0,flip=false,bb={x=0,y=0,w=4,h=4}}

function cacau.init(_hab,_x,_y,_flip)
    if cacau.hab ~= -1 then return end
    cacau.hab=_hab
    cacau.x=_x
    cacau.y=_y
    cacau.flip=_flip
end

function cacau.draw()
    draw.circf(cacau.x*o2aX,cacau.y*o2aX,2*o2aX,16)
	draw.circf((cacau.x+2)*o2aX,cacau.y*o2aX,2*o2aX,16)
    draw.circf(cacau.x*o2aX,cacau.y*o2aX,1*o2aX,6)
    draw.circf((cacau.x+2)*o2aX,cacau.y*o2aX,1*o2aX,6)
end

function cacau.update()
    if cacau.hab == -1 then return end
    cacau.wait=cacau.wait+1

    if cacau.wait==3 then
        cacau.wait=0

        if cacau.x>96 then
            cacau.hab=-1
            return
        elseif check_tile(cacau.hab,cacau.x,cacau.y)<tiletype.block then
            if cacau.flip then
                cacau.x=cacau.x-4
            else
                cacau.x=cacau.x+4
            end
            if cacau.x<-4 then
                cacau.hab=-1
                return
            end
        else
            cacau.hab=-1
            return
        end
    end
end
