#TouhouDanmakufu
#Title[Bro Sign "Fist Missile"]
#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{
    PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");
    Concentration01(60);
    loop(60){yield;}
    ascent(i in -2..3){
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        Fist(GetAngleToPlayer+i*60);
        loop(20){yield;}
    }
    loop(500){yield;}
    SetMovePosition02(GetPlayerX+rand(-50, 50), GetClipMinY+rand(50, 120), 40);
    attack;
}
task Fist(angle){
    let counter=0;
    let obj=Obj_Create(OBJ_SHOT);
    Obj_SetPosition(obj, GetX, GetY);
    Obj_SetSpeed(obj, 5);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, RED04);
    ObjShot_SetDelay(obj, 0);
    ObjShot_SetBombResist(obj, true);
    while(Obj_BeDeleted(obj)==false){
        if(Obj_GetSpeed(obj)>=2){
            if(Obj_GetX(obj)>GetClipMaxX+30 || Obj_GetX(obj)<GetClipMinX-30){Obj_SetAngle(obj, 180-Obj_GetAngle(obj)); Obj_SetSpeed(obj, Obj_GetSpeed(obj)-1); counter=0;}
            if(Obj_GetY(obj)>GetClipMaxY+30 || Obj_GetY(obj)<GetClipMinY-30){Obj_SetAngle(obj, 0-Obj_GetAngle(obj)); Obj_SetSpeed(obj, Obj_GetSpeed(obj)-1); counter=0;}
        }
        if(counter==70-(Obj_GetSpeed(obj)*12)){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 3, Obj_GetAngle(obj)+90, RED02, 10);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 3, Obj_GetAngle(obj)-90, RED02, 10);
            counter=0;
        }else{
            counter++;
        }
        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 Missile''",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==90){attack;}
}
	
	@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
	{
	}
}