#TouhouDanmakufu
#Title[SakuyaS3_N]
#Text[SakuyaS3_N]
#Player[FREE]
#ScriptVersion[2]
#BGM[.\mu\bgm.mp3]

script_enemy_main {

	#include_function ".\Sakuyainclude.txt";
	let i = 0;
	let one = 1;
	let anim3 = 0;
	let color = 0;
	let x = 0;
	let randnum = rand(-5, 30);
	let yy = 0;
	let y = 0;
	@Initialize{
	shotinit;
	LoadSE(time1);
	LoadGraphic(background);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(ping);
	LoadSE(shot);
	DelayedStart;
	LoadSE(shot2);
	LoadSE(die);
	LoadGraphic(background);
	SetTimer(99);
	SetEnemyMarker(true);
	SetInvincibility(270);
	SetDamageRate(25, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(10, 10, 10, 10);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(dream);
	LoadSE(die);
	LoadSE(poof);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	SetCommonData("lastattack", false);
	
	}

task DelayedStart {
let radius = 30;

wait(90);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Jugglery "\""Knife Fold"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
Spell1;
Spell2;
//Shiny;
SetTimer(62);
}


task Spell1{
wait(150);
SetAction(ACT_SHOT_B, 1000000);
loop{
if(TimeStopped==false){
PlaySE(shot3);
loop(16){
CreateShotA(1, GetX, GetY, 10);
SetShotDataA(1, 0, 2, angle, 0, -0.04, 0, BLUE31);
SetShotDataA(1, 45, 3, angle+(35*one), 0, -0.1, 0, NULL);
SetShotDataA(1, 90, 1.75, angle+(35*one)-180, 0, 0, 0, NULL);
FireShot(1);
CreateShotA(1, GetX, GetY, 10);
SetShotDataA(1, 0, 2, angle, 0, -0.04, 0, BLUE31);
SetShotDataA(1, 45, 3, angle+(35*one), 0, -0.1, 0, NULL);
SetShotDataA(1, 90, 1.25, angle+(90*one)-180, 0, 0, 0, NULL);
angle+=360/16;
FireShot(1);
}
}
one=one*-1;
angle+=rand(-200, 200);
wait(20);
}
}

task Spell2{
wait(180);
loop(10){
Deflation(GetClipMinX+x-25, GetClipMinY+10, 0, 90, PURPLE32, 60);
x+=(GetClipMaxX)/5.5;
}
x=0;
wait(150);
PlaySE(timestop);
TimeStopped=true;
timer2 = GetTimer;
TimeStop(120, 1, 1, 1);
loop(120){
wait(1);

}
TimeStopped=false;
wait(1);
DeleteEnemyShot(SHOT);
wait(30);
loop(2){
PlaySE(GetCurrentScriptDirectory~"sfx\caution.wav");
wait(60);
}
loop{
loop(10){
Deflation(GetClipMinX+x-25+randnum, GetClipMinY+10+randnum, 0, 90, PURPLE32, 60);
x+=(GetClipMaxX)/5.5;
}
x=0;
wait(30);

loop(10){
Deflation(GetClipMinX+10+randnum, GetClipMinY+yy-25+randnum, 0, 0, PURPLE32, 60);
yy+=(GetClipMaxY)/5.5;
}
yy=0;
wait(120);
Concentration01(30);
wait(30);
PlaySE(timestop);
TimeStopped=true;
timer2 = GetTimer;
TimeStop(120, 1, 1, 1);
wait(120);
TimeStopped=false;
wait(180);
randnum = rand(-5, 30);
}
}


task Deflation(x, y, v, angle, graphic, delay){
		let obj = Obj_Create(OBJ_SHOT);
		let f = 0;
		let rad = 0;
		
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, delay);
		Obj_SetAutoDelete(obj, true);
		ObjShot_SetBombResist(obj, true);
		while(!Obj_BeDeleted(obj)){
			while(TimeStopped==true){
			expand;
			yield;
			yield;
			f=10;
			}
			if(TimeStopped==false && f==10){
			Obj_Delete(obj);
			}
			yield;
		}
		
		task expand {
		CreateShot01(Obj_GetX(obj)+rad*cos(Obj_GetAngle(obj)), Obj_GetY(obj)+rad*sin(Obj_GetAngle(obj)), 3, Obj_GetAngle(obj), WHITE32, 0);
		
		CreateShot01(Obj_GetX(obj)-rad*cos(Obj_GetAngle(obj)), Obj_GetY(obj)-rad*sin(Obj_GetAngle(obj)), 3, Obj_GetAngle(obj), WHITE32, 0);
		rad+=20;
		}
		
		}
	
	


    @BackGround{
	 SetTexture(background);
   SetGraphicRect(0, 0, 256, 256);
   SetGraphicScale(2.5, 2.5);
   SetGraphicAngle(0, 0, y);
   DrawGraphic(GetCenterX, GetCenterY);
	if(TimeStopped!=true){
   y+=1;
	}
	SetGraphicAngle(0, 0, 0);
	}





	
}

