#TouhouDanmakufu
#Title[Seud : "Tech sign : Double rotations"]
#Text[Une experience sur la gravite. Cette attaque etant tres localise, seud est oblige de vous enfermer avec des lasers de chaque cote. Pas evident a lire mais suffisemment lent pour y arriver.]
#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(7000);
            SetTimer(60);
            SetInvincibility(100);
            SetMovePosition02(GetCenterX, GetCenterY-100, 50);   
            SetScore(1000000);
            CutIn(YOUMU, "Tech sign"\""Double rotations"\", "script\DanMUku\Stage5\Image\seudcutin.png" , 0,0,121,214);               
   }
   
   @MainLoop
   {
            SetEnemyMarker(false);
        SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);
if(count%200==0)
{
SetMovePositionRandom01(50, 50, 2, GetClipMinX+30, GetClipMinY+40, GetClipMaxX-30, GetCenterY-10);

CreateLaserA(1, GetX-80, GetClipMinY+20, GetClipMaxY, 20, 5, 10);
SetLaserDataA(1, 0, 180, 0, 0, 0, 0);
SetLaserDataA(1, 20, NULL, -a, 0, 0, 0);
SetLaserDataA(1, 100, NULL, 0, 0, 0, 0);
SetShotKillTime(1, 190);

CreateLaserA(2, GetX+80, GetClipMinY+20, GetClipMaxY, 20, 2, 10);
SetLaserDataA(2, 0, 0, 0, 0, 0, 0);
SetLaserDataA(2, 20, NULL, a, 0, 0, 0);
SetLaserDataA(2, 100, NULL, 0, 0, 0, 0);
SetShotKillTime(2, 190);

FireShot(1);
FireShot(2);

a+=0.01;
}

if(count%200==20)
{
PlaySE(laser);
}

if(count%rythme==0)
{
Racine(GetX, GetY, rand(75,105), v, BLUE03, RED02, WHITE01);
rythme-=20;
}



count++;
yield;
   }
   @Finalize
   {
loop(10)
{
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 Feuille(maitre, racine, angle, graphic){

            let obj=Obj_Create(OBJ_SHOT);
            Obj_SetPosition(obj, Obj_GetX(maitre), Obj_GetY(maitre));
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, 2);
            ObjShot_SetGraphic(obj, graphic);
	    ObjShot_SetBombResist(obj, true);
		PlaySE(tir);

		loop(30) {
			Obj_SetPosition(obj, Obj_GetX(obj)+cos(Obj_GetAngle(maitre))*Obj_GetSpeed(maitre)+cos(Obj_GetAngle(racine))*Obj_GetSpeed(racine), Obj_GetY(obj)+sin(Obj_GetAngle(maitre))*Obj_GetSpeed(maitre)+sin(Obj_GetAngle(racine))*Obj_GetSpeed(racine));
			yield;
		}
		Obj_SetAngle(obj, Obj_GetAngle(obj)+90);
		Obj_SetSpeed(obj, 1);
		
	while(Obj_BeDeleted(obj)==false){
		if(Obj_BeDeleted(maitre)) {
			Obj_Delete(obj);
			yield;
		}
		Obj_SetAngle(obj, Obj_GetAngle(obj)+1);
		Obj_SetPosition(obj, Obj_GetX(obj)+cos(Obj_GetAngle(maitre))*Obj_GetSpeed(maitre)+cos(Obj_GetAngle(racine))*Obj_GetSpeed(racine), Obj_GetY(obj)+sin(Obj_GetAngle(maitre))*Obj_GetSpeed(maitre)+sin(Obj_GetAngle(racine))*Obj_GetSpeed(racine));
		yield;
	}
	}


	task Noeud(maitre, angle, graphic, graphic2){

            let obj=Obj_Create(OBJ_SHOT);
            Obj_SetPosition(obj, Obj_GetX(maitre), Obj_GetY(maitre));
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, 3);
            ObjShot_SetGraphic(obj, graphic);
	    ObjShot_SetBombResist(obj, true);
		PlaySE(tir);

		let angle_maitre = Obj_GetAngle(maitre);
		let vitesse_maitre = Obj_GetSpeed(maitre);

		loop(30) {
			Obj_SetPosition(obj, Obj_GetX(obj)+cos(angle_maitre)*vitesse_maitre, Obj_GetY(obj)+sin(angle_maitre)*vitesse_maitre);
			yield;
		}

		let a = 0;
		loop(6) {
			Feuille(obj, maitre, a, graphic2);
			a+=360/6;
		}

		Obj_SetAngle(obj, Obj_GetAngle(obj)-90);
		Obj_SetSpeed(obj, 1);
		
	while(Obj_BeDeleted(obj)==false){
		if(Obj_BeDeleted(maitre)) {
			Obj_Delete(obj);
			yield;
		}
		Obj_SetAngle(obj, Obj_GetAngle(obj)-0.5);
		Obj_SetPosition(obj, Obj_GetX(obj)+cos(angle_maitre)*vitesse_maitre, Obj_GetY(obj)+sin(angle_maitre)*vitesse_maitre);
		yield;
	}
	}


	task Racine(x, y, angle, vitesse, graphic, graphic2, graphic3) {
		let rac=Obj_Create(OBJ_SHOT);
            Obj_SetPosition(rac, x, y);
            Obj_SetAngle(rac, angle);
            Obj_SetSpeed(rac, vitesse);
            ObjShot_SetGraphic(rac, graphic);
	    ObjShot_SetBombResist(rac, true);
	PlaySE(tir);

		Wait(30);
		let a = 0;
		loop(6) {
			Noeud(rac, a, graphic2, graphic3);
			a+=360/6;
		}
	  while(Obj_BeDeleted(rac)==false){
		yield;
	  }

	}

}
