#TouhouDanmakufu
#Title[Full_Korbe NSC02]
#Text[Boss du stage 5, 2nde NSC]
#Image[]
#BGM[script\DanMUku\Stage5\fully.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 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;

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
	    LoadSE(tir);
	    LoadSE(munch);
            SetLife(4000);
            SetTimer(40);
            SetInvincibility(160);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100, 120);     
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

	if (count>0&&count%100==1) {
		SetMovePositionRandom01(rand(50,70), rand(50,100), 2, GetClipMinX+10, GetClipMinY+10, GetClipMaxX-10, GetCenterY);
		rng = rand_int(1,7);
		alternative(rng)
		case(1){
			SetColor(255,0,0);
		}
		case(2){
			SetColor(200,100,0);
		}
		case(3){
			SetColor(255,255,0);
		}
		case(4){
			SetColor(100,0,200);
		}
		case(5){
			SetColor(255,255,255);
		}
		case(6){
			SetColor(0,0,255);
		}
		case(7){
			SetColor(0,255,0);
		}
		Concentration01(35);
	}

	if (count>0&&count%100==40){
		alternative(rng)
		case(1) {
			let delay=0;
			loop(4) {
				PlaySE(tir);
				let a = GetAngleToPlayer-100+delay;
				loop(20) {
					Carte_Rouge(GetX, GetY, 5, a, delay);
					a+=10;
				}
				delay+=10;
			}
		}
		case(2){
			let delay=0;
			loop(6) {
				PlaySE(tir);
				let a = GetAngleToPlayer-100+delay;
				loop(20) {
					Carte_Marron(GetX, GetY, 5, a, delay);
					a+=10;
				}
				delay+=5;
			}
		}
		case(3){
			let delay=0;
			loop(5){
				PlaySE(tir);
				let a = GetAngleToPlayer;
				loop(15){
					Carte_Jaune(GetX, GetY, 2, a, delay);
					a+=360/15;
				}
				delay+=5;
			}
		}
		case(4){
			let a=0;
			let delay=0;
			loop(3) {
				PlaySE(tir);
				loop(12) {
					Carte_Violette(GetX+cos(-a)*60, GetY+sin(-a)*30, 2, -a, delay); 
					a-=180/12;
					delay+=2;
				}
				a=3;
				delay+=10;
			}
		}
		case(5) {
			let delay=0;
			PlaySE(munch);
			loop(5){
				let a = GetAngleToPlayer-70;
				loop(16){
					Carte_Blanche(GetX, GetY, 2, a, delay);
					a+=10;
				}
				delay+=5;
			}
		}
		case(6){
			PlaySE(munch);
			let a=GetAngleToPlayer;
			loop(36){
				Carte_Bleue(GetX, GetY, 2, a, 0);
				a+=10;
			}
		}
		case(7){
			PlaySE(munch);
			loop(100){
				Carte_Verte(GetX, GetY, 3, rand(0,360), rand(0,40));
			}
		}
	}

	count++;
	yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);
   }
   
   @DrawLoop
   {
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetTexture(imgEnemy);
            SetGraphicRect(0, 0, 35, 46);
            DrawGraphic(GetX,GetY+z);
     if(z==10){w=-0.5;}
     if(z==-10){w=0.5;}
z+=w;
	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.1, 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;
      }

   }

}
