@name Holo_Piano
@inputs 
@outputs 
@persist [E O]:entity R:array Count Hit Index
@trigger

interval(20)

# Number of keys
#=====================================================
Count = 20

if (first() | duped())
{
    E = entity()
    O = owner()
    
    for (I = 1,clamp(Count,0,30))
    {
        holoCreate(I,E:toWorld(vec((I*50)-20,0,0)),vec(4,4,0.5),E:angles())
        holoMaterial(I,"models/shiny")
        holoParent(I,E)
    }
}

for (I = 1,clamp(Count,0,30))
{
    if (O:aimPos():distance(holoEntity(I):pos()) < 25 & O:keyAttack1())
    {
        if (holoEntity(I):getColor() != vec(0,255,0))
        {
            holoColor(I,vec(0,255,0))
            Hit = I
            timer("Play",10)
        }
        
    }
    else
    {
        if (holoEntity(I):getColor() != vec(255,255,255))
        {
            holoEntity(I):setColor(255,255,255)
        }
    }
}

if (clk("Play"))
{
    Index = Index % 9 + 1
    holoEntity(Hit):soundPlay(Index,0.5,"synth/sine.wav")
    holoEntity(Hit):soundPlay(Index+1,0.5,"synth/tri.wav")
    soundPitch(Index,Hit*(250/Count))
    soundPitch(Index+1,Hit*(250/Count))
}