#TouhouDanmakufu
#Title[Full_Korbe : "All colors : Maximum Power!"]
#Text[Fully choisit une couleur a la fois pour vous attaquer. Il ne choisit jamais deux fois la meme couleur. Observez le changement de couleurs du fond pour deviner la prochaine attaque et placez-vous en consequence. C'est sa derniere attaque, encore juste un peu !]
#Image[]
#BGM[script\DanMUku\Stage5\fulllast.mp3]
#Player[script\DanMUku\Joueur\KorA\KorHosik.txt, script\DanMUku\Joueur\KorB\KorB.txt, script\DanMUku\Joueur\KorC\KorC.txt]
#ScriptVersion[2]

script_enemy_main
{    
    let imgEnemy ="script\DanMUku\Stage5\Image\fully.png";
    let bg = "script\DanMUku\Stage5\Image\abstrait.png";
    let fg = "script\DanMUku\Stage5\Image\rond.png";
    let count=-60;
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let tir = "script\DanMUku\Stage1\Son\tir.wav";
    let z = 0;
    let w = 0.5;
    let rng=0;
    let old = 0;
    let q=0;
    let spin =0;

	let r=255;
	let g=255;
	let b=255;
	let rc=255;
	let gc=255;
	let bc=255;

    let a;
    let d;
    let c;
    let f;
    let v;

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
	    LoadGraphic(bg);
	    LoadGraphic(fg);
	    LoadSE(tir);
	    LoadSE(munch);
            SetLife(21000);
            SetTimer(120);
	    SetScore(5000000);
            SetInvincibility(160);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100, 120); 
	    SetEffectForZeroLife(60,200,2); 
		SetDamageRate(100,50);
		CutIn(YOUMU, "All colors"\""Maximum Power!"\", "script\DanMUku\Stage5\Image\fullycutin.png" , 0,0,99,200); 
   
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);


	if (count==3480){
		CreateEnemyFromScript("machin", 0, 0, 0, 0, 0);
	}

	if (count>0&&count%600==19) {
		DeleteEnemyShotToItem(CHILD);
		SetMovePositionRandom01(rand(50,100), rand(50,100), 2, GetClipMinX+20, GetClipMinY+30, GetClipMaxX-20, GetCenterY);
		while(rng==old){
			rng = rand_int(1,7);
		}
		old=rng;
		alternative(rng)
		case(1){
			rc=255;
			gc=0;
			bc=0;
		}
		case(2){
			rc=200;
			gc=100;
			bc=0;
		}
		case(3){
			rc=255;
			gc=255;
			bc=0;
		}
		case(4){
			rc=100;
			gc=0;
			bc=200;
		}
		case(5){
			rc=255;
			gc=255;
			bc=255;
		}
		case(6){
			rc=0;
			gc=0;
			bc=255;
		}
		case(7){
			rc=0;
			gc=255;
			bc=0;
		}
		SetColor(rc,gc,bc);
		Concentration01(100);
	}

	if(rng==1){

		if (count%600==120){
			a=rand(GetClipMinX, GetClipMinX+50);
			d=rand(GetClipMinY, GetClipMinY+50);
			f=[];
			v=1;
			loop(8){
				f=f~[rand(100,150)];
			}
		}

		if(count%600>120&&count%3==0){
			v+=0.2;
			PlaySE(tir);
			let x=a;
			let y=GetClipMinY;
			let i =0;
			loop(8){
				Carte_Rouge(x, y, v, 45, 0);
				Carte_Rouge(x, y, v, 135, 0);
				Carte_Rouge(x, y, v, 225, 0);
				Carte_Rouge(x, y, v, 315, 0);
				x+=f[i];
				i++;
				if (x>GetClipMaxX){
					y+=x-GetClipMaxX;
					x=GetClipMaxX;
				}
			}
		}

		if(count%600>120&&count%3==1){
			let x=GetClipMinX;
			let y=d;
			let i=0;
			loop(8){
				Carte_Rouge(x, y, v, 45, 0);
				Carte_Rouge(x, y, v, 135, 0);
				Carte_Rouge(x, y, v, 225, 0);
				Carte_Rouge(x, y, v, 315, 0);
				y+=f[i];
				i++;
				if (y>GetClipMaxY){
					x+=y-GetClipMaxY;
					y=GetClipMaxY;
				}
			}
		}

		if(count%600>120&&count%200==120){
			PlaySE(munch);
			let delay=0;
			loop(6){
				let angle=GetAngleToPlayer-5;
				loop(10){
					Carte_Rouge(GetX, GetY, 5, angle, delay);
					angle+=1;
				}
				delay+=3;
			}
		}

	}

	if (rng==2) {

		if(count%600>120&&count%15==0){
			PlaySE(tir);
			let x = rand(GetClipMinX, GetClipMinX+30);
			loop(15){
				Carte_Marron(x, GetClipMinY, 9, 90, 0);
				x+=rand(30,50);
			}
		}

	}

	if (rng==3) {

		if (count%600==120) {
			a=GetAngleToPlayer;
			if (GetX<GetCenterX) {
				c=-2;
			}
			else{
				c=2;
			}
		}

		if (count%600>120&&count%5==0) {
			let angle = a;
			PlaySE(tir);
			loop(6){
				if (count%52<18){
					Carte_Jaune(GetX, GetY, 2, angle, 0);
				}
				else{
					CreateShot01(GetX, GetY, 2, angle, 51, 0);
				}
				angle+=60;
			}
			a+=c;
		}

	}

	if (rng==4) {

		if (count%600==120) {
			a=GetPlayerX;
			if (a>GetCenterX) {
				c=-6;
			}
			else {
				c=6;
			}
		}

		if (count%600>120&&count%4==0){
			PlaySE(tir);
			if (c<0){
				Carte_Violette(a-70, GetClipMinY, 4, 90, 0);
				CreateShot01(a+70, GetClipMinY, 4, 90, 40, 0);
			}
			else{
				Carte_Violette(a+70, GetClipMinY, 4, 90, 0);
				CreateShot01(a-70, GetClipMinY, 4, 90, 40, 0);
			}
			a+=c;
			if (a>GetClipMaxX-80){
				c=-9;
			}
			if (a<GetClipMinX+80){
				c=9;
			}
		}

	}

	if (rng==5) {
		if (count%600==120){
			a=rand(GetClipMinX, GetClipMinX+50);
			d=rand(GetClipMinY, GetClipMinY+50);
			f=[];
			v=0.5;
			loop(5){
				f=f~[rand(150,200)];
			}
		}

		if(count%600>120&&count%6==0){
			if (v<2) {
				v+=0.075;
			}
			PlaySE(tir);
			let x=a;
			let y=GetClipMinY;
			let i =0;
			loop(5){
				Carte_Blanche(x, y, v, 45, 0);
				Carte_Blanche(x, y, v, 135, 0);
				Carte_Blanche(x, y, v, 225, 0);
				Carte_Blanche(x, y, v, 315, 0);
				x+=f[i];
				i++;
				if (x>GetClipMaxX){
					y+=x-GetClipMaxX;
					x=GetClipMaxX;
				}
			}
		}

		if(count%600>120&&count%6==3){
			let x=GetClipMinX;
			let y=d;
			let i=0;
			loop(5){
				Carte_Blanche(x, y, v, 45, 0);
				Carte_Blanche(x, y, v, 135, 0);
				Carte_Blanche(x, y, v, 225, 0);
				Carte_Blanche(x, y, v, 315, 0);
				y+=f[i];
				i++;
				if (y>GetClipMaxY){
					x+=y-GetClipMaxY;
					y=GetClipMaxY;
				}
			}
		}


	}

	if (rng==6) {

		if (count%600==120) {
			c = GetPlayerX;
			d = GetPlayerY;
			a = rand(0,360);
		}

		if (count%600>120&&count%4==0) {
			PlaySE(tir);
			let angle = a;
			loop(6){
				Carte_Bleue(c+cos(angle)*70, d+sin(angle)*70, 9, angle+45, 30);
				angle+=60;
			}
			a-=4;
		}

	}

	if (rng==7) {

		if (count%600>120&&count%5==0){
			PlaySE(tir);
			Carte_Verte(GetX, GetY, 4, rand(0,360), 0);
			Carte_Verte(GetClipMinX, GetCenterY-80, 4, rand(280,420), 0);
			Carte_Verte(GetClipMaxX, GetCenterY-80, 4, rand(120,260), 0);
		}

	}

	count++;
	yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);
   }
   
   @DrawLoop
   {
	if(r<rc){r+=3;}
	if(r>rc){r-=3;}
	if(g<gc){g+=3;}
	if(g>gc){g-=3;}
	if(b<bc){b+=3;}
	if(b>bc){b-=3;}

	SetColor(r,g,b);
	SetRenderState(ALPHA);
            SetAlpha(255);
            SetTexture(bg);
	    SetGraphicAngle(0, 0, 0);
            SetGraphicRect(q, -q, 640+q, 480-q);
            DrawGraphic(GetCenterX,GetCenterY);

	SetRenderState(ALPHA);
            SetAlpha(100);
            SetTexture(fg);
	    SetGraphicAngle(0, 0, spin);
            SetGraphicRect(0, 0, 544, 416);
	    SetGraphicScale(2,2);
            DrawGraphic(GetCenterX,GetCenterY);

            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetTexture(imgEnemy);
	    SetGraphicScale(1,1);
	    SetGraphicAngle(0, 0, 0);
            SetGraphicRect(0, 0, 35, 46);
            DrawGraphic(GetX,GetY+z);
     if(z==10){w=-0.5;}
     if(z==-10){w=0.5;}
z+=w;
spin+=0.5;
q+=1;
	DrawText("Full_Korbe", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }


   task Carte_Jaune(x, y, v, angle, delay)
   {
            let obj=Obj_Create(OBJ_SHOT);

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, 144);
            ObjShot_SetDelay  (obj, delay);
      let counter=0;

            while(Obj_BeDeleted(obj)==false)
      {
                    if(Obj_GetX(obj)<GetClipMinX&&counter==0)
         {
                          Obj_SetAngle(obj,  180-Obj_GetAngle(obj) );
                          Obj_SetX(obj,  Obj_GetX(obj) + 0.1);
	        ObjShot_SetGraphic(obj, 50);
            counter++;
                    }

                    if(Obj_GetX(obj)>GetClipMaxX&&counter==0)
         {
                          Obj_SetAngle(obj,  180-Obj_GetAngle(obj) );

                          Obj_SetX(obj,  Obj_GetX(obj) - 0.1);
	        ObjShot_SetGraphic(obj, 50);
            counter++;
                    }

                    if(Obj_GetY(obj)<GetClipMinY&&counter==0)
         {
	        Obj_SetAngle(obj, -Obj_GetAngle(obj) );
                          Obj_SetY(obj,  Obj_GetY(obj) + 0.1);
	        ObjShot_SetGraphic(obj, 50);
            counter++;
                    }

         yield;
            }
   }

   task Carte_Violette(x, y, v, angle, delay)
   {
            let obj=Obj_Create(OBJ_SHOT);

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, 141);
            ObjShot_SetDelay  (obj, delay);
      let counter=0;

            while(Obj_BeDeleted(obj)==false)
      {
                    if(Obj_GetY(obj)>GetClipMaxY&&counter==0)
         {
	        Obj_SetAngle(obj, rand(190, 350) );
		Obj_SetSpeed(obj, v/2);
                          Obj_SetY(obj,  Obj_GetY(obj) + 0.1);
	        ObjShot_SetGraphic(obj, 137);
            counter++;
                    }

         yield;
            }
   }

   task Carte_Rouge(x, y, v, angle, delay)
   {
	CreateShot02(x, y, 0, angle, 0.05, v, 140, delay);
   }

   task Carte_Marron(x, y, v, angle, delay)
   {
	CreateShot02(x, y, v, angle, -0.1, v/10, 145, delay);
   }

   task Carte_Blanche(x, y, v, angle, delay)
   {
	CreateShotA(1, x, y, delay);
	SetShotDataA(1, 0, v, angle, -1, 0, v, 146);
	SetShotDataA(1, 60, NULL, NULL, 1, 0, v, 146);
	SetShotDataA(1, 120, NULL, NULL, -1, 0, v, 146);
	SetShotDataA(1, 180, NULL, NULL, 1, 0, v, 146);
	SetShotDataA(1, 240, NULL, NULL, -1, 0, v, 146);
	FireShot(1);
   }

   task Carte_Verte(x, y, v, angle, delay)
   {
            let obj=Obj_Create(OBJ_SHOT);

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, 143);
            ObjShot_SetDelay  (obj, delay);
		let count = 0;

	while(Obj_BeDeleted(obj)==false)
      {
	if (count<100) {
		Obj_SetSpeed(obj, Obj_GetSpeed(obj)-v/100);
	}	
	if (count==100) {
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetSpeed(obj, v);
	}

	count++;
	yield;
      }

   }

   task Carte_Bleue(x, y, v, angle, delay)
   {
            let obj=Obj_Create(OBJ_SHOT);

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, 142);
            ObjShot_SetDelay  (obj, delay);
		let count = 0;
		let dir = 0;
		let phase = 1;
		let count = 0;
		let alea = rand_int(130,200);

		if (angle%360>270||(angle%360>90&&angle%360<180)) {
			dir=5;
		}
		else {
			dir=-5;
		}

	while(Obj_BeDeleted(obj)==false)
      {
	if (phase==1){
		Obj_SetSpeed(obj, Obj_GetSpeed(obj)-v/100);
		if (count==100) {
			phase = 2;
		}
	}

	if (phase==2){
		Obj_SetAngle(obj, Obj_GetAngle(obj)+dir);
		if ( count==alea ) {
			phase = 3;
		}
	}

	if (phase==3){
		Obj_SetSpeed(obj, Obj_GetSpeed(obj)+0.03);
	}

	count++;
	yield;
      }

   }

}

script_enemy machin
{     
    let imgEnemy="script\DanMUku\Stage1\Image\Machin.png";
    let count=-120;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let z = 0;
    let w = 0.5;

 function Wait(let frames){
   loop(frames){yield;}
 }

   @Initialize
   {
      LoadGraphic(imgEnemy);
		SetLife(10);
            SetMovePosition02(GetCenterX, GetCenterY - 100, 120);        
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
	SetDamageRateEx(0,0,50,30);

	if ( absolute(GetX-GetEnemyX)<50 && absolute(GetY-GetEnemyY)<50 ) {
		SetMovePositionRandom01(30, 30, 2, GetClipMinX+20, GetClipMinY+20, GetClipMaxX-20, GetCenterY);
	}

	if(count%600<120&&count%50==49)
	{
		let a=GetAngleToPlayer;
		PlaySE(tir);
		loop(36)
		{
			CreateShot01(GetX, GetY, 2, a, BLUE01, 0);
			Circle(GetX, GetY, 2, a+5, 0);
			a+=10;
		}
	}

count++;
yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);
   }

   task Circle(x, y, v, angle, delay) {
      let obj_idd=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj_idd, x, y);
     Obj_SetAngle(obj_idd, angle);
     Obj_SetSpeed(obj_idd, v);
     ObjShot_SetGraphic(obj_idd, BLUE01);
     ObjShot_SetDelay  (obj_idd, delay);
     Wait(50);
     ObjShot_SetGraphic(obj_idd, GREEN01);
     Obj_SetSpeed(obj_idd, v*2);
     while(Obj_BeDeleted(obj_idd)==false) {
             yield;
      }
}

   @DrawLoop
   {
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicRect(0,0,16*1.5,16*1.5);
            DrawGraphic(GetX,GetY+z);
     if(z==10){w=-0.5;}
     if(z==-10){w=0.5;}
z+=w;
   }

}
