gota={}

function gota.new(_hab,_x,_y,_freq)
    return {hab=_hab,ix=_x,iy=_y,x=_x,y=_y,freq=_freq,cx=0,dx=0,dy=0,wait=0,step=0,hit=gota.hit,update=gota.update_normal, draw=gota.draw_normal,bb={x=2,y=0,w=4,h=6}}
end

function gota:draw_normal()
    draw.surf(112,0,8,8,self.x,self.y)
end

function gota:update_normal()
    self.wait=self.wait+1

    if self.wait==6 then
        self.wait=0
        self.step=self.step+1
        if self.step > self.freq then
            self.y=self.y+4
            if check_tile(self.hab,self.x+2,self.y+2)>=tiletype.block then
                self.update=gota.update_splash
                self.draw=gota.draw_splash
                self.cx=self.x+2
                self.dx=0
                self.dy=-4
                if self.hab==abad.hab then sound.play(audio_low) end
            end
        else
            --self.flip=not self.flip
        end

        if self.hab==abad.hab then
            if aabb(abad,self) then
                abad_hurt(1)
                self.update=gota.update_splash
                self.draw=gota.draw_splash
                self.cx=self.x+2
                self.dx=0
                self.dy=-4
            end
        end

    end
end

function gota:hit()
end

function gota:draw_splash()
    draw.circf(self.cx+self.dx,self.y,2,16)
    draw.circf(self.cx+self.dx,self.y,1,11)
    draw.circf(self.cx-self.dx,self.y,2,16)
    draw.circf(self.cx-self.dx,self.y,1,11)
    draw.circf(self.cx-(self.dx/2),self.y-4,2,16)
    draw.circf(self.cx-(self.dx/2),self.y-4,1,11)
    draw.circf(self.cx+(self.dx/2),self.y-4,2,16)
    draw.circf(self.cx+(self.dx/2),self.y-4,1,11)
end

function gota:update_splash()
    self.wait=self.wait+1

    if self.wait==3 then
        self.wait=0
        self.dx=self.dx-2
        self.x=self.cx+self.dx
        self.y=self.y+self.dy
        self.dy=self.dy+1
        if self.y>48 then
            self.step=0
            self.update=gota.update_normal
            self.draw=gota.draw_normal
            self.x=self.ix
            self.y=self.iy
        end
    end
end