#TouhouDanmakufu
#Title[Inconnu : "A Star life cycle"]
#Text[Qui est cette ombre, d'ou vient-elle, ou va-t-elle et pourquoi vous attaque-t-elle ? Tant de questions sans reponses... Cette attaque se base sur la rotation des etoiles et leur destruction. Plus une etoile est eloigne du centre plus elle met de temps a exploser.]
#Image[]
#BGM[script\DanMUku\Stage6\Stage6.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\Stage6\Image\inconnu.png";
    let count=-200;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let dir=0;
    let vitesse=0.2;
    let bg = "script\DanMUku\Stage1\Image\etoiles.png";
    let x = GetX;
    let q = 0;

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

   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(imgEnemy);
	LoadGraphic(bg);
      LoadSE(tir);
      LoadSE(munch);
            SetLife(10000);
            SetTimer(60);
            SetInvincibility(60);
	SetScore(2000000);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX, GetCenterY-100, 120);
	CutIn(YOUMU, "A Star life cycle", "", 0,0,0,0);
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

	if(count%100==0&&count>=0){
		loop(8){
			PlaySE(munch);
			Stars(GetX, GetY, 4, dir, 80, rand(10,100));
			dir+=360/8;
		}
		vitesse+=0.01;
	}
count++;
yield;
   }
   @Finalize
   {
      DeleteGraphic(imgEnemy);

	loop(12) {
		CreateItem(ITEM_SCORE, rand(GetX-10, GetX+10), rand(GetY-10, GetY+10));  
	}
   }
   
   task Nova(obj, attente){
	let clign=60;
	let angle=0;
	Wait(attente*2);
     ObjShot_SetGraphic(obj, 77);
	Wait(attente*3);
     ObjShot_SetGraphic(obj, 78);
	Wait(attente*4);
	ObjShot_SetGraphic(obj, 73);
	loop(10){
		Wait(clign);
     		ObjShot_SetGraphic(obj, 78);
		Wait(clign);
     		ObjShot_SetGraphic(obj, 73);
		clign-=6;
	}
	PlaySE(tir);
	loop(5){
	CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, angle+rand(-10,10), 67, 80);
	angle+=72
	}
	Obj_Delete(obj);

}

   task Stars(x, y, v, angle, graphic, attente) {
     let obj=Obj_Create(OBJ_SHOT);
	SetCoordinateType(COODINATE_TYPE_PARENT);
     Obj_SetAutoDelete(obj, false);
     ObjShot_SetBombResist(obj, true);
     Obj_SetPosition(obj, x, y);
     Obj_SetAngle(obj, angle);
     Obj_SetSpeed(obj, v);
     ObjShot_SetGraphic(obj, graphic);
	Wait(attente);
	Nova(obj, attente);
     while(Obj_BeDeleted(obj)==false) {
		if(Obj_GetSpeed(obj)>0){
			Obj_SetSpeed(obj, Obj_GetSpeed(obj)-0.1);
		}
		Obj_SetPosition(obj, GetX+v*attente*cos(angle), GetY+v*attente*sin(angle));
		angle+=vitesse;
		yield;
      }

}
   @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(0,0,0);
	}
	if(x<GetX){
		SetGraphicAngle(180,0,0);
	}
      x=GetX;
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicRect(32,0,61,29);
            DrawGraphic(GetX,GetY);

	DrawText("???", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }

}
