
#Title[EirinS2_L]
#Text[Instead of trapping the player, Eirin traps herself. Doesn't the card name seem a bit haughty?]
#Player[FREE]
#ScriptVersion[2]
#BGM[.\mu\bgm.mp3]

script_enemy_main {
let c = 0;
let life = 0;
	#include_function ".\Eirininclude.txt";

	@Initialize{
	DeleteSE("se\seEnemyExplode01.wav");
	shotinit;
	LoadGraphic(imglifebar); 
	LoadSE(time1);
	LoadSE(capture);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(laser2);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(shot);
	DelayedStart;
	LoadSE(shot2);
	SetTimer(99);
	SetEnemyMarker(true);
	SetInvincibility(600);
	SetDamageRate(40, 25);
	//SetMovePosition02(GetCenterX+rand(-30, 30), GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(50, 100, 50, 50);
	LoadGraphic(SP);
	LoadGraphic(MC);
	MagicCircle(false);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadGraphic(CBG3);
	LoadGraphic(CBG4);
	LoadGraphic(CBG5);
	LoadGraphic(Cut);
	LoadSE(orb);
	LoadSE(warp);
	LoadSE(caution);
	LoadSE(border);
	SetAction(ACT_MOVE, 60);
	}


task DelayedStart {
wait(60);
SetScore(6000000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Spacesphere "\""God in a Pot"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
attack1;
SetTimer(73);
wait(120);
SetCommonData("spells", GetCommonDataDefault("spells", 0)+1);
}



task CreateLaser(angle, graphic, delay){
let obj = Obj_Create(OBJ_LASER);
		let width = 20;
		let count = 0;
		let length = 0;
		Obj_SetPosition(obj,GetX,GetY);
		ObjLaser_SetLength(obj,0);
		ObjLaser_SetWidth(obj,width);
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,graphic);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetSource(obj, false);
		while(!Obj_BeDeleted(obj)) {
		if(length<700){ length+=10; }
		ObjLaser_SetLength(obj,length);
		if(count==90){
		PlaySE(ping);
		}
		if(count>=550){
		width-=1;
		}
		if(width<=10){
		Obj_SetCollisionToPlayer(obj, false);
		}
		
		if(count>=570){
		Obj_Delete(obj);
		}
		ObjLaser_SetWidth(obj,width);
		count++;
		yield;
		}
	}


		

task attack1 {
//collision=false;
let one = 1;
let firsttime = true;
let j = 0;
wait(135);
SetMovePosition02(GetCenterX, GetCenterY, 60);
SetAction(ACT_MOVE, 60);
wait(75);
Concentration01(120);
PlaySE(charge);
SetAction(ACT_SHOT_B, 1200000000);
wait(120);

loop(14){
CreateEnemyFromScript("familiar", GetX+120*sin(angle), GetY+120*cos(angle), 0, 0, angle);
angle+=360/14;
}
wait(540);


loop{
Concentration01(60);
wait(60);
PlaySE(laser);
	loop(4){
		
		CreateLaser(angle, [RED60, YELLOW60, GREEN60, BLUE60][c%4], 90);
		angle+=360/4;
		}
	c++;

wait(690);
angle+=360/4/2
		 

}
}






@BackGround{
SetTexture(CBG1);
SetGraphicRect(0, anim2/-2, 512, 512+(anim2/-2));
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG2);
SetAlpha(130);
SetGraphicScale(0.5, 1);
SetGraphicRect(0, anim2*3, 512, 512 + anim2*3);
DrawGraphic(GetCenterX-130, GetCenterY);
DrawGraphic(GetCenterX+130, GetCenterY);
SetGraphicScale(1, 1);
SetAlpha(255);
SetTexture(CBG3);
SetGraphicRect( 0, 0, 512, 512 );
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG4);
SetRenderState(ADD);
SetGraphicRect(0, 0, 512, 512);
SetGraphicScale(0.9, 0.9);
SetColor(80, 80, 80);
DrawGraphic(GetCenterX, GetCenterY-70);
SetColor(255, 255, 255);
SetRenderState(ALPHA);
SetGraphicScale(1, 1);



anim2 += 1;
acc1 = 6;


}




}









script_enemy familiar {
	let c = rand_int(0, 120);
	let radiusmax = 100;
	let boom = GetCurrentScriptDirectory~"sfx\boom.wav";
	let angle = 0+GetArgument;
	let angle2 = 0;
	let angle3 = 0;
	let i = 0;
	let time = 0;
	let radius = 360;
	let radius2 = GetArgument;
	let charge = GetCurrentScriptDirectory~"sfx\Charge.wav";
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
	let shot4 = GetCurrentScriptDirectory~"sfx\shot4.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	let familiar = GetCurrentScriptDirectory~"sprites\familiar.png";
	let Custom = GetCurrentScriptDirectory~"sup\supershot.txt";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame = 0;
	let frame2 = 0;
	@Initialize{
	attack1;
	attack2;
	Outward;
	LoadGraphic(familiar);
	LoadSE(boom);
	SetLife(500);
	LoadSE(shot);
	LoadSE(shot2);
	LoadSE(shot3);
	LoadSE(charge);
	LoadSE(shot4);
	shotinit;
	SetDamageRateEx(0, 0, 0, 0);
}

function wait(w){ loop(w){ yield;}}
task Outward{
loop(240){
radius-=0.9;
wait(1);
}
}


function GetAngleToBoss{
let angle2 = 0;
angle2 = atan2(GetY - GetEnemyY, GetX - GetEnemyX)+rand(-10, 10);
return(angle2);
}

function GetAngleToBoss2{
let angle2 = 0;
angle2 = atan2(GetY - GetEnemyY, GetX - GetEnemyX);
return(angle2);
}


task attack1{
	wait(120);

	loop{
		angle3 = GetAngleToBoss+rand(-10, 10);
		PlaySE(shot4);
		ascent(i in -5..4){
		
		CreateShot01(GetX, GetY, 3, angle3+(i*2), GREEN50, 0);
		}
		
		wait(10);
		i++;
	    }
}
	

task attack2{
i = 0;
wait(240);
Concentration01(30);
wait(30);
wait(rand_int(0, 60));
loop{
//PlaySE(shot);
loop(4){
CreateShot01(GetX, GetY, 1, atan2(GetY-GetPlayerY, GetX-GetPlayerX)-180, [RED05, BLUE05][c%2], 30);
wait(25);
}
c++;
wait(180);
}
}


	@MainLoop{
time++;
//SetCollisionA(GetX, GetY, 10);
	SetMovePosition02(GetEnemyX+radius*cos(angle), GetEnemyY+radius*sin(angle), 10);

	angle+=1.75685345;
	yield;
	
	
	 
}
	@DrawLoop{
	frame++;
	SetTexture(familiar);
	SetGraphicRect(192, 0, 256, 64);
	SetGraphicScale(0.5, 0.5);
	SetAlpha(255);
	SetGraphicAngle(0, 0, frame*4);
	DrawGraphic(GetX, GetY);
	
}

	
	
	@Finalize{
	PlaySE(boom);
	}

}



	