#e
#Title[777uEׁ̎v]
#Text[ŏIXyA擾͌]
#PlayLevel[Extra]
#BGM[.\BGM\th06_11.wav]
#Image[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	let u=0;
	let a=0;
	let spd=1;
	let spd2=1;
	let lnum=72;
	let dangle=360/lnum;
	let count=-180;
	let scount=60;
	let animationcount=0;
	let imgBoss=GetCurrentScriptDirectory~".\img\Sakuya.png";
	let timestart=0;
	let shootSE = GetCurrentScriptDirectory~".\SE\shoot13.wav";
	let cutin = GetCurrentScriptDirectory~".\img\cutSakuya.png";
@Initialize(){
	SetLife(5000);
	SetTimer(99);	
	LoadGraphic(imgBoss);
        SetTexture(imgBoss);
        SetGraphicRect(0, 0, 44, 86);
	SetMovePosition02(224,90,60);
	SetScore(10000000);
CutIn(KOUMA,"777uEׁ̎v",cutin,0,0,256,256);
        SetInvincibility(270);
        SetDamageRate(100,0);
}

@MainLoop(){
	if(count == -120){
		Concentration01(100);
		}

	if((GetLife()<5000 && GetLife()>=4000) || (GetTimer()<55 && GetTimer()>=30)){spd=1.25;spd2=1.25;}
	else if(GetLife()<4000 || GetTimer()<30){spd=1.5;spd2=1.5;}

	if(count == 0){
		let angle=GetAngleToPlayer();
		PlaySE(shootSE);
		loop(lnum){
			RefrectShot(GetX(),GetY(),spd,angle,1);
			angle+=dangle;
			}	
		if(GetLife()<2500){
			angle=0;
			PlaySE(shootSE);
			loop(60){
				RefrectShot(GetX(),GetY(),2,angle,1);
				angle+=6;
				}
			}	
		}

	if(count == 240){
		let angle=GetAngleToPlayer();
		let xx=GetX()+rand(-160,160);
		let yy=GetY()+rand(-100,100);
		PlaySE(shootSE);
		loop(lnum){
			RefrectShot(xx,yy,spd,angle,1);
			angle+=dangle;
			}	
		if(GetLife()<2500){
			angle=0;
			PlaySE(shootSE);
			loop(60){
				RefrectShot(xx,yy,4,angle,1);
				angle+=6;
				}
			}
		}

	if(count == 180 && (GetLife()<3500 || GetTimer()<30)){
		let angle=GetAngleToPlayer();
		let xx=GetX()+rand(-80,80);
		let yy=GetY()+rand(-50,50);
		PlaySE(shootSE);
		loop(lnum){
			RefrectShot(xx,yy,spd,angle,1);
			angle+=dangle;
			}
		if(GetLife()<1200){
			angle=GetAngleToPlayer();
			PlaySE(shootSE);
			loop(60){
				RefrectShot(xx,yy,3,angle,2);
				angle+=6;
				}
			}		
		}

	if(count == 300 && (GetLife()<3500 || GetTimer()<30)){
		let angle=GetAngleToPlayer();
		let xx=GetX()+rand(80,80);
		let yy=GetY()+rand(-50,50);
		PlaySE(shootSE);
		loop(lnum){
			RefrectShot(xx,yy,spd,angle,1);
			angle+=dangle;
			}
		if(GetLife()<1200){
			angle=GetAngleToPlayer();
			PlaySE(shootSE);
			loop(60){
				RefrectShot(xx,yy,4,angle,2);
				angle+=6;
				}
			}		
		}

	if(count==300){count=-1;}

	if(GetTimeOfPlayerInvincibility() !=0){SetDamageRate(0,0);scount=0;}
	else if(GetTimeOfPlayerInvincibility()==0 && scount<=60){SetDamageRate(0,0);}
	else{SetDamageRate(100,0);}


	if(GetTimer==9 && timestart==0){Timecounter;timestart++;}
	if(!OnBomb && scount>60){SetCollisionA(GetX(),GetY(),32);}
	SetCollisionB(GetX(),GetY(),16);
	count++;
	scount++;
	yield;
 }

@DrawLoop(){
 DrawGraphic(GetX, GetY);

	}

@Finalize(){
	DeleteGraphic(imgBoss);
	DeleteSE(shootSE);
	       }        


	task Timecounter{
		function Wait(let frame){loop(frame){yield};}
		
		loop(7){
			Wait(60);
			}
		loop(3){
			Wait(60);
			}
		}

	task RefrectShot(let x,let y,let speed,let angle,let speed2){
		let objShot= Obj_Create(OBJ_SHOT);
		Obj_SetX(objShot, x);
		Obj_SetY(objShot, y);
		Obj_SetSpeed(objShot, speed);
        	ObjShot_SetGraphic(objShot,RED32);
		Obj_SetAlpha(objShot, 255);     
		Obj_SetAngle(objShot, angle);
		while( !Obj_BeDeleted(objShot) ){
			if(Obj_GetX(objShot) >= GetClipMaxX || Obj_GetX(objShot) <= GetClipMinX){
				CreateShot01(Obj_GetX(objShot),Obj_GetY(objShot),speed2,180-angle,RED32,0);
				break;
					}
			if(Obj_GetY(objShot) <= GetClipMinY){
				CreateShot01(Obj_GetX(objShot),Obj_GetY(objShot),speed2,-angle,RED32,0);
				break;
					}
			yield;
			}
		Obj_Delete(objShot);
		}

}
