#TouhouDanmakufu
#Title["Sleep for the Insomniacs"]
#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\face04ct.png";
	#include_function ".\satorianim.txt";
task thing{
    let x=0;
    let y=0;
    let angle=rand(0, 359);
    while(x<GetClipMaxX-GetClipMinX){
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        CreateShotA(1, GetClipMinX+x+40*cos(angle), GetClipMinY+y+40*sin(angle), 20);
        SetShotDataA(1, 0, 0, angle*1.5, 0, 0, 0, 47);
        SetShotDataA(1, 30, 2.5, angle*1.5, 0, 0, 0, 47);
        FireShot(1);
        CreateShotA(1, GetClipMaxX-x-40*cos(angle), GetClipMinY+y+40*sin(angle), 20);
        SetShotDataA(1, 0, 0, 180-angle*1.5, 0, 0, 0, 47);
        SetShotDataA(1, 30, 2.5, 180-angle*1.5, 0, 0, 0, 47);
        FireShot(1);
        x+=2;
        y++;
        angle+=7;
        yield;
    }
    thing;
}
task thingb{
    let angle=0;
    loop{
        CreateShotA(1, GetX+100*cos(angle), GetY+100*sin(angle*2), 20);
        SetShotDataA(1, 0, 0, angle*1.5, 0, 0, 0, 47);
        SetShotDataA(1, 30, 2.5, angle*1.5, 0, 0, 0, 47);
        FireShot(1);
        CreateShotA(1, GetX+100*cos(angle+180), GetY+100*sin(angle*2+180), 20);
        SetShotDataA(1, 0, 0, angle*1.5, 0, 0, 0, 47);
        SetShotDataA(1, 30, 2.5, angle*1.5, 0, 0, 0, 47);
        FireShot(1);
        angle-=3;
        yield;
    }
}
task sounds{
    loop{
        PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
        yield;
    }
}
task rings{
    let angle=rand(0, 359);
    loop{
        angle=rand(0, 359);
        ascent(i in 0..20){
            CreateShot01(GetX, GetY, 4, angle+i*18, 227, 20);
        }
    loop(15){yield;}
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
        LoadGraphic(cutin);

		SetMovePosition02(GetCenterX,GetCenterY-100,20);
		Concentration01(150);
		CutIn(YOUMU, "''Sleep for the Insomniacs''",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(),24);
		frame++;
		yield;
        if(frame==100){thing;}
        if(frame==150){sounds;}
        if(frame==200){thingb;}
        if(frame==400){SetMovePosition01(GetPlayerX+rand(-50, 50), GetClipMinY+rand(50, 120), 2); frame=201;}
        if(frame==200){rings;}
}
	
	@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;
        anim2;
	}
}