#TouhouDanmakufu
#Title[Bro Sign "Fist Onslaught"]
#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";
task attack{
    let x=0;
    PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");
    Concentration01(60);
    SetMovePosition02(GetCenterX, GetClipMinY-120, 30);
    loop(60){yield;}
    loop{
        x=GetPlayerX;
        loop(25){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            ascent(i in -4..4){
                if(i!=0){
                    shot(x+i*100+rand(-20, 20), rand(GetClipMinY-120, 0), rand_int(0, 200));
                }
            }
            loop(5){yield;}
        }
        loop(50){yield;}
        PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");   
        loop(60){yield;}
    }
}
task shot(x, y, count){
    let obj=Obj_Create(OBJ_SHOT);
    Obj_SetPosition(obj, x, y);
    Obj_SetAngle(obj, 90);
    Obj_SetSpeed(obj, rand(10, 13));
    ObjShot_SetGraphic(obj, ORIG05);
    while(Obj_BeDeleted(obj)==false){
        SetCollisionA(Obj_GetX(obj), Obj_GetY(obj), 30);
        count++;
        if(count%200==0){
            ascent(i in 0..4){
                CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, Obj_GetAngle(obj)+i*90, RED01, 10);
            }
        }
        yield;
    }
}
task bossgraphic{
    yield;
    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, GetY-121);
        ObjEffect_SetAngle(obj, 0, 0, 180);
        yield;
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		LoadGraphic(BossCutIn);
		SetMovePosition02(GetCenterX,120,20);
		CutIn(YOUMU, "Bro Sign ''Fist Onslaught''",BossCutIn,0,0,256,416);
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 5400);
        bossgraphic;
        SetCommonData("ONSPELL", "TRUE");
        if(GetCommonDataDefault("NOMISSCOUNT", -1)==-1){
            initmeh;
        }
	}
	
	@MainLoop
	{
        SetShotAutoDeleteClip(300, 300, 300, 300);
        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==90){attack;}
}
	
	@Finalize
	{
        SetCommonData("ONSPELL", "FALSE");
        SetShotAutoDeleteClip(32, 32, 32, 32);
		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
	{
	}
}