#TouhouDanmakufu[Stage]
#Title[EX-BROFIST]
#Text[OMEGAHD WAT]
#Player[FREE]
#ScriptVersion[2]

script_stage_main
{
    let bgm=GetCurrentScriptDirectory~"bgm.mp3";
    let bg_distance=0;
    let bg_img=GetCurrentScriptDirectory~"FIST.png";
    let bg_imgb=GetCurrentScriptDirectory~"img\white.png";
    let scbg=GetCurrentScriptDirectory~"img\scbg.png";
    let frame=0;
    let yb=0;
    let xb=0;
    let bros=0;
    let rot=0;
    let alpha=0;
    let life=1;
	#include_function ".\fist_replace.txt";
task FistBG(x, y){
    yield;
    let obj=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(obj, x, y);
    ObjEffect_SetTexture(obj, bg_img);
    ObjEffect_SetLayer(obj, 0);
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_CreateVertex(obj, 4);
    ObjEffect_SetVertexUV(obj, 0, 0, 0);
    ObjEffect_SetVertexUV(obj, 1, 256, 0);
    ObjEffect_SetVertexUV(obj, 2, 0, 416);
    ObjEffect_SetVertexUV(obj, 3, 256, 416);
    ObjEffect_SetVertexXY(obj, 0, -128, -208);
    ObjEffect_SetVertexXY(obj, 1, 128, -208);
    ObjEffect_SetVertexXY(obj, 2, -128, 208);
    ObjEffect_SetVertexXY(obj, 3, 128, 208);
    ascent(i in 0..4){ObjEffect_SetVertexColor(obj, i, 194, 255, 255, 255);}
    while(Obj_BeDeleted(obj)==false){
        y-=20;
        Obj_SetY(obj, y);
        if(y<GetClipMinX-200){Obj_Delete(obj);}
        yield;
    }
}
task scbgb{
    yield;
    let objb=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(objb, GetCenterX, GetCenterY);
    ObjEffect_SetTexture(objb, bg_imgb);
    ObjEffect_SetLayer(objb, 1);
    ObjEffect_SetPrimitiveType(objb, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_CreateVertex(objb, 4);
    ObjEffect_SetVertexUV(objb, 0, 0, 0);
    ObjEffect_SetVertexUV(objb, 1, 384, 0);
    ObjEffect_SetVertexUV(objb, 2, 0, 448);
    ObjEffect_SetVertexUV(objb, 3, 384, 448);
    ObjEffect_SetVertexXY(objb, 0, -192, -224);
    ObjEffect_SetVertexXY(objb, 1, 192, -224);
    ObjEffect_SetVertexXY(objb, 2, -192, 224);
    ObjEffect_SetVertexXY(objb, 3, 192, 224);
    let obj=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(obj, GetCenterX, GetCenterY);
    ObjEffect_SetTexture(obj, scbg);
    ObjEffect_SetLayer(obj, 1);
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_CreateVertex(obj, 4);
    ObjEffect_SetVertexUV(obj, 0, 0, 0);
    ObjEffect_SetVertexUV(obj, 1, 320, 0);
    ObjEffect_SetVertexUV(obj, 2, 0, 320);
    ObjEffect_SetVertexUV(obj, 3, 320, 320);
    ObjEffect_SetVertexXY(obj, 0, -160, -160);
    ObjEffect_SetVertexXY(obj, 1, 160, -160);
    ObjEffect_SetVertexXY(obj, 2, -160, 160);
    ObjEffect_SetVertexXY(obj, 3, 160, 160);
    ObjEffect_SetScale(obj, 1.5, 1.5);
    while(Obj_BeDeleted(obj)==false){
        ascent(i in 0..4){ObjEffect_SetVertexColor(obj, i, alpha, 255, 255, 255);}
        ObjEffect_SetAngle(obj, 0, 0, rot);
        ascent(i in 0..4){ObjEffect_SetVertexColor(objb, i, alpha, 1, 1, 1);}
        yield;
    }
}
task stage
{
	PlayMusic(bgm);
    yield;
    bros=1;
	loop(60){yield;}
    initmeh;
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"ExFist.txt", GetCenterX, GetClipMinY-20, 0, 0, 0);
	yield;
	while(GetEnemyNum!=0){yield;}
	loop(60){yield;}
	Clear;
}
   @Initialize
   {
	LoadGraphic(bg_img);
	LoadGraphic(bg_imgb);
	LoadGraphic(scbg);
	stage;
    SetCommonData("ONSPELL", "FALSE");
    scbgb;
    SetCommonData("NOMISSCOUNT", 0);
   }

   @MainLoop
   {
    frame++;
    if(frame%7==0 && bros==1){
        xb=rand(-50, 50);
        FistBG(GetCenterX+xb, GetClipMaxY+250);
        FistBG(GetClipMinX+75+xb, GetClipMaxY+230);
        FistBG(GetClipMaxX-75+xb, GetClipMaxY+230);
        FistBG(GetClipMinX-50+xb, GetClipMaxY+200);
        FistBG(GetClipMaxX+50+xb, GetClipMaxY+200);
    }
    rot+=0.5;
    if(GetCommonData("ONSPELL")=="TRUE"){
        if(alpha<198){alpha+=11;}
    }else{
        if(alpha>0){alpha-=11;}
    }
    if(GetCommonData("NOMISSCOUNT")%5==0){
        if(life==GetCommonData("NOMISSCOUNT")/5){
            ExtendPlayer(1);
            life++;
        }
    }
	yield;
   }

   @DrawLoop
   {
   }

   @BackGround
   {
        if(bros==1){
            SetTexture(bg_imgb);
            SetGraphicRect(0, 0, 384, 448);
            DrawGraphic(GetCenterX, GetCenterY);
        }
   }

   @Finalize
   {
   }
}
