@name Ocean
@persist Bubbles:array
@inputs Scr:wirelink 
@persist Filling CurFil Inverted Color:vector Blocks BColor:vector
@persist Colors Raintick ID1
@trigger all
#@model models/props/radio_reference.mdl
#By Scriptis
if (duped()) {reset()}
if (first() | changed(Scr)) {Scr:egpClear() Filling=1 CurFil=0}
interval(1000/(egpMaxUmsgPerSecond()-2))
if (Filling) {
if (first() | changed(Scr)) {
    ID1=200
    Colors=24
    soundPurge()
    Scr:entity():soundPlay(1,0,"/ambient/water/water_flow_loop1.wav")
    #Scr:entity():setMaterial("models/shiny")
    #Scr:entity():setColor(vec(256,256,256))
    Scr:egpClear()
    #entity():setAlpha(0)
    Scr:egpBox(200,vec2(256,256),vec2(512,512))
    #Scr:egpMaterial(200,"maps/noicon")

    ##########################
    Blocks=100
    Inverted=1
    Color=vec(0,0,256)
    BColor=vec(256,256,256)
    ##########################
    Scr:egpBox(201,vec2(256,256),vec2(20,512))
    Scr:egpColor(201,Color)
    Scr:egpBox(202,vec2(256,0),vec2(50,30))
    Scr:egpColor(202,vec(128,128,128))
    Scr:egpText(203,"OCEANOS",vec2(256,256))
    Scr:egpColor(203,vec(256*100,256*100,0))
    Scr:egpSize(203,50)
    Scr:egpAlign(203,1,1)
    Scr:egpText(204,"Made by Scriptis",vec2(256,290))
    Scr:egpAlign(204,1,1)
    Scr:egpColor(204,vec(Color:z(),Color:y(),Color:x()))

    
}


if (clk("Filling")) {
    CurFil++
    if (!Inverted) {
        Pos=vec2(256,((256/Blocks)+((512/Blocks)/2))*CurFil)
    } else {
            Pos=vec2(256,512-(((256/Blocks)+((512/Blocks)/2))*CurFil))
    
}
        C=Color*(CurFil/Blocks)
        Scr:egpBox(CurFil,Pos,vec2(512,512/Blocks+3))
        Scr:egpColor(CurFil,C)
        if (CurFil==Blocks) {
            soundStop(1)
            Filling=0
            Scr:egpAlpha(201,0)
            soundPlay(0,0,"/ambient/water/lake_water.wav")
        }
    
}
timer("Filling",100)
} else {
#Create new bubble
if (randint(1,50)==5) {
    if (ID1>egpMaxObjects()) {
        ID1=200
    }
    ID1=ID1+2
    ID2=ID1-1
    Bubbles[Bubbles:count()+1,vector2]=vec2(ID2,ID1)
    Size=randint(5,20)
    Scr:egpCircle(ID1,vec2(randint(1,512),550),vec2(Size,Size))
    Scr:egpCircle(ID2,Scr:egpPos(ID1),vec2(Size-2,Size-2))
    Scr:egpColor(ID1,BColor)
    Scr:egpColor(ID2,BColor*0.9)
    #print("Making new bubble")
    
}
if (clk("Up")) {
    Raintick++
for (I=1, Bubbles:count()) {
    if (Bubbles[I,vector2]:x()) {
    ID1=Bubbles[I,vector2]:x()
    ID2=Bubbles[I,vector2]:y()
    Pos=Scr:egpPos(ID1)
    Pos=Pos-vec2(randint(-3,3),randint(3,7))
    Scr:egpPos(ID1,Pos)
    Scr:egpPos(ID2,Pos)
    if (Pos:y()<0) {
        Scr:egpAlpha(ID1,0)
        Scr:egpAlpha(ID2,0)
        #Scr:egpRemove(ID1)
        #Scr:egpRemove(ID2)
        Bubbles[I,vector2]=vec2(0,0)
    }
}
}
}
timer("Up",200)
}
#Color=Color=hsv2rgb((360/Colors)*Raintick,1,1)
