#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 l=0;
	let shotseA=csd~"se\ShotSE02.wav";
	let shotseB=csd~"se\BOM.wav";
	let Flag=false;

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

		SetLife(600);
		SetTimer(55);
		SetScore(1750000);
		SetDamageRate(20,20);
		SetInvincibility(100);
		SetMovePosition02(cx,120,60);
		LoadGraphic(imgBoss);
		LoadUserShotData(csd~"img\PLUS_shot.txt");
		SetEffectForZeroLife(30,0,0);
		TAnime1;
	}

        @MainLoop
        {
	if(count==100){
		SetColor(255,0,255);
		Concentration01(100);
		}
	if(count==200){
		PlaySE(shotseB);
		}
	if(count>=200&&count<=250){
        	SetShotDirectionType(ABSOLUTE);
		let i=0;
		while(i<30){
        		let shot01=1;
        		CreateShotA(shot01,GetX+cos(i*12+angle)*(30+l*15),GetY+sin(i*12+angle)*(30+l*15),100);
        		SetShotDataA(shot01,0,0.1,rand(0,360),0,0,0,227);
			let j=149;
			while(j<150){
				let id2=2;
				CreateShotA(id2,0,0,20);
				SetShotDataA(id2,0,0,rand_int(0,120)*3,0,0,0,227);
				SetShotKillTime(id2,0);
				AddShot(j,shot01,id2,0);
				j++;
				}
			SetShotKillTime(shot01,150);
        		FireShot(shot01);
			i++;
			}
		angle=rand(0,360);
		DeleteEnemyShotInCircle(SHOT,GetPlayerX,GetPlayerY,50);
		l++;
		}
	if(count>=200&&count<=250&&!Flag){
		AddLife(1)
		}
	if(count>=350&&count<=425&&count%2==0){
		PlaySE(shotseA);
        	SetShotDirectionType(ABSOLUTE);
		let i=0;
		while(i<4){
        		let shot01=1;
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,1,i*90+angle,0,0,0,107);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,1.5,i*90+angle+2,0,0,0,107);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,2,i*90+angle+4,0,0,0,107);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,2.5,i*90+angle+6,0,0,0,107);
        		FireShot(shot01);
			i++;
			}
		angle+=50;
		}
	if(count==450){
		SetColor(255,0,255);
		Concentration01(100);
        	TAnime2;
		move;
		l=0;
		}
	if(count==550){
		PlaySE(shotseB);
		}
	if(count>=550&&count<=600){
        	SetShotDirectionType(ABSOLUTE);
		let i=0;
		while(i<30){
        		let shot01=1;
        		CreateShotA(shot01,GetX+cos(i*12+angle)*(30+l*15),GetY+sin(i*12+angle)*(30+l*15),100);
        		SetShotDataA(shot01,0,0.1,rand(0,360),0,0,0,227);
			let j=149;
			while(j<150){
				let id2=2;
				CreateShotA(id2,0,0,20);
				SetShotDataA(id2,0,0,rand_int(0,120)*3,0,0,0,227);
				SetShotKillTime(id2,0);
				AddShot(j,shot01,id2,0);
				j++;
				}
			SetShotKillTime(shot01,150);
        		FireShot(shot01);
			i++;
			}
		angle=rand(0,360);
		DeleteEnemyShotInCircle(SHOT,GetPlayerX,GetPlayerY,50);
		l++;
		}
	if(count>=550&&count<=600){
		AddLife(1)
		}
	if(count>=700&&count<=775&&count%2==0){
		PlaySE(shotseA);
        	SetShotDirectionType(ABSOLUTE);
		let i=0;
		while(i<4){
        		let shot01=1;
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,1,i*90+angle,0,0,0,107);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,1.5,i*90+angle-2,0,0,0,107);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,2,i*90+angle-4,0,0,0,107);
        		FireShot(shot01);
        		CreateShotA(shot01,GetX+cos(i*90+angle)*15,GetY+sin(i*90+angle)*15,5);
        		SetShotDataA(shot01,0,2.5,i*90+angle-6,0,0,0,107);
        		FireShot(shot01);
			i++;
			}
		angle-=50;
		}
	if(count==800){
		SetColor(255,0,255);
		Concentration01(100);
        	TAnime2;
		move;
		l=0;
		count=100;
		}
        if(GetEnemyLife<1&&!Flag){
		Flag=true;
		Explosion01(GetX(),GetY(),1/60*255,0.3,60);
		PlaySE(shotseB);
        	}
	SetCollisionA(GetX(),GetY(),18);
	SetCollisionB(GetX(),GetY(),18);
        count++;
        yield;
        }

       @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		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 {
		PlaySE(shotseB);
		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(80){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}


task move{
	let wMove=100;
	moveToPlayer(rand(100,150),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;}
	}
}