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

script_enemy_main {
	let lastphase = false;
	let variable = 0;
	let xpos = 0;
	let one = 1;
	let frame = 0;
	let c = 0;
	let boom = false;
	let random = 0;
	let b = 0;
	let frame2 = 0;
	let undulate = 0;
	let color = 0;
	#include_function ".\Yukainclude.txt";
	let i = 0;
	let onee = 1;
	let anim3 = 0;
	let plax = 0;
	let blah = 0;
	@Initialize{
	shotinit;
	LoadSE(capture);
	LoadSE(time1);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(3000);
	LoadSE(ping);
	LoadSE(shot);
	DelayedStart;
	LoadSE(laser);
	SetCommonData("lastattack", true);
	LoadSE(shot2);
	LoadSE(die);
	SetTimer(120);
	SetEnemyMarker(true);
	SetInvincibility(420);
	SetDamageRate(30, 0);
	SetEffectForZeroLife(120, 100, 1);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(50, 50, 50, 50);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(laser2);
	LoadSE(die);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	MagicCircle(false);
	}

task DelayedStart {
wait(90);
kaboom;
Concentration01(60);
PlaySE(charge);
wait(60);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin(""\""The Garden of the Sun"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
attack1;
Movement;
//attack2;
SpellBG;
SetTimer(120);
}

	let backRED = 255;
	let backGREEN = 255;
	let backBLUE = 255;

task Movement{
wait(420);
loop{
	if(lastphase==true){
	break;
	}
ExMove;
wait(240);
}
}


task CreateShotSinuate(x, y, v, angle, graphic, delay, length, width) {
		let obj = Obj_Create(OBJ_SINUATE_LASER);
		let angle2 = 0;
		let stopped = false;
		let speed = v;
		let firsttime = true;
		let time = 0;
		let radius = 0;
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, v);
		Obj_SetCollisionToObject(obj, true);
		ObjShot_SetDelay(obj, 0);
		ObjShot_SetGraphic(obj, YELLOW51);
		ObjSinuateLaser_SetLength(obj, length);
		ObjSinuateLaser_SetWidth(obj, width);
		while(!Obj_BeDeleted(obj)){
		if(speed>0 && stopped==false){
		speed-=0.08888888888;
		Obj_SetSpeed(obj, speed);
		}
		if(speed<=0){
		stopped=true;
		}
		if(stopped==true && firsttime==true){
		firsttime = false;
		wait(30);
		Obj_SetAngle(obj, atan2(Obj_GetY(obj)-GetPlayerY, Obj_GetX(obj)-GetPlayerX)-180);
		}
		
		if(speed<5 && stopped==true){
		speed+=0.1;
		Obj_SetSpeed(obj, speed);
		}		

		time++;
		yield;
		}	
}		

task CreateShotAngular(x, y, v, angle, graphic, delay, angvel) {
		let obj = Obj_Create(OBJ_SHOT);
		let angle2 = 0;
		let time = 0;
		let radius = 0;
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, 0);
		Obj_SetCollisionToObject(obj, true);
		ObjShot_SetDelay(obj, delay);
		ObjShot_SetGraphic(obj, graphic);
		while(!Obj_BeDeleted(obj)){
		Obj_SetPosition(obj, x+radius*cos(angle+angle2), y+radius*sin(angle+angle2));
		radius+=v;
		angle2+=angvel;
		yield;
		}	
}		
	
task CreateLaser(ang, delay){
let obj = Obj_Create(OBJ_LASER);
		let angle = ang;
		let count = 0;
		let width = 17;
		Obj_SetPosition(obj,GetCenterX+36*cos(angle),GetClipMinY+36*sin(angle));
		ObjLaser_SetLength(obj,500);
		ObjLaser_SetWidth(obj,20);
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,ORANGE60);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetSource(obj, false);
		while(!Obj_BeDeleted(obj)) {
		ObjLaser_SetWidth(obj,width);
		
		count++;
		if(count==90){
		//PlaySE(ping);
			ascent(i in 0..20){
				CreateShotA(1, Obj_GetX(obj)+((30+i*23)*cos(angle)), Obj_GetY(obj)+((30+i*23)*sin(angle)), 10);
				SetShotDataA(1, 0, 0, ang+(i*(17+b)), 0, 0, 0, RED23);
				SetShotDataA(1, 30, 0, NULL, 0, 0.01, 1.25, NULL);
				FireShot(1);
				wait(1);
				}
		}
		if(count>110+delay){
		width-=0.7;
		if(width<=5){
		Obj_SetCollisionToPlayer(obj, false);
		}
		if(width<=0){
		Obj_Delete(obj);
		}
		}
		yield;
		}
	}



task kaboom{
loop{
if(GetEnemyLife==0 && boom==false){
boom=true;
PlaySE(die);
}
yield;
}
}


task attack1{
wait(120);
PlaySE(charge);
Concentration01(60);
wait(60);
PlaySE(ping);
loop(20){
CreateSun(GetCenterX, GetClipMinY, 0, 0, YELLOW51, 0);
CreateSun(GetCenterX+15*cos(angle), GetClipMinY+15*sin(angle), 0, 0, YELLOW51, 0);
CreateSun(GetCenterX+30*cos(angle), GetClipMinY+30*sin(angle), 0, 0, YELLOW51, 0);
angle+=360/20;
}
wait(60);
attack2;
while(GetEnemyLife>=2400){
yield;
}
wait(30);
Concentration01(60);
PlaySE(charge);
wait(60);
PlaySE(ping);
SetCommonData("suncolor", 2);
SetInvincibility(240);
attack3;
SetDamageRate(35, 0);
while(GetEnemyLife>=1700){
yield;
}
wait(60);
loop(3){
Concentration01(30);
PlaySE(charge);
wait(30);
}
PlaySE(ping);
SetCommonData("suncolor", 3);
DeleteEnemyShotToItem(SHOT);
loop(30){
CreateSun(GetCenterX+45*cos(angle), GetClipMinY+45*sin(angle), 0, 0, RED51, 0);
angle+=360/30;
c++;
if(c%2==0){
wait(1);
}
}
loop(35){
CreateSun(GetCenterX+60*cos(angle), GetClipMinY+60*sin(angle), 0, 0, RED51, 0);
angle+=360/30;
c++;
if(c%2==0){
wait(1);
}
}
attack4;
SetDamageRate(20, 0);
while(GetEnemyLife>=1000){
yield;
}
SetInvincibility(120);
SetDamageRate(35, 0);
loop(4){
Concentration01(30);
PlaySE(charge);
wait(20);
}
SetCommonData("suncolor", 4);
PlaySE(ping);
loop(45){
CreateSun(GetCenterX+70*cos(angle), GetClipMinY+70*sin(angle), 0, 0, GREEN51, 0);
angle+=360/45;
c++;
if(c%2==0){
wait(1);
}
}
SetMovePosition02(GetCenterX, GetClipMinY, 60);
wait(30);
attack5;
attack5b;
lastphase = true;


}

task attack5b{
wait(120);
loop{
angle2 = rand(90+45, 90-45);
PlaySE(laser2);
CreateShotSinuate(GetCenterX+75*cos(angle2), GetClipMinY+75*sin(angle2), 4, angle2, WHITE51, 10, 55, 15);
wait(45);
}
}

task attack5{
SetShotAutoDeleteClip(10, 10, 10, 10);

loop{
	loop(8){
CreateShot01(GetCenterX+75*cos(angle), GetClipMinY+75*sin(angle), 3.35+rand(-0.1, 0.1), angle+rand(1,-1), GREEN21, 10);
CreateShot01(GetCenterX+75*cos(-angle), GetClipMinY+75*sin(-angle), 3.05+rand(-0.1, 0.1), -angle+rand(1,-1), BLUE21, 10);
	angle+=360/8;
	}
wait(4);
angle+=4.569489832;
}
}



task attack4{
SetShotAutoDeleteClip(150, 150, 150, 50);
loop{
	loop(18){
CreateShotAngular(GetCenterX+65*cos(angle), GetClipMinY+65*sin(angle), 2.5, angle, RED51, 10, 0.45*one);
	angle+=360/18;
	}
one=one*-1;
wait(15);
angle+=rand(-10, 10);
if(GetEnemyLife<=1000){
break;
}
}
}

	

task frametick{
loop{
frame++;
wait(1);
}
}

task CreateSun(x, y, v, angle, graphic, delay){
	let alpha = 0;
	let speed = v;
	let change = 1;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetAutoDelete(obj, false);
	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)){
	if(GetCommonDataDefault("suncolor", 1)==2 && change ==1){
	ObjShot_SetGraphic(obj, ORANGE51);
	change=2;
	}
	if(GetCommonDataDefault("suncolor", 2)==3 && change ==2){
	ObjShot_SetGraphic(obj, RED51);
	change=3;
	}
	if(GetCommonDataDefault("suncolor", 3)==4 && change ==3){
	ObjShot_SetGraphic(obj, GREEN51);
	change=4;
	}
	Obj_SetAlpha(obj, alpha);
	if(alpha<255){
	alpha+=15;
	}
	yield;
	}
	
	
	
	
	


}

task attack3{
wait(30);
SetShotAutoDeleteClip(20, 50, 20, 10);
angle = 45;
	loop{
	CreateLaser(angle, 45);
	angle+=pi*3;
	wait(6);
	b+=2;
	if(GetEnemyLife<=1700){
break;
}

}
}


task attack2b{
	wait(60);
	loop{

		
if(GetEnemyLife<=2400){
break;
}
		PlaySE(laser2);
		loop(18){
		CreateLaser01(GetCenterX+38*cos(angle2), GetClipMinY+38*sin(angle2), 3.85, angle2+rand(-5, 5), 125, 10, YELLOW50, 10);
		angle2+=360/18;
		}

angle2-= -69.41982;

wait(25);
}
} 

task attack2{
attack2b;
frametick;
loop{

if(GetEnemyLife<=2400){
break;
}
random = rand(-3, 3);
	loop(14){
		ascent(i in -2..3){
		CreateShot01(GetCenterX+38*cos(angle), GetClipMinY+38*sin(angle), 3.35+(random/75), (angle+(i*1.25))+random, ORANGE04, 10);
		}
		angle+=360/14;
		}
angle+=67.42083;
wait(15);


}
}

	task SpellBG {
		let w = 60;
		wait(w);
		loop(w){
			backGREEN-=255/w;
			backBLUE-=255/w;
			wait(1);
		}
		loop{
			loop(w){
				backGREEN+=128/w;
				wait(1);
			}
			loop(w){
				backGREEN+=127/w;
				wait(1);
			}
			loop(w){
				backRED-=255/w;
				wait(1);
			}
			loop(w){
				backBLUE+=255/w;
				wait(1);
			}
			loop(w){
				backGREEN-=255/w;
				wait(1);
			}
			loop(w){
				backRED+=255/w;
				wait(1);
			}
			loop(w){
				backBLUE-=255/w;
				wait(1);
			}
		}
	}




@BackGround{
SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetGraphicScale(1, 1);
SetColor(backRED/3, backGREEN/3, backBLUE/3);
SetGraphicRect(19, 0+(anim2*5), 474, 455+(anim2*5));
SetAlpha(255);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetColor(255, 255, 255);
SetGraphicScale(1, 1);
SetGraphicRect(0, 0-(anim2*4), 512, 512-(anim2*4));
SetAlpha(60);
DrawGraphic(GetCenterX, GetCenterY);
SetColor(255, 255, 255);
i+=1; i%=360;
anim2 += 0.75;
acc1 = 6;


}




	
}