health_potion_gif_x = 192
health_potion_gif_y = 128

health_potion={}

function health_potion.new(_hab, _x, _y, _y_speed, _max_height, _heal)
    _raising = false
    if _max_height>0 then _raising=true end
    return {
        name="health_potion",
        hab = _hab,
        x = _x, y = _y,
        w = 16, h = 16,
        vx=0, vy=0,
        y_speed = _y_speed,
        max_height = _max_height,
        heal = _heal,
        raising = _raising,
        enabled=true,
        wait = 0,
        bb={x=4,y=0,w=9,h=16},
        update=health_potion.update,
        draw=health_potion.draw,
    }
end

function health_potion:draw()
    if not self.enabled then return end
    local x = health_potion_gif_x
	local y = health_potion_gif_y
    local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
    if self.heal==1 then
        pal.subpal(3,11)
    elseif self.heal==2 then
        pal.subpal(3,8)
    end
    draw.surf(x,y,self.w,self.h,scr_x,scr_y,self.w,self.h)
    pal.subpal(3)
    -- draw.rect(scr_x+health_potion.bb.x,scr_y+health_potion.bb.y,health_potion.bb.w,health_potion.bb.h,3)
end

function health_potion:update()
    if not self.enabled then return end
    if self.raising and self.y_speed>0 then
        self.y_speed = -self.y_speed
    elseif not self.raising and self.y_speed<0 then
        self.y_speed = -self.y_speed
    end
    
    local x2_check = self.x+self.bb.x+self.bb.w
    local x1_check = self.x+self.bb.x
    local y_check = self.y+self.bb.h+self.y_speed
    
    if true then 
        self.wait=0
        self.max_height = self.max_height+self.y_speed
        self.y = self.y+self.y_speed
        if self.max_height==0 then self.raising=false end
    end
    self.wait=self.wait+1
    
    local tile1_hit_type= arc_check_tile(x1_check, y_check )
    local tile2_hit_type= arc_check_tile(x2_check, y_check)
    local block_tile = tile1_hit_type == tiletype.block or tile2_hit_type == tiletype.block
    
    if block_tile then self.y_speed=0 end
    self.hab = coords.world_to_tile(self.x, self.y)
    if self.hab==abad.hab then
        if collision(abad,self) then
            abad_heal(self.heal)
            self.enabled = false
            remove_actor(self)
        end
    end
end