local CreateDogEffectContent = nil

function CreateDogEffect(targetPos, startPos, callback)
    CreateDogEffectContent()
    
    local level  = GetCurrentLevel()
    local tracer = play_field:GetObject('DogEffectTracer')
    local target = play_field:GetObject('DogEffectTarget')
    
    if not startPos then
        local dogArea = level:GetPanel():GetObject('area_dog')
        startPos = Vector(dogArea:GetScrX(), dogArea:GetScrY())
    end
    
    local deltaPos    = targetPos - startPos
    local tracerScale = deltaPos:Length() / tracer:GetAnimation():GetWidth()
    
    do
        tracer:SetLayer( level:GetPanel():GetLayer() + 1)
        tracer:SetZ(1000)
        tracer:SetScrXY(startPos.x, startPos.y)
        tracer:SetAngle(deltaPos:Angle(nil))
        tracer:SetScaleX(tracerScale)
        
        tracer:SetVisible(true)
        tracer:GetAnimation():Play()
        
        level.sound_dog_effect:StopSound()
        level.sound_dog_effect:PlaySound(false)
    end
    
    do
        target:SetLayer( level:GetPanel():GetLayer() + 1)
        target:SetZ(1000)
        target:SetScrXY(targetPos.x, targetPos.y)
        target:SetAngle(deltaPos:Angle(nil))
    end
    
    level.mouseBlocker:Push()
    level.timer:Add(function()
                        target:SetVisible(true)
                        target:GetAnimation():Play()
                        
                        level.timer:Add(function()
                                            level.mouseBlocker:Pop()
                                            
                                            target:SetVisible(false)
                                            target:GetAnimation():Stop()
                                            target:GetAnimation():Rewind(false)
                                            
                                            tracer:SetVisible(false)
                                            tracer:GetAnimation():Stop()
                                            tracer:GetAnimation():Rewind(false)
                                            
                                            if callback then
                                                callback()
                                            end
                                        end,
                                        GetAnimationLength(target:GetAnimation()))
                    end,
                    GetAnimationLength(tracer:GetAnimation()) * 0.3)
end

CreateDogEffectContent = function()
    if play_field:HasObject('DogEffectTracer') then
        return
    end
    
    do
        local anim
        local object
        
        anim = CreateAnimation('data/Texture/GUI/DogEffect/DogEffectTracer.png',0,0,490,130,23,24)
        anim:SetHotSpot(0,65)
        anim:SetBlendMode(2)
        anim:SetColor('0xFFFFFFFF')
        object = play_field:CreateObject('DogEffectTracer',anim,0,0,0,0,1,1)
        object:GetAnimation():SetMode(HGEANIM_FWD + HGEANIM_NOLOOP)
        object:SetVisible(false)
    end
    
    do
        local anim
        local object
        
        anim = CreateAnimation('data/Texture/GUI/DogEffect/DogEffectTarget.png',0,0,110,100,24,24)
        anim:SetHotSpot(55,50)
        anim:SetBlendMode(2)
        anim:SetColor('0xFFFFFFFF')
        object = play_field:CreateObject('DogEffectTarget',anim,0,0,0,0,1.5,1.5)
        object:GetAnimation():SetMode(HGEANIM_FWD + HGEANIM_NOLOOP)
        object:SetVisible(false)
    end
    
    GetCurrentLevel().sound_dog_effect = MakeSoundEntity('dog_effect')
end