#Title[アリス]
#Text[アリスの通常１]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=75;
        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_EXalice.png";
        let imgBoss2=csd~"img\dot_yousei.png";

	@Initialize
	{
        SetLife(2000);
        SetTimer(35);
        SetDamageRate(100,100);
	SetX(498);
	SetY(200);
	SetEnemyMarker(true);
	SetMovePosition02(GetCenterX,150,75);
        SetInvincibility(125);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBoss2);
	SetEnemyMarker(true);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
        TAnime;
	}
	
	@MainLoop
	{
	if(count>=300&&count%200==100){
        	TAnime2;
		move;
        	}
	if(count>=200&&count%200==0){
		CreateEnemyFromScript("DOLLA",GetX,GetY,0,0,0);
		CreateEnemyFromScript("DOLLB",GetX,GetY,0,0,0);
		CreateEnemyFromScript("DOLLC",GetX,GetY,0,0,0);
		}
        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
        {
		DeleteGraphic(imgBoss);
		DeleteGraphic(imgBoss2);
        }

	task TAnime{
		loop{
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		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;}
	}
}

script_enemy DOLLA{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei.png";
	let angle=0;
	let imgAngle=0;
	let imgAlpha=255;
	let deathse=csd~"se\DEATH.wav";
	let Flag=false;
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(400);
        SetDamageRateEx(100,100,10,10);
        SetInvincibility(50);
	SetMovePosition02(rand(100,348),rand(100,200),50);
        TAnime;
	}

	@MainLoop {
	if(count>=250&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(GetLife<=100&&Flag==false){
			PlaySE(deathse);
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(Flag==true){
		imgAngle+=15;
		imgAlpha-=5;
		if(imgAlpha<=0){VanishEnemy();}
		} else {
		SetCollisionA(GetX(),GetY(),10);
		SetCollisionB(GetX(),GetY(),10);
		}
	if(count>=50&&count%10==0&&Flag==false){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		let i=0;
		while(i<3){
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,1,i*120+90+angle,0,0,1,216);
			FireShot(shotA);
			i++;
			}
		angle-=15;
		}
	count++;
	yield;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,64,31+Animation*32,95)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation*32,96,159+Animation*32,127);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation*32,96,31+Animation*32,127);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        } 

    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}

script_enemy DOLLB{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei.png";
	let angle=0;
	let imgAngle=0;
	let imgAlpha=255;
	let deathse=csd~"se\DEATH.wav";
	let Flag=false;
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(400);
        SetDamageRateEx(100,100,10,10);
        SetInvincibility(50);
	SetMovePosition02(rand(100,348),rand(100,200),50);
	LoadGraphic(imgBoss2);
        TAnime;
	}

	@MainLoop {
	if(count>=250&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(GetLife<=100&&Flag==false){
			PlaySE(deathse);
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(Flag==true){
		imgAngle+=15;
		imgAlpha-=5;
		if(imgAlpha<=0){VanishEnemy();}
		} else {
		SetCollisionA(GetX(),GetY(),10);
		SetCollisionB(GetX(),GetY(),10);
		}
	if(count>=50&&count%10==0&&Flag==false){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		let i=0;
		while(i<3){
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,1,i*120+90+angle,0,0,1,214);
			FireShot(shotA);
			i++;
			}
		angle+=15;
		}
	count++;
	yield;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,128,31+Animation*32,159)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation*32,160,159+Animation*32,191);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation*32,160,31+Animation*32,191);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        } 

    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}

script_enemy DOLLC{
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei.png";
	let angle=0;
	let imgAngle=0;
	let imgAlpha=255;
	let deathse=csd~"se\DEATH.wav";
	let Flag=false;
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(400);
        SetDamageRateEx(100,100,10,10);
        SetInvincibility(50);
	SetMovePosition02(rand(100,348),rand(100,200),50);
	LoadGraphic(imgBoss2);
        TAnime;
	}

	@MainLoop {
	if(count>=250&&Flag==false){
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(GetLife<=100&&Flag==false){
			PlaySE(deathse);
			SetMovePosition01(GetX,GetY+100,1);
			Flag=true;
			}
	if(Flag==true){
		imgAngle+=15;
		imgAlpha-=5;
		if(imgAlpha<=0){VanishEnemy();}
		} else {
		SetCollisionA(GetX(),GetY(),10);
		SetCollisionB(GetX(),GetY(),10);
		}
	if(count>=50&&count%10==0&&Flag==false){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		let i=0;
		while(i<3){
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,1.5,i*120+90+angle,0,0,1.5,211);
			FireShot(shotA);
			i++;
			}
		angle=rand(0,360);
		}
	count++;
	yield;
	}

        @DrawLoop {
		SetTexture(imgBoss2);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		if(int(GetSpeedX())==0)
		{SetGraphicRect(Animation*32,0,31+Animation*32,31)}
		else if(GetSpeedX()>0){SetGraphicRect(128+Animation*32,32,159+Animation*32,63);}
		else if(GetSpeedX()<0){SetGraphicRect(Animation*32,32,31+Animation*32,63);}
		DrawGraphic(GetX(),GetY());
	}

        @Finalize
        {
        } 

    	task TAnime{
		loop{
			Animation=0;
        		loop(10){yield;}
			Animation=1;
        		loop(10){yield;}
			Animation=2;
        		loop(10){yield;}
			}
		}
}