#Title[毒符「ポイズンビー」]
#Text[メディスン・メランコリーのスペルカード]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd=GetCurrentScriptDirectory;
        let imgBoss=csd~"img\dot_medicine.png";
        let name="毒符「ポイズンビー」";
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
        let angle=0;
        let imgALPHA=255;
	let Flag=false;
	let shotseA=csd~"se\ShotSE03.wav";

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

		SetLife(600);
		SetTimer(55);
		SetScore(1750000);
		SetDamageRate(20,20);
		SetInvincibility(100);
		LoadGraphic(imgBoss);
		LoadUserShotData(csd~"img\PLUS_shot.txt");
		TAnime1;
	}

        @MainLoop
        {
	if(count>=200&&count%400==200){
		let i=0;
        	while(i<10){
        		SetShotDirectionType(PLAYER);
        		CreateShotA(1,GetX,GetY,0);
        		SetShotDataA(1,0,1,36*i,0,0,1,36);
        		FireShot(1);
        		CreateShotA(1,GetX,GetY,0);
        		SetShotDataA(1,0,2,36*i,0,0,2,36);
        		FireShot(1);
        		CreateShotA(1,GetX,GetY,0);
        		SetShotDataA(1,0,3,36*i,0,0,3,36);
        		FireShot(1);
        		i++;
			}
		let i=0;
		while(i<8){
			CreateEnemyFromScript("DOLLA",GetX,GetY,1,i*45,0);
			i++;
			}
		SetMovePosition02(GetPlayerX,GetPlayerY,1);
		Flag=true;
		imgALPHA=0;
		}
	if(count>=200&&count%400==350){
		Flag=false;
        	imgALPHA=255;
		}
	if(Flag==false){
		SetCollisionA(GetX(),GetY(),18);
		SetCollisionB(GetX(),GetY(),18);
		}
        count++;
        yield;
        }

       @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(imgALPHA);
		SetColor(255,255,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 {
		if(!IsTimeOut){
			CreateItem(ITEM_1UP,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);
	}

    	task TAnime1{
		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;}
		}
}

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

	@Initialize
	{
		SetLife(40000);
        	SetDamageRateEx(100,100,50,2);
        	TAnime1;
	}
	
	@MainLoop
	{
	if(count==2){
		SetMovePositionHermite(GetEnemyX,GetEnemyY,750,angle,10,atan2(GetY-GetEnemyY,GetX-GetEnemyX),148);
        	}
	if(count>=2&&count<=149&&count%4==2){
		PlaySE(shotseA);
		SetShotDirectionType(ABSOLUTE);
		let shotA=0;
		CreateShotA(shotA,GetX,GetY,5);
		SetShotDataA(shotA,0,0,angle,0,0.0,0,67);
		SetShotDataA(shotA,150-count,0,NULL,0,0.01,1.5,67);
		FireShot(shotA);
		CreateShotA(shotA,GetX,GetY,5);
		SetShotDataA(shotA,0,0,angle-180,0,0.0,0,67);
		SetShotDataA(shotA,150-count,0,NULL,0,0.01,1.5,67);
		FireShot(shotA);
		angle=angle-30;
		}

	if(count>=150&&Flag==false){
		Flag=true;
		}
	if(GetLife<=100&&Flag==false){
		SetMovePosition01(GetX,GetY+100,1);
		PlaySE(deathse);
		Flag=true;
		}
	if(Flag==true){
		imgAngle+=15;
		imgAlpha-=5;
		if(imgAlpha<=0){VanishEnemy();}
		} else {
		SetCollisionA(GetX(),GetY(),10);
		SetCollisionB(GetX(),GetY(),10);
		}
	count++;
	yield;
	}
	
	@Finalize{
	}
	
	@DrawLoop{
		SetGraphicRect(767+32*AnimationC,32*AnimationB,798+32*AnimationC,31+32*AnimationB);
		SetTexture(imgBoss);
		SetGraphicAngle(0,0,imgAngle);
		SetAlpha(imgAlpha);
		DrawGraphic(GetX(),GetY());
	}

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