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

script_enemy_main
{
	let frame=0;
    let clawhit=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;}
    PlaySE(GetCurrentScriptDirectory~"sound\Laser1.wav");
    claw(-40);
    claw(40);
    claw(0);
    loop(100){yield;}
    loop{
        SetMovePosition02(GetPlayerX, GetClipMinY+50+rand(-20, 50), 30);
        PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");
        loop(60){yield;}
        PlaySE(GetCurrentScriptDirectory~"sound\se_slash.wav");
        SetSpeed(12);
        SetAngle(90);
        while(GetY<GetClipMaxY+100){yield; clawhit=1;}
        clawhit=0;
        SetSpeed(0);
        shots;
        loop(80){yield;}
    }
}
task claw(x){
    let obj=Obj_Create(OBJ_LASER);
    Obj_SetPosition(obj, GetX+x, GetY+30);
    Obj_SetAngle(obj, 90);
    ObjShot_SetGraphic(obj, WHITE05);
    ObjLaser_SetWidth(obj, 20);
    ObjLaser_SetLength(obj, 0);
    ObjLaser_SetSource(obj, false);
    while(Obj_BeDeleted(obj)==false){
        if(ObjLaser_GetLength(obj)<200){ObjLaser_SetLength(obj, ObjLaser_GetLength(obj)+2);}
        Obj_SetPosition(obj, GetX+x, GetY+30);
        if(clawhit==1){Obj_SetCollisionToPlayer(obj, true);}else{Obj_SetCollisionToPlayer(obj, false);}
        yield;
    }
}
task shots{
    ascent(i in -1..13){
        PlaySE(GetCurrentScriptDirectory~"sound/Shot1.wav");
        CreateShot01(GetX, GetClipMinY+25+i*35, 2, 0, RED01, 5);
        CreateShot01(GetX, GetClipMinY+25+i*35, 2, 180, RED01, 5);
        CreateShot01(GetX-40, GetClipMinY+25+i*35-10, 2, 0, RED01, 5);
        CreateShot01(GetX-40, GetClipMinY+25+i*35-10, 2, 180, RED01, 5);
        CreateShot01(GetX+40, GetClipMinY+25+i*35-10, 2, 0, RED01, 5);
        CreateShot01(GetX+40, GetClipMinY+25+i*35-10, 2, 180, RED01, 5);
        yield;
        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, "Fist Sign ''The Claw''",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
	{
	}
}