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

script_enemy_main {

	#include_function ".\Yuyukoinclude.txt";
	let i = 0;
	let dx = 0;
	let onee = 1;
	let anim3 = 0;
	let color = 0;
	let x = 0;
let y = 0;
let one = 1;
let wide = 1;
let angle2 = 0;
	@Initialize{
	shotinit;
	LoadSE(time1);
	LoadGraphic(imageFile);
	LoadGraphic(imageFile2);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(ping);
	LoadSE(shot);
	DelayedStart;
	LoadSE(shot2);
	LoadSE(die);
	LoadSE(wisps);
	LoadSE(wispspawner);
	SetTimer(99);
	SetEnemyMarker(true);
	SetInvincibility(600);
	SetDamageRate(30, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(30, 30, 30, 40);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(ping);
	LoadSE(dream);
	LoadSE(die);
	LoadSE(ylaser);
	LoadSE(glaser);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	SetCommonData("lastattack", false);
	}

task DelayedStart {
let i = 0;
let radius = 30;
angle = 180;
wait(90);

SetScore(1500000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Nether Sign "\""Lights of the Undead"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);

attack1;
attack2;
//Shiny;
SetTimer(62);
}


task attack1 {
wait(150);
x = 1;
loop{
loop(x){
angle = GetAngleToPlayer;
PlaySE(laser);
CreateLaser(angle, 90);
wait(90);
PlaySE(glaser);
}
wait(120);
ExMove;
wait(90);
PlaySE(ylaser);
if(wide==1){
ascent(i in -3..2){
CreateLaser2(GetAngleToPlayer+(i*15)+15, 90, 180);
}
wide=0;
wait(60);
}
else if(wide==0){

ascent(i in -3..2){
CreateLaser2(GetAngleToPlayer+(i*5)+5, 120, 60);
}
wide=1;
}
wait(240);
ExMove;
wait(60);
x=3;
}
}


task attack2 {
wait(360);
loop{
y++;
PlaySE(shot4);
loop(22){
ascent(i in 0..2){
CreateShotA(1, GetX, GetY, 10);
SetShotDataA(1, 0, 4, angle2, 0.5*one, -0.2, 1, [AQUA22, RED22][y%2]);
SetShotDataA(1, 60, NULL, NULL, 0, 0, 1, NULL);
SetShotDataA(1, 90, NULL, NULL, 0, 0.02, 1+(i/10), NULL);
FireShot(1);
}
angle2+=360/22;
}
angle2+=9.5+rand(-3, 31.010392);
one=one*-1;
wait(30);
}
}
task CreateLaser(angle, delay){
let obj = Obj_Create(OBJ_LASER);
		let width = 40;
		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,WHITE60);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetSource(obj, false);
		while(!Obj_BeDeleted(obj)) {
		if(length<600){ length+=10; }
		ObjLaser_SetLength(obj,length);
		
		if(count==delay){
		CreateLaser01(GetX, GetY, 10, angle, 400, 50, RED02, 0);
		Obj_Delete(obj);
		}
		count++;
		yield;
		}
	}



task CreateLaser2(angle, delay, time){
let obj = Obj_Create(OBJ_LASER);
		let width = 40;
		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,PURPLE60);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetSource(obj, false);
		while(!Obj_BeDeleted(obj)) {
		if(length<600){ length+=10; }
		ObjLaser_SetLength(obj,length);
		
		if(count>delay+time){
		width--;
		ObjLaser_SetWidth(obj,width);
		if(width<=0){
		Obj_Delete(obj);
		}
		}
		count++;
		yield;
		}
	}

	


@BackGround{

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(255);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetGraphicScale(1, 1);
SetGraphicRect(0, 0, 512, 512);
SetAlpha(150);
DrawGraphic(GetCenterX, GetCenterY);

SetGraphicScale(1, 1);
anim2 += 1.5;
acc1 = 6;
}


}