#e
#Title[yuiCgtB[o[v]
#Text[i]ߋ̃XyJ[h]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name    = "yuiCgtB[o[v";
        let csd     = GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_iku.png";
	let imgEnemy=csd~"img\familiar2.png";
        let imgSPELL =csd~"img\SPELL_H2.png";
        let imgSPELL2 =csd~"img\SPELL_H3.png";
	let imgBACK=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let big=0;
	let angle=0;
	let imgAngle=0;
	let shotseA = csd~"se\laser001.wav";

    @Initialize {
    CutIn(YOUMU,name,0,0,0,0,0);

        SetLife(3500);
        SetTimer(60);
        SetScore(1000000);
        SetDamageRate(100,100);
        SetInvincibility(200);
        SetMovePosition02(cx,cy-50,60);
	LoadGraphic(imgBoss);
	LoadGraphic(imgEnemy);
	LoadGraphic(imgSPELL);
	LoadGraphic(imgSPELL2);
        TAnime1;
	}

        @MainLoop
        {

	imgAngle+=5;
	if(imgAngle>=360){imgAngle=0;}
	if(big<99){big+=2;}
	imgBACK+=2;
	if(imgBACK==448){imgBACK=0;}

	if(count==150){
		Concentration01(60);
		}
	if(count==200){
		PlaySE(shotseA);
        	let i=0;
        	while(i<7)
        	{
        		SlaserA(44+i*60,20);
                	SetShotDirectionType(ABSOLUTE);
        		let shot01 = 1;
        		CreateShotA(shot01,44+i*60,20,100);
        		SetShotDataA(shot01,0,3,90,0,0.01,3.5,RED21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,20,100);
        		SetShotDataA(shot01,0,2.5,90,0,0.01,3,RED21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,20,100);
        		SetShotDataA(shot01,0,2,90,0,0.01,2.5,RED21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,20,100);
        		SetShotDataA(shot01,0,1.5,90,0,0.01,2,RED21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,20,100);
        		SetShotDataA(shot01,0,1,90,0,0.01,1.5,RED21);
        		FireShot(shot01);
        		i++;
        		}
		}
	if(count==275){
        	let i=0;
        	while(i<18)
        	{
                	SetShotDirectionType(PLAYER);
        		let shot01 = 1;
        		CreateShotA(shot01,GetX(),GetY(),0);
        		SetShotDataA(shot01,0,2,i*20,0,0.02,3.5,YELLOW21);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX(),GetY(),0);
        		SetShotDataA(shot01,0,1.5,i*20,0,0.02,3,YELLOW21);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX(),GetY(),0);
        		SetShotDataA(shot01,0,1,i*20,0,0.02,2.5,YELLOW21);
        		FireShot(shot01);
        		i++;
        		}
		}
	if(count==300){
		PlaySE(shotseA);
        	let i=0;
        	while(i<7)
        	{
        		SlaserB(44+i*60,460,-15+i*5);
                	SetShotDirectionType(ABSOLUTE);
        		let shot01 = 1;
        		CreateShotA(shot01,44+i*60,460,100);
        		SetShotDataA(shot01,0,3,270,0,0.01,3.5,BLUE21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,460,100);
        		SetShotDataA(shot01,0,2.5,270,0,0.01,3,BLUE21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,460,100);
        		SetShotDataA(shot01,0,2,270,0,0.01,2.5,BLUE21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,460,100);
        		SetShotDataA(shot01,0,1.5,270,0,0.01,2,BLUE21);
        		FireShot(shot01);
        		CreateShotA(shot01,44+i*60,460,100);
        		SetShotDataA(shot01,0,1,270,0,0.01,1.5,BLUE21);
        		FireShot(shot01);
        		i++;
        		}
		}
	if(count>=200&&count%100==0){
        	let i=0;
        	while(i<7)
        	{
                	SetShotDirectionType(PLAYER);
        		let shot01 = 1;
        		CreateShotA(shot01,44+i*60,20,0);
        		SetShotDataA(shot01,0,2,0,0,0.02,4,GREEN02);
        		FireShot(shot01);
        		i++;
        		}
		}
	if(count==350){
        	let i=0;
        	while(i<18)
        	{
                	SetShotDirectionType(PLAYER);
        		let shot01 = 1;
        		CreateShotA(shot01,GetX(),GetY(),0);
        		SetShotDataA(shot01,0,2,i*20,0,0.02,3.5,YELLOW21);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX(),GetY(),0);
        		SetShotDataA(shot01,0,1.5,i*20,0,0.02,3,YELLOW21);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX(),GetY(),0);
        		SetShotDataA(shot01,0,1,i*20,0,0.02,2.5,YELLOW21);
        		FireShot(shot01);
        		i++;
        		}
		move;
        	TAnime2;
        	count=150;
		}
        SetCollisionB(GetX(),GetY(),22);
	SetCollisionA(GetX(),GetY(),22);
        count++;
        yield;
        }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgEnemy);
		SetGraphicRect(0,0,192,192);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicScale(0.01*big,1);
		SetGraphicAngle(0,0,imgAngle);
		DrawGraphic(GetX(),GetY());

		SetGraphicAngle(0,0,-imgAngle);
		DrawGraphic(GetX(),GetY());

		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(128*AnimationC,128*AnimationB,127+128*AnimationC,127+128*AnimationB);}
		else if(GetSpeedX()>0){SetGraphicRect(256,256+128*AnimationA,383,383+128*AnimationA);}
		else if(GetSpeedX()<0){SetGraphicRect(256,128*AnimationA,383,127+128*AnimationA);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
	loop(50)
	{
		angle=rand(0,360);
		CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,50),GetY+sin(angle)*rand(35,50));
	}
        }

	@BackGround
	{
		//wi`
		SetGraphicRect(0,0,384,448);
		SetTexture(imgSPELL2);
		SetRenderState(ALPHA);
		SetColor(255,255,255);
		SetAlpha(155);
		DrawGraphic(cx,cy+448-imgBACK);

		DrawGraphic(cx,cy-imgBACK);

		SetTexture(imgSPELL);
		SetAlpha(55);
		DrawGraphic(cx,cy-448+imgBACK);

		DrawGraphic(cx,cy+imgBACK);
	}

    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(8){yield;}
			AnimationB=1;
        		loop(8){yield;}
			AnimationB=2;
        		loop(8){yield;}
			AnimationB=3;
        		loop(32){yield;}
			AnimationB=2;
        		loop(8){yield;}
			AnimationB=1;
        		loop(8){yield;}
			AnimationB=0;
        		loop(8){yield;}
		loop(2){
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			}
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
		loop{
			AnimationB=0;
			AnimationC=3;
        		loop(50){yield;}
			AnimationB=1;
        		loop(5){yield;}
			AnimationB=2;
        		loop(5){yield;}
			AnimationB=3;
        		loop(125){yield;}
			AnimationB=2;
        		loop(5){yield;}
			AnimationB=1;
        		loop(5){yield;}
			AnimationB=0;
        		loop(5){yield;}
			}
		}

    	task TAnime2{
			AnimationA=0;
        		loop(10){yield;}
			AnimationA=1;
        		loop(40){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}

    	task SlaserA(x,y){
		let obj = Obj_Create(OBJ_LASER);
		let l = 0;
		Obj_SetPosition(obj,x,y);
		ObjShot_SetGraphic(obj,ORANGE01);
		ObjShot_SetDelay(obj,100);
		ObjLaser_SetWidth(obj,30);
	loop(50){
		Obj_SetAngle(obj,atan2(GetEnemyY-y,GetEnemyX-x));
		ObjLaser_SetLength(obj,l*20);
		l++;
		yield;}
	loop(100){
		Obj_SetAngle(obj,atan2(GetEnemyY-y,GetEnemyX-x));
		yield;}
	Obj_Delete(obj);
	}

    	task SlaserB(x,y,angle){
		let obj = Obj_Create(OBJ_LASER);
		let l = 0;
		Obj_SetPosition(obj,x,y);
		ObjShot_SetGraphic(obj,AQUA01);
		ObjShot_SetDelay(obj,100);
		ObjLaser_SetWidth(obj,30);
	loop(50){
		Obj_SetAngle(obj,angle+atan2(GetEnemyY-y,GetEnemyX-x));
		ObjLaser_SetLength(obj,l*20);
		l++;
		yield;}
	loop(100){
		Obj_SetAngle(obj,angle+atan2(GetEnemyY-y,GetEnemyX-x));
		yield;}
	Obj_Delete(obj);
	}

task move{
	let wMove = 60;
	moveToPlayer(80,0,wMove,GetClipMinX+48,cy-50,GetClipMaxX-48,cy-50);
	wait(wMove);
	}

function moveToPlayer(xMove,yAdd,frame,left,top,right,bottom){
	let x;
	let y;
	if(GetPlayerX<GetX){//vC[EɓG΁AG͍ɓ܂B
		x=GetX-xMove;
		//AAG̈̍[ɂ悤ȂAEɓ܂B
			if(x<left){
				x=GetX+xMove;
 			}
		} else {
		//Ȃ΁AG͉Eɓ܂B
		x=GetX+xMove;
		// AAG̈̉E[Eɂ悤ȂAɓ܂B
		if(right<x){
			x=GetX-xMove;
			}
		}
	y=GetY+yAdd;
	if(y<top) {
		y=top;
	} else if(bottom<y){
		y=bottom;
		}
	SetMovePosition02(x,y,frame);
	}

function wait(w) {
	loop(w){yield;}
	}
}