#TouhouDanmakufu
#Title[War' : "Obscure sign : Devil's spinning top"]
#Text[Une strategie classique consiste a encercle l'ennemi, ainsi, meme en inferiorite numerique, on prend l'avantage. La toupie demoniaque de War' lui permet de prendre cet avantage a lui tout seul. Ce n'est pas tres pratique pour nous...]
#Image[]
#BGM[script\DanMUku\Stage2\War.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\Stage2\Image\WaruigiN.png";
    let bg ="script\DanMUku\Stage2\Image\wafond.png";
    let count=-120;
    let angle=0;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let a=0;
    let z = 0;
    let w = 0.5;
    let toupie = -120;
    let angle=0;
    let difficulties=0;
    let q = 0;
    let bonus = true;

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

   @Initialize
   {
            LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
            LoadGraphic(bg);
            LoadGraphic(imgEnemy);
            SetLife(2000);
            SetTimer(40);
            SetInvincibility(150);
            SetEnemyMarker(true);
            SetMovePosition02(GetCenterX-150, GetCenterY-100, 120); 
            SetScore(1000000);
            CutIn(YOUMU, "Obscure sign"\""Devil's spinning top"\", "script\DanMUku\Stage2\Image\Warcutin.png" , 0,0,121,214);       
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 16);
        SetCollisionB(GetX, GetY, 16);

	if(GetTimer==20){
		bonus=false;
	}

if(toupie%10==0&&toupie>-1&&toupie<40)
{
a+=40
}
if(toupie==40)
{
a=40;
toupie=1;
}
if(count%100==0&&count>0)
{
if(count%200==0)
{
SetMovePositionHermite(GetCenterX-150, GetCenterY-100, -500, 270, 500, 90, 100);
}
else
{
SetMovePositionHermite(GetCenterX+150, GetCenterY-100, 500, 90, -500, 270, 100);
}
}
if(count%4==0&&count>0)
{
CreateShot01(GetX, GetY, 1.5, angle, 99, 0);
angle+=10;
}
if(count%12==0&&count>0)
{
PlaySE(tir);
}
if(count%4==0&&count>0)
{
if(difficulties==1)
{
Bullet(GetX, GetY, 1.5, angle+180, 0);
}
else
{
CreateShot01(GetX, GetY, 1.5, angle+180, 99, 0);
}
}
if(count%400==0)
{
difficulties=1;
}
if(count%500==0)
{
difficulties=0;
}
yield;
toupie++;
count++;
   }
   @Finalize
   {
loop(7)
{
CreateItem(ITEM_SCORE, rand(GetX-20, GetX+20), rand(GetY-20, GetY+20));  
}
	if (bonus){
		SetCommonData("U", true);
	}
      DeleteGraphic(imgEnemy);
   }
   
   @DrawLoop
   {
            SetTexture(bg);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetGraphicRect(0, 0, 384, 50000+q);
            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX, GetCenterY+q);

            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetTexture(imgEnemy);
            SetGraphicRect(a, 0, a+40, 40);
            DrawGraphic(GetX,GetY+z);
     if(z==10){w=-0.5;}
     if(z==-10){w=0.5;}
z+=w;
q+=10;
	DrawText("War'", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }

   task Bullet(x, y, v, angle, delay) {
    let obj_id=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj_id, x, y);
     Obj_SetAngle(obj_id, angle);
     Obj_SetSpeed(obj_id, v);
     ObjShot_SetGraphic(obj_id, 88);
     ObjShot_SetDelay  (obj_id, delay);
     while(Obj_BeDeleted(obj_id)==false) {
	Wait(120);
	     Obj_SetAngle(obj_id, atan2(GetPlayerY-Obj_GetY(obj_id), GetPlayerX-Obj_GetX(obj_id)));
	     ObjShot_SetGraphic(obj_id, 97);
	     Obj_SetSpeed(obj_id, 0);
	Wait(60);
	      PlaySE(munch);
	     Obj_SetSpeed(obj_id, v*2);
	Wait(1000000000);
             yield;
      }
}
}
