#TouhouDanmakufu
#Title[Seud : "SOB : Suggestive Optical Barrier"]
#Text[Seud utilise maintenant sa technologie de camouflage sur ses tirs ! Faites bien attention a ce qui arrive pour prevoir la trajectoire des tirs, meme invisibles, ils peuvent vous toucher !]
#Image[]
#BGM[script\DanMUku\Stage5\Stage5.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\seud.png";
    let count = -100;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let laser ="script\DanMUku\Stage2\Son\laser.wav";
    let v = 0.5;
    let a=1;
    let rythme = 800;
    let bullets = [];
	let i = 0;
    let q=0;
    let bg = "script\DanMUku\Stage1\Image\etoiles.png";

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
	    LoadGraphic(bg);
	    LoadSE(tir);
	    LoadSE(munch);
	    LoadSE(laser);
	    MagicCircle(false);
            SetLife(4000);
            SetTimer(70);
            SetInvincibility(100);
            SetMovePosition02(GetCenterX, GetCenterY-100, 50);   
            SetScore(2000000);
            CutIn(YOUMU, "SOB : Suggestive Optical Barrier", "script\DanMUku\Stage5\Image\seudcutin.png" , 0,0,121,214);               
   }
   
   @MainLoop
   {
	SetEnemyMarker(false);
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

if (count>0)
{
	if(count%60==0)
	{
		SetMovePositionRandom01(rand(50,200), rand(50,100), 2, GetClipMinX+10, GetClipMinY+10, GetClipMaxX-10, GetCenterY);
		let angle=rand(-40,20);	
		loop(4){
			Invisible(GetX+cos(angle)*50, GetY+sin(angle)*50, angle, 2, 0, RED03);
			angle+=360/16;
		}
		Invisible(GetX+cos(angle)*50, GetY+sin(angle)*50, angle, 2, 0, WHITE03);
		angle+=360/16;
		loop(4){
			Invisible(GetX+cos(angle)*50, GetY+sin(angle)*50, angle, 2, 0, AQUA03);
			angle+=360/16;
		}
	}

	if (count%100==0){
		let angle=0;
		loop(30) {
			Invisible(GetX+cos(angle)*100, GetY+sin(angle)*100, atan2(GetPlayerY-(GetY+sin(angle)*100), GetPlayerX-(GetX+cos(angle)*100))-20, 2, 0, 10);
			angle+=360/30;
		}
	}

	if (count%100==30){
		let angle=0;
		loop(30) {
			Invisible(GetX+cos(angle)*100, GetY+sin(angle)*100, atan2(GetPlayerY-(GetY+sin(angle)*100), GetPlayerX-(GetX+cos(angle)*100))+20, 2, 0, 17);
			angle+=360/30;
		}
	}

	if(count>1000&&count%100==60){
		let angle=rand(0,360);
		loop(30){
			Invisible(GetX+cos(angle)*100, GetY+sin(angle)*100, angle-1, 2, -0.3, 10);
			angle+=360/30;
		}
		loop(30){
			Invisible(GetX+cos(angle)*100, GetY+sin(angle)*100, angle+1, 2, 0.3, 17);
			angle+=360/30;
		}
	}
}

count++;
yield;
   }
   @Finalize
   {
loop(25)
{
CreateItem(ITEM_SCORE, rand(GetX-20, GetX+20), rand(GetY-20, GetY+20));  
}
      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 (GetHitCount>0) {
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicAngle (0, 0, 0);
            SetGraphicRect(0, 0, 23, 42);
            DrawGraphic(GetX,GetY);
	}

	q+=1;
	DrawText("Seud", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }

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

	task Invisible(x, y, a, v, angular, g){

		let obj=Obj_Create(OBJ_SHOT);
            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, a);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, g);
		PlaySE(tir);
		let alpha = 0;
		let change = 4;

	    while(Obj_BeDeleted(obj)==false) {
          	Obj_SetAlpha(obj, alpha);
		alpha+=change;
		if (alpha<0){
			change=4;
		}
		if (alpha>255){
			change=-4;
		}

		Obj_SetAngle(obj, Obj_GetAngle(obj)+angular);
         	yield;
            }
	}

}
