#Title[槍符「人形千槍」]
#Text[アリスのスペルカード]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
        let count=0;
        let name="槍符「人形千槍」";
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\dot_EXalice.png";
        let imgBoss2=csd~"img\dot_yousei.png";
        let angle=0;
        let i=0;
	let Motion=0;
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        CutIn(YOUMU,name,0,0,0,0,0);
        SetLife(600);
        SetTimer(40);
        SetScore(1500000);
        SetDamageRate(30,30);
        SetInvincibility(200);
        SetMovePosition02(GetCenterX(),150,50);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBoss2);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
        TAnime1;
    }

        @MainLoop
        {
	if(count==150){
		Concentration01(60);
		}
	if(count==200){
		angle=GetAngleToPlayer;
		i=0;
		}
	if(count>=200&&count<=220&&count%5==0){
		CreateEnemyFromScript("DOLL",GetX,GetY,2,angle-40,i);
		angle+=20;
		i++;
		}
	if(count==250){
                TAnime2;
		move;
		}
	if(count>=250&&count%10==0){
		PlaySE(shotseA);
        	SetShotDirectionType(PLAYER);
		let i=0;
		while(i<7)
		{
			let shotA=0;
			CreateShotA(shotA,GetX,GetY,0);
			SetShotDataA(shotA,0,2,i*20-60,0,0,2,66);
			FireShot(shotA);
			i++;
			}
		}
	if(count==300){
                count=149;
		}
        	SetCollisionA(GetX(),GetY(),18);
        	SetCollisionB(GetX(),GetY(),18);
        	count++;
        yield;

}
    @Finalize {
		if(!IsTimeOut){
			CreateItem(ITEM_BOMB,GetX,GetY);
			loop(50){
				angle=rand(0,360);
				CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,45),GetY+sin(angle)*rand(35,45));
			}
		}
		DeleteGraphic(imgBoss);
		DeleteGraphic(imgBoss2);
    }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		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 {SetGraphicRect(256,128*AnimationA,383,127+128*AnimationA);}
		DrawGraphic(GetX(),GetY());
		}

    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(16){yield;}
			AnimationB=1;
        		loop(56){yield;}
			AnimationB=0;
        		loop(8){yield;}
		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(30){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}

task move {
    let wMove = 60;

    moveToPlayer(rand(60,120),rand(-80,80),wMove,GetClipMinX+48,GetClipMinY+64,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 DOLL{
        let count=GetArgument*5;
        let cx=GetCenterX();
        let cy=GetCenterY();
	let Animation=0;
        let csd=GetCurrentScriptDirectory;
        let imgBoss2=csd~"img\dot_yousei.png";
	let angle=GetAngle;
	let angle2=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
	let imgAngle=0;
	let imgAlpha=255;
	let Flag=false;
	let shotseA=csd~"se\ShotSE02.wav";

    @Initialize {
        SetLife(10000);
        SetDamageRateEx(0,0,100,5);
        SetInvincibility(50);
        TAnime;
	}

	@MainLoop {
	if(count>=200&&Flag==false){
			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){
		SetMovePosition01(GetX,GetY,1);
		}
	if(count>=50&&count%5==0&&Flag==false){
        	SetShotDirectionType(ABSOLUTE);
		PlaySE(shotseA);
		CreateLaser01(GetX,GetY,rand(3,5),angle2+rand(-65,65),100,10,216,0);
		}
	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;}
			}
		}
}