#Title[チルノ]
#Text[チルノの通常８]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let angle=0;
        let csd     = GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_cirno.png";
	let shotse = csd~"se\ShotSE02.wav";

	@Initialize
	{
	SetLife(3000);
	SetTimer(50);
        SetDamageRate(100,100);
        SetInvincibility(200);
	LoadGraphic(imgBoss);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
	SetEnemyMarker(true);
        TAnime;
	}
	
	@MainLoop
	{
	if(count==150){
		Concentration01(60);}
	if(count>=240&&count%90==0){
        	TAnime2;
		move;
        	}
	if(count>=200&&count%20==0){
		PlaySE(shotse);
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,1.4,i*18+angle-12,0,0,0,56);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==1){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,1.8,i*18+angle-9,0,0,0,53);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==2){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,2.2,i*18+angle-6,0,0,0,53);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==3){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,2.6,i*18+angle-3,0,0,0,54);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==4){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,3,i*18+angle,0,0,0,54);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==10){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,1.4,i*18+angle+12,0,0,0,56);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==21){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,1.8,i*18+angle+9,0,0,0,53);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==22){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,2.2,i*18+angle+6,0,0,0,53);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==23){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,2.6,i*18+angle+3,0,0,0,54);
			FireShot(shotA);
			i=i+1;
			}
		}
	if(count>=200&&count%40==24){
		let i=0;
		while(i<20){
        		SetShotDirectionType(PLAYER);
			let shotA=0;
			CreateShotA(shotA,GetX(),GetY(),5);
			SetShotDataA(shotA,0,3,i*18+angle,0,0,0,54);
			FireShot(shotA);
			i=i+1;
			}
		}
        SetCollisionB(GetX(),GetY(),22);
	SetCollisionA(GetX(),GetY(),22);
        count++;
        yield;
	}
	
        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		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
        {
        }

	task TAnime{
		loop{
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			AnimationB=3;
        		loop(10){yield;}
			}
		}

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

task move{
	let wMove = 60;
	moveToPlayer(rand(40,80),rand(-40,40),wMove,GetClipMinX+48,GetClipMinY+32,GetClipMaxX-48,GetClipMinY+128);
	wait(wMove);
	}

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;
		}
	SetMovePosition02(x,y,frame);
	}
function wait(w) {
	loop(w){yield;}
	}
}