local offsets = {
    idle = 
    {
        x = 22, 
        y = -118
    },
    left =
    {
        x = 35,
        y = -96
    },
    down =
    {
        x = 19,
        y = -115
    },
    up =
    {
        x = -11,
        y = -116
    },
    right =
    {
        x = 65,
        y = -42
    }
}

local playerX = getProperty("boyfriend.x") 
local playerY = getProperty("boyfriend.y") 

function onCreatePost()
    makeAnimatedLuaSprite("alienarms", "characters/alienarms", playerX - offsets.idle.x, playerY - offsets.idle.y)
    addAnimationByPrefix("alienarms", "idle", "idle", 24, true)
    addAnimationByPrefix("alienarms", "left", "left", 24, false)
    addAnimationByPrefix("alienarms", "down", "down", 24, false)
    addAnimationByPrefix("alienarms", "up", "up", 24, false)
    addAnimationByPrefix("alienarms", "right", "right", 24, false)
    
    setObjectOrder("alienarms", 6)
    addLuaSprite("alienarms")
end

function goodNoteHit(index, noteData, noteType, isSustain)
    if noteData == 0 then
        setProperty("alienarms.x", playerX - offsets.left.x)
        setProperty("alienarms.y", playerY - offsets.left.y)
        playAnim("alienarms", "left", true, false)
    elseif noteData == 1 then
        setProperty("alienarms.x", playerX - offsets.down.x)
        setProperty("alienarms.y", playerY - offsets.down.y)
        playAnim("alienarms", "down", true, false)
    elseif noteData == 2 then
        setProperty("alienarms.x", playerX - offsets.up.x)
        setProperty("alienarms.y", playerY - offsets.up.y)
        playAnim("alienarms", "up", true, false)
    elseif noteData == 3 then
        setProperty("alienarms.x", playerX - offsets.right.x)
        setProperty("alienarms.y", playerY - offsets.right.y)
        playAnim("alienarms", "right", true, false)
    end
end

local oldCurAnim = ""
local newCurAnim = ""

local function returnCurAnim()
    oldCurAnim = getProperty('boyfriend.animation.curAnim.name')
    if oldCurAnim ~= newCurAnim then
        return oldCurAnim
    end
    newCurAnim = oldCurAnim
end

function onUpdatePost(elapsed)
    if returnCurAnim() == "idle" then
        setProperty("alienarms.x", playerX - offsets.idle.x)
        setProperty("alienarms.y", playerY - offsets.idle.y)
        playAnim("alienarms", "idle", true, false)
    end

    canSeeArms = string.find(getProperty('boyfriend.animation.curAnim.name'),'miss')

    setProperty('alienarms.visible',canSeeArms == nil);
end