#TouhouDanmakufu
#Title[Fist Sign "Brofist Smash"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=0;
    let BossCutIn=GetCurrentScriptDirectory~"FIST.png";
	#include_function ".\spellcard.txt";
	#include_function ".\fist_replace.txt";
    let smashing=0;
    let type=1;
    let anglec=0;
    let distx=0;
    
task smash{
    Concentration01(60);
    loop(60){yield;}
    smashing=1;
    SetMovePositionHermite(GetClipMinX, GetCenterY, 200, 270, 200, 0, 60);
    loop(80){yield;}
    SetMovePositionHermite(GetPlayerX, GetCenterY-50, 400, -45, 400, 135, 50);
    loop(50){yield;}
    SetMovePosition02(GetX, GetClipMaxY, 10);
    loop(10){yield;}
    explode;
    loop(30){yield;}
    
    loop{
        smashing=-1;
        SetMovePosition02(GetCenterX, GetClipMinY+120, 60);
        Concentration01(60);
        loop(60){yield;}
        SetMovePositionHermite(GetClipMaxX+200, GetCenterY, 200, 270, 200, 180, 60);
        loop(60){yield;}
        type=2;
        smashing=2;
        SetMovePosition02(GetClipMaxX, GetCenterY, 10);
        loop(30){yield;}
        SetMovePositionHermite(GetPlayerX, GetCenterY-50, 400, 225, 400, 45, 50);
        loop(50){yield;}
        SetMovePosition02(GetX, GetClipMaxY, 10);
        loop(10){yield;}
        explode;
        loop(30){yield;}
        smashing=-2;
        SetMovePosition02(GetCenterX, GetClipMinY+120, 60);
        Concentration01(60);
        loop(60){yield;}
        SetMovePositionHermite(GetClipMinX-200, GetCenterY, 200, 270, 200, 0, 60);
        loop(60){yield;}
        type=1;
        smashing=1;
        SetMovePosition02(GetClipMinX, GetCenterY, 10);
        loop(30){yield;}
        SetMovePositionHermite(GetPlayerX, GetCenterY-50, 400, -45, 400, 135, 50);
        loop(50){yield;}
        SetMovePosition02(GetX, GetClipMaxY, 10);
        loop(10){yield;}
        explode;
        loop(30){yield;}
    }
}
task explode{
    PlaySE(GetCurrentScriptDirectory~"sound\Shot2.wav");
    loop(5){
        ascent(i in -9..9){
            CreateShot12(GetX+i*10+rand(-5, 5), GetY, rand(-3, 3), rand(-2, -4), rand(-0.01, 0.01), rand(0.01, 0.03), rand(-3, 3), rand(2, 4), RED01, 0);
        }
    }
}
task bossgraphic{
    yield;
    let angle=0;
    let angleb=0;
    let obj=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(obj, GetX, GetY);
    ObjEffect_SetTexture(obj, BossCutIn);
    ObjEffect_SetLayer(obj, 4);
    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, 255, 255, 255, 255);}
    while(Obj_BeDeleted(obj)==false){
        Obj_SetPosition(obj, GetX+121*cos(angle-90), GetY+121*sin(angle-90));
        if(smashing==1){if(angle>-90){angle-=1.5;}}
        if(smashing==-1){if(angle<0){angle+=1.5;}}
        if(smashing==2){if(angle<90){angle+=1.5;}}
        if(smashing==-2){if(angle>0){angle-=1.5;}}
        if(type==1){angleb=0;}else{angleb=1;}
        ObjEffect_SetAngle(obj, angleb*180, 0, 180+angle);
        yield;
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		LoadGraphic(BossCutIn);
		SetMovePosition02(GetCenterX,120,20);
		CutIn(YOUMU, "Fist Sign ''Brofist Smash''",BossCutIn,0,0,256,416);
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 5400);
        bossgraphic;
        SetCommonData("ONSPELL", "TRUE");
        if(GetCommonDataDefault("NOMISSCOUNT", -1)==-1){
            initmeh;
        }
	}
	
	@MainLoop
	{
        if(OnBomb==true){SetDamageRate(0, 0);}else{SetDamageRate(10+floor(30-30*GetCommonData("timercount")/5400),5);}
		SetCollisionA(GetX(),GetY(),75);
		SetCollisionB(GetX(),GetY(),75);
		frame++;
		yield;
        if(frame==30){smash;}
        if(frame>150 && frame%50==0){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            anglec=rand(-10, 10);
            distx=rand(-30, 30);
            ascent(i in 0..7){
                CreateShot01(GetClipMinX+384/6*i+distx, GetClipMinY-15, 2, 90+anglec, YELLOW01, 0);
            }
        }
}
	
	@Finalize
	{
        SetCommonData("ONSPELL", "FALSE");
		AddScore(spellbonustotal);
		if(spellbonustotal>0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\se_cardget.wav");
		loop(50)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}else{
		loop(15)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}
		 
        if(GetMissCountInThisSpell==0){
            SetCommonData("NOMISSCOUNT", GetCommonData("NOMISSCOUNT")+1);
        }
	}
	
	@DrawLoop
	{
	}
}