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

script_enemy_main {

	#include_function ".\Sakuyainclude.txt";
	let i = 0;
	let wp = 0;
	let one = 0;
	let color = 0;
	let acc = 1;
	let anim3 = 0;
	let color = 0;
	let x = 0;
let y = 0;
let one = 0;
let spd = 0;
let slowed = false;
let slow = 0;
let randx = 0;
let randy = 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(charge2);
	LoadSE(die);
	LoadGraphic(background);
	SetTimer(199);
	MagicCircle(false);
	SetEnemyMarker(true);
	SetInvincibility(210);
	SetDamageRate(50, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(90, 90, 90, 20);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(dream);
	LoadSE(die);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	SetCommonData("lastattack", false);
	
	}

task DelayedStart {
let radius = 30;
SetCommonData("spells", GetCommonDataDefault("spells", 0)+1);
wait(70);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Maid Skill "\""Silver Convergence"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
Spell;
//Shiny;
SetTimer(57);
}


task Spell{
wait(60);
loop{
wait(60);
Concentration01(60);
PlaySE(charge2);
SetAction(ACT_SHOT_A, 60);
wait(60);
ascent(i in 0..12){
	loop(20){
		CreateHater(GetX, GetY, 0.25+(i/3.5), angle+(i*(360/20/2)), BLUE32, 10);
		angle+=360/20;
		}
	}
wait(75);
Concentration01(60);
PlaySE(charge2);
wait(45);
SetAction(ACT_SHOT_B, 75);
TimeStopped = true;
PlaySE(timestop);
TimeStop(105, 1, 1, 0);
SetCommonData("spin", true);
wait(1);
SetCommonData("spin", false);
wait(104);
TimeStopped = false;
wait(120);
Concentration01(60);
PlaySE(charge2);
wait(45);
SetAction(ACT_SHOT_B, 75);
TimeStopped = true;
PlaySE(timestop);
TimeStop(105, 1, 1, 0);
SetCommonData("spin2", true);
wait(1);
SetCommonData("spin2", false);
wait(104);
TimeStopped = false;
wait(30);
ExMove;
}
}

task CreateHater(x, y, v, angle, graphic, delay){
	let speed = v;
	let tasking = true;
	let variable = 0;
	let turnacc = 0;
	let normalangle = 0;
	let spinning = 0;
	let angletoplayer = 0;
	let distancetoturn = 0;
	let thisangle = NormalizeAngle(angle);
	let initialangle = NormalizeAngle(angle);
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetAutoDelete(obj, true);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, v);
	Obj_SetAngle(obj, angle);
	ObjShot_SetBombResist(obj, true);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(obj) && tasking==true){
	

	if(GetCommonDataDefault("spin", false)==true){
	Obj_SetSpeed(obj, 0);
	
	angletoplayer = NormalizeAngle(atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
	normalangle = NormalizeAngle(Obj_GetAngle(obj));
	distancetoturn = normalangle-angletoplayer;
	turnacc = distancetoturn/45;
	loop(45){
	Obj_SetAngle(obj, Obj_GetAngle(obj)-turnacc);
	wait(1);
	}
	wait(60);
	Obj_SetSpeed(obj, -0.5);
	loop(90){
	Obj_SetSpeed(obj, Obj_GetSpeed(obj)+2.5/120);
	wait(1);
	}
	wait(30);
	}
	
	if(GetCommonDataDefault("spin2", false)==true){
	tasking = false;
	Obj_SetSpeed(obj, 0);
	normalangle = NormalizeAngle(Obj_GetAngle(obj));
	distancetoturn = normalangle-initialangle;
	turnacc = distancetoturn/45;
	loop(45){
	Obj_SetAngle(obj, Obj_GetAngle(obj)-turnacc);
	wait(1);
	}
	wait(60);
	Obj_SetSpeed(obj, -0.5);
	loop(90){
	Obj_SetSpeed(obj, Obj_GetSpeed(obj)+2.5/120);
	wait(1);
	}
	}
yield;
}	

}


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





	
}

