@name TowerDefense [FailCake Hati and Foton]
@inputs EGP:wirelink 
@outputs [E O]:entity Ready X Y Clean Once Ops Credits Timeout StartGame
@persist Music:array
@trigger all

runOnTick(1)

Ops = ops()
## Ops - Must Not Delete

EGP:egpText(9,"Expression2 Ops : " + Ops + " %",vec2(315,478))

if(duped() | first()){

EGP:egpClear()
    
E = entity()
O = owner()

Music[1,string]="ui/gamestartup8.mp3"
Music[2,string]="ui/gamestartup9.mp3"
Music[3,string]="ui/gamestartup6.mp3"

print("* Game is Preparing! *")

EGP:egpBox(1,vec2(250,250),vec2(110,110))
EGP:egpColor(1,vec(255,0,0)) 
EGP:egpText(2,"Press to Start",vec2(200,240)) 

Ready = 0 
Clean = 0    
}

X=EGP:egpCursor(O):x()
Y=EGP:egpCursor(O):y()
EGP:egpCircle(3,EGP:egpCursor(O),vec2(3,3)) 

if(Clean == 0 & Ready == 0){
   
if(O:keyUse() & X >= 194 & X <= 306 & Y >= 194 & Y <= 307){
EGP:egpColor(1,vec(0,255,0))  
E:soundPlay(100,100,"ui/duel_challenge.wav")
Clean = 1   
}
    
}

if(Clean){

## Clean the Original EGP
timer("hold",2000)
if(clk("hold")){
Ready = 1
Clean = 0
EGP:egpClear()
}
    
}

if(Ready){
## Spawn the New Menu EGP
if(Once == 0){
Once = 1    

E:soundPlay(1000,1000,Music[randint(1,Music:count()),string])

## BackGround ##
EGP:egpBox(1,vec2(10,10),vec2(1100,1000))
EGP:egpColor(1,vec(20,20,20))

EGP:egpRoundedBox(4,vec2(255,70),vec2(410,100))

EGP:egpText(2,"-- Tower Defense --",vec2(65,40))
EGP:egpColor(2,vec(1,1,1))
EGP:egpFont(2,"Arial",50)
EGP:egpColor(4,vec(90,90,90))

## Start ##
EGP:egpRoundedBox(5,vec2(250,220),vec2(200,80))
EGP:egpColor(5,vec(80,80,80))
EGP:egpText(7,"Start Game",vec2(185,205))
EGP:egpFont(7,"Arial",30)
EGP:egpColor(7,vec(1,1,1))
## Credits ##
EGP:egpRoundedBox(6,vec2(250,350),vec2(200,80))
EGP:egpColor(6,vec(80,80,80))
EGP:egpText(8,"Credits",vec2(205,335))
EGP:egpFont(8,"Arial",30)
EGP:egpColor(8,vec(1,1,1))

}
## CREDITS
if(X >= 150 & X <= 351 & Y >= 310 & Y <= 389 & Timeout == 0){
    
EGP:egpColor(6,vec(0,255,0))    

if(O:keyUse()){
Credits = 1 
Timeout =1
}

}else{
EGP:egpColor(6,vec(80,80,80))
}


## Game Start Button
if(X >= 150 & X <= 351 & Y >= 180 & Y <= 260){
    
EGP:egpColor(5,vec(0,255,0))    

if(O:keyUse()){
StartGame = 1
}

}else{
EGP:egpColor(5,vec(80,80,80))
}



if(Timeout){
timer("wait",800)
if(clk("wait")){
Timeout = 0    
stoptimer("wait")
}    
    
}

if(Credits){  
 
Credits = 0 
print("### Tower Defense Team ###")  
print("Made By :") 
print("FailCake")
print("[NO].:|Hatifnat|:.")
print("Foton_63rus")
print("##########################") 
}

   
}
