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

script_enemy_main {

	#include_function ".\Sakuyainclude.txt";
	let i = 0;
	let wp = 0;
	let pp = -1;
	let one = 0;
	let a = 0;
	let playx = 0;
	let playy = 0;
	let color = 0;
	let acc = 1;
	let anim3 = 0;
	let color = 0;
	let angle2 = 0;
	let x = 0;
let y = 0;
let one = 0;
let spd = 0;
let firsttime = true;
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);
	SetX(GetClipMinX-20);
	SetY(GetClipMinY-50);
	DelayedStart;
	SetEffectForZeroLife(120, 125, 1);
	LoadSE(phase);
	LoadSE(shot2);
	LoadSE(charge2);
	MagicCircle(false);
	LoadSE(die);
	LoadGraphic(background);
	SetTimer(199);
	SetEnemyMarker(true);
	SetInvincibility(420);
	SetDamageRate(25, 25);
	SetMovePosition03(GetCenterX, GetClipMinY + 120, 20, 4);
	SetAction(ACT_MOVE, 200);
	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", true);
	}

task DelayedStart {
let radius = 30;
SetCommonData("spells", GetCommonDataDefault("spells", 0)+1);
wait(150);
Concentration01(120);
SetAction(ACT_SHOT_B, 90);
loop(3){
PlaySE(charge2);
wait(30);
}
wait(15);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin(" "\""Flos Mors (Death Lotus)"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
Spell;
SetTimer(120);
FamiliarSpawn1;
}


task Spell{
wait(120);
SetAction(ACT_SHOT_B, 120910291029);
loop(4){
	CreateEnemyFromScript("familiar1", GetX, GetY, 0, angle, angle);
	CreateEnemyFromScript("familiar2", GetX, GetY, 0, angle, angle);
	angle+=360/4;
	}
loop{


wait(1);

}
}


task FamiliarSpawn1{
wait(1);
while(GetEnemyLife>=1250 && GetTimer>100){
wait(1);
}
PlaySE(charge2);
Concentration01(30);
wait(30);
loop(3){
	CreateEnemyFromScript("familiar3", GetX, GetY, 0, angle, angle);
	angle+=360/3;
	}

while(GetEnemyLife>=950 && GetTimer>=80){
wait(1);
}
PlaySE(charge2);
Concentration01(30);
wait(30);
loop(3){
	CreateEnemyFromScript("familiar4", GetX, GetY, 0, angle, angle);
	angle+=360/3;
	}
while(GetEnemyLife>=650 && GetTimer>=60){
wait(1);
}
PlaySE(charge2);
Concentration01(30);
wait(30);
CreateEnemyFromScript("familiarhorizontal", GetX, GetY, 0, 0, 1);
CreateEnemyFromScript("familiarhorizontal", GetX, GetY, 0, 0, 2);
while(GetEnemyLife>=350 && GetTimer>=40){
wait(1);
}
SetDamageRate(32.5, 25);
Concentration01(30);
PlaySE(charge2);
wait(30);
loop{
loop(14){
	CreateShot02(GetX, GetY, 1, angle, 0.02, 3, RED03, 10);
	angle+=360/14;
	}
wait(50);
angle+=360/14/3;
}
}

    @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);
	}





	
}


script_enemy familiarhorizontal{
	let anim = 0;
	let one = 1;
	let vanished = false;
	let graphic = 0;
	let time = 0;
	let img = GetCurrentScriptDirectory~"sprites\familiar.png";
	let ang = 0;
	let www = 0;
	let a = 0;
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame=0;
	let angle=0;
	let frame2 = 0;
	@Initialize{
	
	LoadGraphic(img);
	
	Attack;

	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
if(GetArgument==1){
SetMovePosition02(GetClipMaxX-10, GetClipMaxY-10, 60);
wait(120);
CreateWarningLaser(GetX, GetY, -90, BLUE60, 90);
CreateWarningLaser(GetX, GetY, 180, BLUE60, 90);
wait(90);
loop{
		CreateShot01(GetX, GetY, 5, -90, BLUE01, 10);
		CreateShot01(GetX, GetY, 5, 180, BLUE01, 10);
		
	wait(2);
}
}

if(GetArgument==2){
SetMovePosition02(GetClipMinX+10, GetClipMinY+10, 60);
wait(120);
CreateWarningLaser(GetX, GetY, 90, BLUE60, 90);
CreateWarningLaser(GetX, GetY, 0, BLUE60, 90);
wait(90);
loop{
		CreateShot01(GetX, GetY, 5, 90, BLUE01, 10);
		CreateShot01(GetX, GetY, 5, 0, BLUE01, 10);
		
	wait(2);
}
}


}

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;
	}
	
	
	
	
	
	

}


	@MainLoop{
	time++;

	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	SetRenderState(ALPHA);
	SetTexture(img);
	SetGraphicScale(0.7, 0.7);
	SetAlpha(255);
	SetGraphicRect(0, 0, 64, 64);
	SetGraphicAngle(0, 0, anim);
	DrawGraphic(GetX, GetY);
}

	
	function wait(w){ loop(w){ yield;}}
	@Finalize{
	PlaySE(GetCurrentScriptDirectory~"sfx\explode.wav");
	}

}



script_enemy familiar1{
	let anim = 0;
	let one = 1;
	let vanished = false;
	let graphic = 0;
	let time = 0;
	let img = GetCurrentScriptDirectory~"sprites\familiar.png";
	let ang = 0;
	let www = 0;
	let a = 0;
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame=0;
	let angle=0;
	let frame2 = 0;
	@Initialize{
	
	LoadGraphic(img);
	
	Attack;
	Attack2;
	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
angle = GetArgument;
loop{
SetMovePosition02(GetEnemyX+60*cos(angle), GetEnemyY+60*sin(angle), 30);
if(time>40){
angle+=2.6535675895;
}
wait(1);
}
}

task Attack2{
wait(60);
loop{
	CreateShot01(GetX, GetY, 3.95+rand(-0.1, 0.1), atan2(GetEnemyY-GetY, GetEnemyX-GetX)+rand(-1, 1)-180, BLUE32, 1);
	wait(6);
	}
}
	@MainLoop{
	time++;

	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	SetRenderState(ALPHA);
	SetTexture(img);
	SetGraphicScale(0.7, 0.7);
	SetAlpha(255);
	SetGraphicRect(0, 0, 64, 64);
	SetGraphicAngle(0, 0, anim);
	DrawGraphic(GetX, GetY);
}

	
	function wait(w){ loop(w){ yield;}}
	@Finalize{
	PlaySE(GetCurrentScriptDirectory~"sfx\explode.wav");
	}

}


script_enemy familiar2{
	let anim = 0;
	let one = 1;
	let vanished = false;
	let graphic = 0;
	let time = 0;
	let img = GetCurrentScriptDirectory~"sprites\familiar.png";
	let ang = 0;
	let www = 0;
	let a = 0;
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame=0;
	let angle=0;
	let frame2 = 0;
	@Initialize{
	
	LoadGraphic(img);
	
	Attack;
	Attack2;
	
	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
angle = GetArgument;
loop{
SetMovePosition02(GetEnemyX+60*cos(angle), GetEnemyY+60*sin(angle), 30);
if(time>40){
angle-=2.6535675895;
}
wait(1);
}
}

task Attack2{
wait(60);
loop{
	CreateShot01(GetX, GetY, 3.95+rand(-0.2, 0.1), atan2(GetEnemyY-GetY, GetEnemyX-GetX)+rand(-1, 1)-180, RED32, 1);
	wait(6);
	}
}

	@MainLoop{
	time++;

	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	SetRenderState(ALPHA);
	SetTexture(img);
	SetGraphicScale(0.7, 0.7);
	SetAlpha(255);
	SetGraphicRect(0, 0, 64, 64);
	SetGraphicAngle(0, 0, anim);
	DrawGraphic(GetX, GetY);
}

	
	function wait(w){ loop(w){ yield;}}
	@Finalize{
	PlaySE(GetCurrentScriptDirectory~"sfx\explode.wav");
	}

}


script_enemy familiar3{
	let anim = 0;
	let one = 1;
	let vanished = false;
	let graphic = 0;
	let time = 0;
	let img = GetCurrentScriptDirectory~"sprites\familiar.png";
	let ang = 0;
	let www = 0;
	let a = 0;
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame=0;
	let angle=0;
	let angle2 = 0;
	let frame2 = 0;
	@Initialize{
	
	LoadGraphic(img);
	
	Attack;
	Attack2;
	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
angle = GetArgument;
loop{
SetMovePosition02(GetEnemyX+70*cos(angle), GetEnemyY+70*sin(angle), 20);
if(time>60){
angle-=1.0235675895;
}
wait(1);
}
}

task Attack2{
wait(60);
loop{
	loop(6){
	CreateShot01(GetX, GetY, 3, atan2(GetEnemyY-GetY, GetEnemyX-GetX)-180, 140, 1);
	wait(2);
	}
	wait(10);
}
}
	@MainLoop{
	time++;

	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	SetRenderState(ALPHA);
	SetTexture(img);
	SetGraphicScale(0.7, 0.7);
	SetAlpha(255);
	SetGraphicRect(0, 0, 64, 64);
	SetGraphicAngle(0, 0, anim);
	DrawGraphic(GetX, GetY);
}

	
	function wait(w){ loop(w){ yield;}}
	@Finalize{
	PlaySE(GetCurrentScriptDirectory~"sfx\explode.wav");
	}

}


script_enemy familiar4{
	let anim = 0;
	let one = 1;
	let vanished = false;
	let graphic = 0;
	let time = 0;
	let img = GetCurrentScriptDirectory~"sprites\familiar.png";
	let ang = 0;
	let www = 0;
	let a = 0;
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame=0;
	let angle=0;
	let frame2 = 0;
	let angle2 = 0;
	@Initialize{
	
	LoadGraphic(img);
	
	Attack;
	Attack2;
	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
angle = GetArgument;
loop{
SetMovePosition02(GetEnemyX+110*cos(angle), GetEnemyY+110*sin(angle), 30);
if(time>60){
angle+=0.9535675895;
}
wait(1);
}
}

task Attack2{
wait(60);
loop{
	
	CreateShot01(GetX, GetY, 3.5, atan2(GetPlayerY-GetY, GetPlayerX-GetX), PURPLE31, 0);
	CreateShot01(GetX, GetY, 3.35, atan2(GetPlayerY-GetY, GetPlayerX-GetX)+0.7, PURPLE31, 0);
	CreateShot01(GetX, GetY, 3.35, atan2(GetPlayerY-GetY, GetPlayerX-GetX)-0.7, PURPLE31, 0);
	CreateShot01(GetX, GetY, 3.2, atan2(GetPlayerY-GetY, GetPlayerX-GetX), PURPLE31, 0);
	CreateShot01(GetX, GetY, 3.2, atan2(GetPlayerY-GetY, GetPlayerX-GetX)-1.4, PURPLE31, 0);
	CreateShot01(GetX, GetY, 3.2, atan2(GetPlayerY-GetY, GetPlayerX-GetX)+1.4, PURPLE31, 0);
	wait(75);
}
}
	@MainLoop{
	time++;

	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	SetRenderState(ALPHA);
	SetTexture(img);
	SetGraphicScale(0.7, 0.7);
	SetAlpha(255);
	SetGraphicRect(0, 0, 64, 64);
	SetGraphicAngle(0, 0, anim);
	DrawGraphic(GetX, GetY);
}

	
	function wait(w){ loop(w){ yield;}}
	@Finalize{
	PlaySE(GetCurrentScriptDirectory~"sfx\explode.wav");
	}

}

