#TouhouDanmakufu
#Title[Seud : "Delay Chase Combo"]
#Text[Seud devient serieux avec cette attaque. Les lasers bleus vous visent directement mais les lasers rouges visent legerement au-dessus de vous, faite attantion a ne pas vous faire pieger !]
#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 = -50;
    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\Stage3\Image\vitrail.png";

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(imgEnemy);
	    LoadGraphic(bg);
	    LoadSE(tir);
	    LoadSE(munch);
	    LoadSE(laser);
	    MagicCircle(false);
            SetLife(5000);
            SetTimer(70);
            SetInvincibility(100);
            SetMovePosition02(GetCenterX, GetCenterY-100, 50);   
            SetScore(1700000);
            CutIn(YOUMU, "Delay Chase Combo", "script\DanMUku\Stage5\Image\seudcutin.png" , 0,0,121,214);               
   }
   
   @MainLoop
   {
	SetEnemyMarker(false);
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
if(count%700>0&&count%700<400&&count%50==0)
{
SetMovePositionRandom01(50, 50, 2, GetClipMinX+30, GetClipMinY+40, GetClipMaxX-30, GetCenterY-10);

CreateLaser01(GetClipMinX, GetPlayerY, 2, 0, 200, 10, 17, 10);
PlaySE(laser);
}

if(count%700>0&&count%700<400&&count%50==20)
{

CreateLaser01(GetClipMaxX, GetPlayerY-30, 2, 180, 200, 10, 11, 10);
PlaySE(laser);
}

if(count%700>0&&count%700<250&&count%10==0){
	let X = 30;
	loop(10){
		Tir(rand(X-5, X+5), 10, 90, 2, 260);
		X+=50;
	}
}



count++;
yield;
   }
   @Finalize
   {
	if(GotSpellCardBonus){
		SetCommonData("N", true);
	}

loop(15)
{
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 Tir(x, y, a, v, d){

            let obj=Obj_Create(OBJ_SHOT);
            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, a);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, 22);
	    ObjShot_SetBombResist(obj, true);
		PlaySE(tir);
		let bool = false;

	    while(Obj_BeDeleted(obj)==false && bool==false)
      {
                    if(Obj_GetY(obj)>GetClipMaxY)
         {
	        Obj_SetAngle(obj, rand(190, 350) );
		Obj_SetSpeed(obj, 0.2);
                          Obj_SetY(obj,  Obj_GetY(obj) + 0.1);
	        ObjShot_SetGraphic(obj, 15);
                bool = true;
                    }

         yield;
            }
		Wait(d);
		ObjShot_SetGraphic(obj, 10);
		Obj_SetSpeed(obj, 0);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)) );
		Wait(15);
		PlaySE(munch);
		Obj_SetSpeed(obj, v);
		ObjShot_SetBombResist(obj, false);
	}

}
