#TouhouDanmakufu
#Title["Guiltless Pleasure"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\spellcard.txt";
	let type=0;
	let frame=0;
    let cutin=GetCurrentScriptDirectory~"img\face07ct.png";
	#include_function ".\koishianim.txt";
    
task shot(x, y, angle, v){
    let counter=0;
    let counterb=0;
    let obj=Obj_Create(OBJ_SHOT);
    Obj_SetPosition(obj, x, y);
    Obj_SetSpeed(obj, v);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, 249);
    ObjShot_SetDelay(obj, 20);
    while(Obj_BeDeleted(obj)==false){
        yield;
        if(counter<=1){
            if(Obj_GetX(obj)>GetClipMaxX+5||Obj_GetX(obj)<GetClipMinX-5){PlaySEWave; Obj_SetAngle(obj, 180-Obj_GetAngle(obj)); counter++;}
            if(Obj_GetY(obj)>GetClipMaxY+5||Obj_GetY(obj)<GetClipMinY-5){PlaySEWave; Obj_SetAngle(obj, 0-Obj_GetAngle(obj)); counter++;}
        }
        counterb++;
        if(counterb%1==0){
            CreateShotA(1, Obj_GetX(obj)+rand(-5, 5), Obj_GetY(obj)+rand(-5, 5), 0);
            SetShotDataA(1, 0, rand(0.2, 0.5), Obj_GetAngle(obj)+rand(0, 359), 0, 0, 0, 239);
            SetShotKillTime(1, 15);
            FireShot(1);
            CreateShotA(1, Obj_GetX(obj)+rand(-5, 5), Obj_GetY(obj)+rand(-5, 5), 0);
            SetShotDataA(1, 0, rand(0.2, 0.5), Obj_GetAngle(obj)+rand(0, 359), 0, 0, 0, 240);
            SetShotKillTime(1, 15);
            FireShot(1);
        }
    }
}

sub PlaySEWave{
    PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
        LoadGraphic(cutin);

		SetMovePosition02(GetCenterX,GetCenterY-100,20);
		Concentration01(150);
		CutIn(YOUMU, "''Guiltless Pleasure''",cutin,0,0,256,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 60*120);
        lastspell;
        PlayMusic(GetCurrentScriptDirectory~"bgm.mp3");
	}
	
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),12);
		frame++;
		yield;
        if(frame>150 && frame%75==0){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            shot(GetClipMinX, GetClipMinY, atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX), 6);
            shot(GetClipMaxX, GetClipMinY, atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX), 6);
            shot(GetClipMinX, GetClipMaxY, atan2(GetPlayerY-GetClipMaxY, GetPlayerX-GetClipMinX), 6);
            shot(GetClipMaxX, GetClipMaxY, atan2(GetPlayerY-GetClipMaxY, GetPlayerX-GetClipMaxX), 6);
            shot(GetClipMinX, GetClipMinY, atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX), 3);
            shot(GetClipMaxX, GetClipMinY, atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX), 3);
            shot(GetClipMinX, GetClipMaxY, atan2(GetPlayerY-GetClipMaxY, GetPlayerX-GetClipMinX), 3);
            shot(GetClipMaxX, GetClipMaxY, atan2(GetPlayerY-GetClipMaxY, GetPlayerX-GetClipMaxX), 3);
        }
}
	
	@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));
		}
		}
		SetCommonData("ONSPELL", "FALSE");
        if(spellbonustotal==0){SetCommonData("REDO", "TRUE");}
	}
	
	@DrawLoop
	{
        bg;
        if(type==0){anim2;}else{animcast;}
	}
}