#TouhouDanmakufu
#Title[Meiling Non-Spell 1.]
#Text[Non-Spell 1. Lunatic mode.]
#Player[FREE]
#BackGround[User(.\world05b.png,0,1)]
#BGM[.\BGM1.wav]
#ScriptVersion[2]

script_enemy_main{
let CSD = GetCurrentScriptDirectory;
let chinacutin = CSD~"Meiling.png";
let china = CSD~"boss10.png";
let niceshot = CSD~"\Thaws_ShotSheet\shotdata.txt";
let f = 0;
let f2 = 0;
let shot = CSD~"Shot1.wav";
let death = CSD~"BossDeath.wav";
let time01 = CSD~"timeout01.wav";
let time02 = CSD~"timeout02.wav";
function wait(t){loop(t){yield;}}

 @Initialize{
                LoadUserShotData(niceshot);
                SetX(0);
                SetY(0);
		SetLife(500);
		SetTimer(30);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-120, 5, 6);
                LoadGraphic(china);
                SetDamageRate(25,25);
                SetEffectForZeroLife(70,200,1);
                mainTask;
                Move; 
                Timer;
  }

  @MainLoop{
  SetCollisionA(GetX,GetY,30);
  SetCollisionB(GetX,GetY,20);
   yield;
 }
 @DrawLoop{

  SetTexture(china);
  SetGraphicScale(1,1);
  SetAlpha(255);
  SetGraphicAngle(0,0,0);
  
  if(int(GetSpeedX())==0){
  if(f<10){SetGraphicRect(0,0,64,64); }
  if(f>=10 && f<20){SetGraphicRect(64,0,128,64); }
  if(f>=20 && f<30){SetGraphicRect(128,0,192,64); }
  if(f>=30 && f<40){SetGraphicRect(192,0,256,64); }
  f2=0;
  }

  if(GetSpeedX()>0){
  SetGraphicAngle(180,0,0);
  if(f2<5){SetGraphicRect(0,64,64,128); }
  if(f2>=5 && f2<10){SetGraphicRect(64,64,128,128); }
  if(f2>=10 && f2<15){SetGraphicRect(128,64,192,128); }
  if(f2>=15){SetGraphicRect(192,64,256,128); }
  f2++;
  }

  if(GetSpeedX()<0){
  if(f2<5){SetGraphicRect(0,64,64,128); }
  if(f2>=5 && f2<10){SetGraphicRect(64,64,128,128); }
  if(f2>=10 && f2<15){SetGraphicRect(128,64,192,128); }
  if(f2>=15){SetGraphicRect(192,64,256,128); }
  f2++;
  }

  DrawGraphic(GetX,GetY);
  f+=1;
  if(f==40){f=0;}
 }
   let bgalpha=0;
   let bgalpha2=0;
   let bgspin=0;

 @Finalize{
 }

     task Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }

    task mainTask{
    wait(100);
    let spiral=0;
    loop{
    CreateShotA(1,GetX,GetY,5);
    CreateShotA(2,GetX,GetY,5);
    CreateShotA(3,GetX,GetY,5);
    CreateShotA(4,GetX,GetY,5);
    CreateShotA(5,GetX,GetY,5);
    SetShotDataA(1,0,3,0+spiral,0,-0.1,-3,1);
    SetShotDataA(2,0,3,72+spiral,0,-0.1,-3,4);
    SetShotDataA(3,0,3,144+spiral,0,-0.1,-3,6);
    SetShotDataA(4,0,3,216+spiral,0,-0.1,-3,3);
    SetShotDataA(5,0,3,288+spiral,0,-0.1,-3,7);
    FireShot(1);
    FireShot(2);
    FireShot(3);
    FireShot(4);
    FireShot(5);
    PlaySE(shot);
    spiral+=6.2;
    wait(3);
    } 
    } 
     
    task Move{
    wait(100);
    loop{
    wait(220);
    SetMovePosition03(rand(GetClipMinX+50,GetClipMaxX-50), GetCenterY-rand(10,200), 8, 7);
    }
    }  

}
