#TouhouDanmakufu
#Title[FdRstar : "Refraction : Prismatic stream"]
#Text[Un veritable arc-en-ciel de danmaku se deploie contre vous ! L'eau et la lumiere sont vitales a tous types de fleurs (enfin presque), elles les absorbent pour grandir et s'epanouir. Les fleurs peuvent arborer de nombreuses couleurs differentes mais aucune n'est comparable a la beaute d'un arc-en-ciel.]
#Image[]
#BGM[script\DanMUku\Stage4\FdRstar.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\Stage4\Image\fdrstar.png";
    let count = -200;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let a=0;
    let b=55;
    let x=GetX;
    let c=0;
    let dif=3;
    let dir=0;
    let q=0;
    let bg = "script\DanMUku\Stage4\Image\eau.png";


   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
	    LoadGraphic(bg);
            SetLife(6000);
            SetTimer(60);
            SetInvincibility(200);
            SetEnemyMarker(true);
            SetScore(1800000);
            CutIn(YOUMU, "Refraction "\""Prismatic stream"\", "script\DanMUku\Stage4\Image\FdRcutin.png", 0,0,121,214);
            SetMovePosition02(GetCenterX, GetCenterY-100, 50);   
           
   }
   
   @MainLoop
   {
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
if(count%10==0){
	if(a==0){a=55;b=112;c=0;}
	else if(a==55&&c==0){a=112;b=168;}
	else if(a==55&&c==1){a=0;b=55;}
	else{a=55;b=112;c=1;}

	if(count==-200){
		CreateLaserA(1, 0, 0, 500, 20, 4, 0);
		SetLaserDataA(1, 0, 0, 0, 0, 2, 90);
		SetLaserDataA(1, 145, 0, 0, 0, 0, 90);
		FireShot(1);
		CreateLaserA(2, 0, 0, 500, 20, 4, 0);
		SetLaserDataA(2, 0, 0, 0, 0, 0, 90);
		SetLaserDataA(2, 60, 0, 0, 0, 2, 90);
		SetLaserDataA(2, 155, 0, 0, 0, 0, 90);
		FireShot(2);
		}


	if(count%120==0&&count>0)
	{
	SetMovePositionRandom01(50, 50, 2, GetClipMinX+10, GetClipMinY+10, GetClipMaxX-10, GetCenterY-60);
	dir=GetAngleToPlayer-10*dif/2;
	PlaySE(tir);
	loop(dif){
		Lumiere(GetX, GetY, 2, dir, 9);
		dir+=10;
	}
	}

	if(count%240==0&&count>0){
	dif++;
	}

	if(count>0){
	Lumiere(rand(GetClipMinX, GetClipMaxX), 0, rand(0.8, 2), rand(45, 135), 9);
	}
	if(dif>5){
	Lumiere(rand(GetClipMinX, GetClipMaxX), 0, rand(0.8, 2), rand(45, 135), 9);
	}
	if(dif>12){
	Lumiere(rand(GetClipMinX, GetClipMaxX), 0, rand(0.8, 2), rand(45, 135), 9);
	}

}

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

	    SetTexture(bg);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetGraphicRect(0, 0, 50000+q, 50000+q);
            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX+q, GetCenterY+q);

	if(x>GetX){
		SetGraphicAngle(180,0,0);
	}
	if(x<GetX){
		SetGraphicAngle(0,0,0);
	}
      x=GetX;
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicRect(a, 0, b, 64);
            DrawGraphic(GetX,GetY);

	DrawText("FdRstar", GetClipMinX+10, GetClipMinY+15, 12, 255);
	q-=2;
   }


	task Lumiere(x, y, v, angle, graphic){

            let obj=Obj_Create(OBJ_SHOT);
    		let indice= [0.90, 0.30, 0, 0, 0.40, 0, 0.50, 0, 0.60, 0, 0, 0.70, 0.80];
		let s=0;
		let i=0;
            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, graphic);

	while(Obj_BeDeleted(obj)==false){
		if(graphic==9){
			if(Obj_GetY(obj)>GetCenterY-55){
						loop(13){
							if(indice[i]!=0){
									if(angle>90){
										s=180-asin(indice[i]*sin(angle));
										}else{
										s=asin(indice[i]*sin(angle));
										}
								Lumiere(Obj_GetX(obj), Obj_GetY(obj), v, s, i+11);
							}
						i=i+1;
						}
					Obj_Delete(obj);
				}
			}
		else{
			if(Obj_GetY(obj)>GetCenterY+45){
				if(angle>90){
				s=180-asin(sin(angle)/indice[graphic-11]);
				}else{
				s=asin(sin(angle)/indice[graphic-11]);
				}
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), v, s, graphic,0);
				Obj_Delete(obj);
			}
		}
	yield;
	}
	}
}
