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

script_enemy_main
{
	let frame=0;
    let angle=[];
    let angleb=0;
    let BossCutIn=GetCurrentScriptDirectory~"FIST.png";
	#include_function ".\spellcard.txt";
	#include_function ".\fist_replace.txt";

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-121*cos(GetAngle), GetY-121*sin(GetAngle));
        ObjEffect_SetAngle(obj, 0, 0, 90+GetAngle);
        yield;
    }
}
task movement{
    angle=[ [GetX, GetY], [GetX, GetY] ];
    angleb=90;
    attack;
    loop{
        angleb-=2;
        SetX(GetCenterX+167*cos(angleb));
        SetY(GetClipMinX+120+50*sin(angleb*2));
        angle=erase(angle, 0);
        angle=angle~[ [GetX, GetY] ];
        SetAngle(atan2(angle[1][1]-angle[0][1], angle[1][0]-angle[0][0]));
        yield;
    }
}
task attack{
    let anglec=0;
    loop{
        anglec=rand(0, 359);
        ascent(i in 0..5){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            CreateShot12(GetX+40*cos(anglec+i*72), GetY+40*sin(anglec+i*72), rand(-3, 3), rand(-1, -3), rand(-0.01, 0.01),
                rand(0.01, 0.03), rand(-3, 3), rand(2, 4), RED01, 0);
            CreateShot12(GetX+40*cos(anglec+i*72), GetY+40*sin(anglec+i*72), rand(-3, 3), rand(-1, -3), rand(-0.01, 0.01),
                rand(0.01, 0.03), rand(-3, 3), rand(2, 4), RED01, 0);
            yield;
        }
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		LoadGraphic(BossCutIn);
		SetMovePosition02(GetCenterX,GetClipMinY+120,20);
		CutIn(YOUMU, "Fist Sign ''Smashing Rain''",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){movement;}
}
	
	@Finalize
	{
		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
	{
	}
}