
#Title[enm2 Attack03 hard]
#Text[REV[bg@ʏ03]
#Player[FREE]
#BackGround[Default]
#ScriptVersion[2]

script_enemy_main {
	let imgEffect = GetCurrentScriptDirectory~".\enm2eff\bossEfect.png";
	let t5		= GetCurrentScriptDirectory~"..\..\se\timer1.wav";
	let t10	   = GetCurrentScriptDirectory~"..\..\se\timer2.wav";
	let tan	   = GetCurrentScriptDirectory~"..\..\se\shot1.wav";
	let kira	  = GetCurrentScriptDirectory~"..\..\se\shot2.wav";
	let Gspel	 = GetCurrentScriptDirectory~"..\..\se\echo5.wav";
	let laser	 = GetCurrentScriptDirectory~"..\..\se\Laser2.wav";
	let power	 = GetCurrentScriptDirectory~"..\..\se\enemy_powereffect.wav";
	let powerl	= GetCurrentScriptDirectory~"..\..\se\power_logo.wav";
	let gekiha	= GetCurrentScriptDirectory~"..\..\se\BossEnd.wav";
	let powerla   = GetCurrentScriptDirectory~"..\..\se\power_logo.wav";
	let kaku	  = GetCurrentScriptDirectory~"..\..\se\j.wav";
	let frame	 = 0;
	let GetAngle  = 0;
	let angle	 = 0;
	let angle2	= 0;
	let angleBase = 0;
	let count	 = 0;
	let timer	 = 0;
	let shotdir   = GetCurrentScriptDirectory ~ "data_usershot.txt";
	let MinX	  = GetClipMinX;
	let MaxX	  = GetClipMaxX;
	let CenX	  = GetCenterX;
	let MinY	  = GetClipMinY;
	let MaxY	  = GetClipMaxY;
	let CenY	  = GetCenterY;
	let T_count   = 0;
	let Damage	= 0;
	let a		 = 0;
	let b		 = 0;
	let S_count   = 0;
	let w		 = 0;
	let lp		= 0;

	@Initialize {
		//SetX(MaxX+100);
		//SetY(MinY-100);

		SetLife(3000);
	SetDamageRate(0,0);

	SetInvincibility(120);

	/*e폜@(l64)*/
	SetShotAutoDeleteClip(30,30,30,30);

	LoadUserShotData(shotdir);
	SetMovePosition03(CenX,CenY-150,10,5);
	LoadGraphic(imgEffect);
	Aura(8,255,32,32);
	MagicCircle(false);
	SetRateScoreSystemEnable(false);
	hpb(0,1,0);
	SetTimer(60);
	Timer(2,1);
	VSname(0);
	VSname2(0,0);
	VSname2(10,0);
	EnemyTexture(true);
	RedMagicCircle(1,0);
	Shot_Main;
	}

	@MainLoop {
	yield;
		SetCollisionA(GetX, GetY, 30);
		SetCollisionB(GetX, GetY, 16);

	/*ԏ*/
	if(GetTimer<=10 && GetTimer>=0){T_count++;}
	alternative(T_count)
	case(1,60,120,180,240){PlaySE(t10);}
	case(300,360,420,480,540){PlaySE(t5);}

	/*{Agp莞ԃ_[W*/
	if(OnBomb==true){SetDamageRate(120,100);Damage=0;}
	if(OnBomb==false){Damage++;}
	if(Damage>=100){SetDamageRate(120,100);}

	/*XyJ[hؐ錾*/
	if(S_count==1){
	CutinSP("TIREI",50,-50,4000000,60,0,0,0,0,0);
	CutinSP2(-120,-10,GetCurrentScriptDirectory~".\enm2spell\enm2_sn01_normal.png",0,0,300,30,255,255,255);
	BackGroundEffect;
	}
	if(S_count==50){
	}
	

	a++;	
	frame++;
	count++;
	//S_count++;
	timer++;

}//MainLoop")"łB

	@DrawLoop {}

	@Finalize {
	}
	
	task Shot_Main{
		MoveToPlayerRand;
		loop(60){yield;}
		loop {
			Concentration(50,powerl);
			loop(60){yield;}
			SetCommonData("Attack",true);
			loop(3){
				angle=GetAngleToPlayer;
				PlaySE(tan);
				ascent( let a in 0..22) loop{
					CreateShotA(0,GetX,GetY,10);
					SetShotDataA(0,0,rand(1.4,2.2),angle+rand(-20,20),0,0,0,17);
					FireShot(0);
				}
				ascent( let a in 0..12) loop{
					CreateShotA(0,GetX,GetY,10);
					SetShotDataA(0,0,rand(2.3,3.1),angle+rand(-10,10),0,0,0,41);
					FireShot(0);
				}
				CreateShotA(0,GetX,GetY,10);
				SetShotDataA(0,0,3.7,angle,0,0,0,49);
				FireShot(0);
				wait(35);
			}
			loop(9){
				PlaySE(tan);
				ascent( let a in 0..22) loop{
					CreateShotA(0,GetX,GetY,10);
					SetShotDataA(0,0,rand(1.4,2.2),angle+rand(-20,20),0,0,0,17);
					FireShot(0);
				}
				ascent( let a in 0..12) loop{
					CreateShotA(0,GetX,GetY,10);
					SetShotDataA(0,0,rand(2.3,3.1),angle+rand(-10,10),0,0,0,41);
					FireShot(0);
				}
				CreateShotA(0,GetX,GetY,10);
				SetShotDataA(0,0,3.7,angle,0,0,0,49);
				FireShot(0);
				angle+=40;
				wait(5);
			}
			SetCommonData("Attack",false);
			MoveToPlayerRand;
			wait(60);
			Concentration(50,powerl);
			loop(60){yield;}
			angle = 180;
			SetCommonData("Charge",true);
			loop(5){
				PlaySE(tan);
				ascent( let a in 0..20) {
					CreateReflectShot(GetX+64*cos(angle),GetY+64*sin(angle),2.2,a*360/20,16,30,1);
					}
				wait(30);
				angle-=180/4;
			}
			MoveToPlayerRand;
			SetCommonData("Charge",false);
			wait(60);
		}
	}
		
	task CreateReflectShot(let x, let y, let speed,
             let angle, let graphic, let delay, let count) {
    
 	   //IuWFNge̍쐬
 	   let obj = Obj_Create(OBJ_SHOT);
    
	    //p[^̐ݒ
	    Obj_SetPosition(obj, x, y);
	    Obj_SetSpeed(obj, speed);
	    Obj_SetAngle(obj, angle);
	    ObjShot_SetGraphic(obj, graphic);
	    ObjShot_SetDelay(obj, delay);
    
	    loop(delay){ yield; }
    
	    while(!Obj_BeDeleted(obj)) {

	        //[
	        if(Obj_GetX(obj)<GetClipMinX){
	            Obj_SetX(obj, GetClipMinX*2 - Obj_GetX(obj));
	            Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
	            count--;
			PlaySE(kira);
	        }
	        //E[
	        if(Obj_GetX(obj)>GetClipMaxX){
	            Obj_SetX(obj, GetClipMaxX*2 - Obj_GetX(obj));
	            Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
	            count--;
			PlaySE(kira);
	        }
	        //[
	        if(Obj_GetY(obj)<GetClipMinY){
	            Obj_SetY(obj, GetClipMinY*2 - Obj_GetY(obj));
	            Obj_SetAngle(obj, 360 - Obj_GetAngle(obj));
	            count--;
			PlaySE(kira);
	        }
        
	        if(count<=0){ break; }
    
	        yield;
	    }
	}

	
function MoveToPlayer_(xMove, yAdd, frame, left, top, right, bottom) {
	let x;
	let y;
	if(GetPlayerX < GetX) {
		x = GetX - xMove;
		if(x < left) {
			x = GetX + xMove;
		}
	} else {
		x = GetX + xMove;
		if(right < x) {
			x = GetX - xMove;
		}
	}
	y = GetY + yAdd;
	if(y < top) {
		y = top;
	} else if(bottom < y) {
		y = bottom;
	}
	SetMovePosition03(x, y, 20, 2);
}

function MoveToPlayerRand {
	MoveToPlayer_(rand(40, 80),rand(-40, 40),60,GetClipMinX+32,GetClipMinY+80,GetClipMaxX-32,GetClipMinY+140);
	}

	#include_function".\Obj_Control.txt"
	#include_function".\lib_kshot.txt"
}