@name 
@inputs INPUT:entity E:wirelink
@outputs 
@persist G:entity TT Dir JJ DOWN DEBUG Started Coor Same RST
@trigger 
if(first()){
    stoptimer("start")
stoptimer("start2")
stoptimer("start3")
stoptimer("start4")
stoptimer("start5")
stoptimer("spawn")
    Same = 1
    RST = 0
    Started = 0
    DEBUG = 0
    DOWN = 0
    JJ=50
    E:egpClear()
    ####################POS########SIZE####
    E:egpText(1,"-->",vec2(20,400))
    E:egpSize(1,80)
    E:egpText(2,"^",vec2(160,400))
    E:egpSize(2,80)
        E:egpText(3,"<--",vec2(260,400))
    E:egpSize(3,80)
            E:egpText(4,"V",vec2(420,400))
    E:egpSize(4,80)
    E:egpColor(1,vec(255,0,0))
    E:egpColor(2,vec(0,255,0))
    E:egpColor(3,vec(0,0,255))
    E:egpColor(4,vec(255,0,255))
    E:egpBox(5,vec2(300,450),vec2(800,130))
    E:egpColor(5,vec4(255,255,255,30))
    E:egpBox(6,vec2(75,300),vec2(130,800))
    E:egpColor(6,vec4(255,0,0,30))
        E:egpBox(7,vec2(200,300),vec2(120,800))
    E:egpColor(7,vec4(0,255,0,30))
            E:egpBox(8,vec2(320,300),vec2(120,800))
    E:egpColor(8,vec4(0,0,255,30))
                E:egpBox(9,vec2(440,300),vec2(120,800))
    E:egpColor(9,vec4(255,0,255,30))
TT=0}
if(changed(owner():keyPressed("h")) & owner():keyPressed("h")){
    TT++
    if(TT>1){
TT = 0}
}
if(TT==1){
    
    dPos("Control",vec2(egpScrW(owner())/50,egpScrH(owner())*50))
dPanel("Control",vec2(50,50),vec2(300,200))
dButton("Up","Control",vec2(120,50),vec2(30,30))
dButton("Down","Control",vec2(120,80),vec2(30,30))

dButton("Left","Control",vec2(90,80),vec2(30,30))
dButton("Right","Control",vec2(150,80),vec2(30,30))
enableMouse(1)
}

if(TT==0){
dPos("Menu",vec2(9999,9999))
enableMouse(0)
stoptimer("start")
stoptimer("start2")
stoptimer("start3")
stoptimer("start4")
stoptimer("start5")
stoptimer("spawn")
if(changed(TT)){
hint("Canceled!",5000)
}
}


runOnTick(1)
dPod(INPUT)
if(dClk("Up")){
if(E:egpPos(JJ):y() > 380){
    if(E:egpPos(JJ):y() < 420){
        stoptimer("down")
        E:egpRemove(JJ)
        hint("WIN!",1000)
      timer("spawn",100)
    DOWN = 0
}
}
}
if(dClk("Down")){
if(E:egpPos(JJ):y() > 380){
    if(E:egpPos(JJ):y() < 420){
        stoptimer("down")
        E:egpRemove(JJ)
        hint("WIN!",1000)
       timer("spawn",100)
    DOWN = 0
}
}
}
if(dClk("Left")){
if(E:egpPos(JJ):y() > 380){
    if(E:egpPos(JJ):y() < 420){
        stoptimer("down")
        E:egpRemove(JJ)
        hint("WIN!",1000)
 timer("spawn",100)
DOWN = 0
}
}
}
if(dClk("Right")){

if(E:egpPos(JJ):y() > 380){
    if(E:egpPos(JJ):y() < 420){
        stoptimer("down")
        E:egpRemove(JJ)
        hint("WIN!",1000)
       timer("spawn",100)  
    DOWN = 0
}
}
}


if(changed(TT) & TT==1){
    Started=1
    timer("start",1000)
    print(_HUD_PRINTCENTER,"Starting in: 5")
}
if(clk("start")){
    timer("start2",1000)
    print(_HUD_PRINTCENTER,"Starting in: 4")
}
if(clk("start2")){
    timer("start3",1000)
    print(_HUD_PRINTCENTER,"Starting in: 3")
}

if(clk("start3")){
    timer("start4",1000)
    print(_HUD_PRINTCENTER,"Starting in: 2")
}
if(clk("start4")){
    timer("start5",1000)
    print(_HUD_PRINTCENTER,"Starting in: 1")
}
if(clk("start5")){
    print(_HUD_PRINTCENTER,"START!")
    
    timer("spawn",randint(2000,4000))
}
if(clk("spawn")){
    if(DEBUG==0){
Dir = randint(1,4)
JJ++
print(Dir)

}
}
if(clk("spawn")){
    if(DEBUG==1){
Dir = 1
JJ = JJ + 5
#print(Dir)

}
}

if(changed(Dir) & Dir==1){
    if(changed(JJ)){
    E:egpText(JJ,"-->",vec2(20,0))
    E:egpSize(JJ,80)
            timer("down",1)
Coor = 20
}}
if(changed(Dir) & Dir==2){
    if(changed(JJ)){
    E:egpText(JJ,"^",vec2(20,0))
    E:egpSize(JJ,80)
            timer("down",1)
Coor = 160
}}
if(changed(Dir) & Dir==3){
    if(changed(JJ)){
    E:egpText(JJ,"<--",vec2(20,0))
    E:egpSize(JJ,80)
            timer("down",1)
Coor = 260
}}
if(changed(Dir) & Dir==4){
    if(changed(JJ)){
        if(Same==1){
    E:egpText(JJ,"V",vec2(20,0))
    E:egpSize(JJ,80)
            timer("down",1)
Coor = 420
}}}
    E:egpPos(JJ,vec2(Coor,DOWN))
if(clk("down")){
 #   print(E:egpPos(JJ):y())
    DOWN = DOWN +40
    Same = 0
    timer("down",200)
    if(E:egpPos(JJ):y()>=440){
        E:egpRemove(JJ)
        JJ++
       hint("fail",1000)
    
        DOWN = 0
        timer("spawn",100)
        stoptimer("down")
    }
}
