 #TouhouDanmakufu
#Title[SakuyaS1_H]
#Text[SakuyaS1_H]
#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(35, 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("Ex Nihilo "\""Killing Doll's Accomplices"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
Spell;
//Shiny;
SetTimer(47);
}


task Spell{
wait(60);
loop{
wait(60);
Concentration01(60);
PlaySE(charge2);
wait(45);
SetAction(ACT_SHOT_B, 120);
wait(15);
Slow(4);
slowed = true;
//MotionBlur(ALL, 45, 40);
wait(15);
PlaySE(ping);
ascent(i in 0..15){
	
	ascent(c in -20..50){
	color+=rand_int(1, 2);
	randx = rand(-4, 4);
	randy = rand(-2, 2);
		if(GetDistance(GetPlayerX, GetPlayerY, (GetClipMinX-50+(randx*2))+(c*34)+randx, GetClipMinY-60+(i*37)+(randy*2))>=30){ 
		CreateShotA(1, (GetClipMinX-50+(randx*2))+(c*34)+randx, GetClipMinY-60+(i*37)+(randy*2), 2);
		SetShotDataA(1, 0, 0, wp+90+(randy*4), 0, 0.001, 1.1, [BLUE31, PURPLE31, WHITE31][color%3]);
		SetShotDataA(1, 120, NULL, NULL, 0, 0.003, 1.75+rand(randy/20, -randy/20), NULL);
		FireShot(1);
		CreateShotA(1, (GetClipMinX-50+(randx*2))+(c*34)+randx, GetClipMinY-60+(i*37)+(randy*2), 2);
		SetShotDataA(1, 0, 0, wp+-90-(randy*4), 0, 0.001, 1.1, [BLUE31, PURPLE31, WHITE31][color%3]);
		SetShotDataA(1, 120, NULL, NULL, 0, 0.003, 1.75+rand(randy/20, -randy/20), NULL);
		FireShot(1);
		}
	}
}
//DeleteEnemyShotImmediatelyInCircle(SHOT, GetPlayerX, GetPlayerY, 25);
wait(5);
Slow(3);
wait(5);
Slow(2);
wait(5);
Slow(1);
wait(5);
Slow(0);
slowed = false;
wait(120);
wp+=45;
Concentration01(60);
PlaySE(charge2);
wait(70);
SetAction(ACT_SHOT_A, 180);
spd = 0;
loop(90){
 loop(3){
	
	CreateKiller(GetX, GetY, 3+spd, angle, BLUE32, 10);
	angle+=360/3;
	}
angle+=7;
spd+=0.02082333333;
wait(2);
}
wait(15);

if(wp==90){
wp=-45;
}
wait(30);
}
	
}



task CreateWarningLaser(x, y, angle, graphic, delay){
	
	let obj = Obj_Create(OBJ_LASER);
	let time = 0;
	ObjLaser_SetSource(obj, false);
	Obj_SetPosition(obj, x, y);
	ObjLaser_SetLength(obj, 1000);
	ObjLaser_SetWidth(obj, 25);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(obj)){
	
	if(time>=delay){
	Obj_Delete(obj);
	}

	time++;
	
	yield;
	}
	
}

task CreateKiller(x, y, v, angle, graphic, delay){
	let speed = v;
	let spinning=3;
	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) && spinning==3){
	if(speed>=0 && spinning==3){
	speed-=0.06;
	}
	if(speed<0 && spinning==3){
	speed = 0;
	}
	if(speed==0 && spinning==3){
	spinning=2;
	}
	
	if(speed==0){
	CreateSpinner(Obj_GetX(obj), Obj_GetY(obj), angle);
	Obj_Delete(obj);
	}	
	Obj_SetSpeed(obj, speed);
	
	yield;
	}
	wait(15);
	
	
	
	


}
task CreateSpinner(x, y, angle){
	let speed = 0;
	let time = 0;
	let plangle = 0;
	let spinning=1;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetAutoDelete(obj, true);
	ObjShot_SetBombResist(obj, true);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, BLUE32);
	ObjShot_SetDelay(obj, 0);
	while(!Obj_BeDeleted(obj)){
	if(spinning==1){
	Obj_SetAngle(obj, Obj_GetAngle(obj)+(360/70));
	}
	if(time>=90&&spinning==1){
	spinning = 0;
	plangle = atan2(Obj_GetY(obj)-GetPlayerY, Obj_GetX(obj)-GetPlayerX)-180+rand(-0.5, 0.5);
	//CreateWarningLaser(Obj_GetX(obj), Obj_GetY(obj), plangle, BLUE60, 5);
	
	Obj_SetAngle(obj, plangle);
	
	}

	if(time>=60){
	speed+=0.0975;
	Obj_SetSpeed(obj, speed);
	}
	time++;
	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);
	}





	
}

