#TouhouDanmakufu
#Title[Star Chi "Earth-Moving Star Bullets".]
#Text[Meiling uses Marisa stars for the lulz. And Yeah, another UNL themed spell. 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 frame = 0;
let niceshot = CSD~"\Thaws_ShotSheet\shotdata.txt";
let bg = CSD~"cdbg10.png";
let overlaybg = CSD~"overlaybg.png";
let f = 0;
let f2 = 0;
let shot = CSD~"Shot1.wav";
let bigshot = CSD~"se_tan00.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);
		SetLife(1000);
		SetTimer(60);
		SetInvincibility(200);
		SetMovePosition03(GetCenterX, GetCenterY-120, 5, 6);
                LoadGraphic(china);
                LoadGraphic(bg);
                LoadGraphic(overlaybg);
                SetScore(100000);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
                CutIn(YOUMU,"Star Chi"\""Earth-Moving Star Bullets"\",chinacutin,0,0,191,319);
                mainTask;
                SupportShoot;
                Timer;
  }

  @MainLoop{
  if(frame<1000){frame++;}
  SetCollisionA(GetX,GetY,30);
  SetCollisionB(GetX,GetY,20);
   if(frame==800){SetDamageRate(50,50);}
   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{
 }
 
 @BackGround{
  if(bgalpha<255){bgalpha+=5;}
   SetAlpha(bgalpha);
   SetTexture(bg);
   SetGraphicRect(0,0,256,256);
   SetGraphicScale(2.2,2.2);
   SetColor(255,255,255);
   SetGraphicAngle(0,0,0);
   DrawGraphic(GetCenterX,GetCenterY);

  if(bgalpha2<80){bgalpha2+=5;}
   SetAlpha(bgalpha2);
   SetTexture(overlaybg);
   SetGraphicRect(0,0,256,256);
   SetGraphicScale(2.5,2.5);
   SetColor(255,255,255);
   SetGraphicAngle(0,0,bgspin);
   DrawGraphic(GetCenterX,GetCenterY);
   bgspin+=0.5;
 }

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

    task mainTask{
    wait(200);
    loop{
    ascent(j in 0..5){
    ascent(i in 0..20){
    Bullet(rand(201,210),rand(201,210),i*360/20,10,75-j*15,0.8,0.5);
    }
    wait(15);
    }
    PlaySE(bigshot);
    wait(0);
    SetMovePosition03(GetPlayerX, GetCenterY-120, 7, 7);
    wait(30);
    } 
    }

    task SupportShoot{
    wait(200);
    let stars=51;
    let AddAngle=0;
    loop{
    if(stars==61){stars=51;}
    ascent(i in 0..8){
    CreateShot02(GetX,GetY,0,i*360/8+AddAngle,0.05,4,stars,5);
    }
    PlaySE(shot);
    stars++;
    AddAngle+=9.3;
    wait(3);
    }
    }
    

    task Bullet(graphic, slavegraphic, angle, delay, time, speed, newspeed) {
     let shot=Obj_Create(OBJ_SHOT);
     let aim=0;
     let count=0;

     Obj_SetPosition(shot, GetX, GetY);
     Obj_SetAngle(shot, angle);
     Obj_SetSpeed(shot, speed);
     ObjShot_SetGraphic(shot, graphic);
     ObjShot_SetDelay  (shot, delay);
     ObjShot_SetBombResist (shot, true);

     while(!Obj_BeDeleted(shot)){
     aim++;
  
     if(aim==time){
     Obj_SetAngle(shot,90);
     Obj_SetSpeed(shot,newspeed);}

     if(aim>time){
     Obj_SetSpeed(shot,Obj_GetSpeed(shot)+0.1);}

     if(Obj_GetY(shot)>GetClipMaxY && count==0){
     CreateShotA(1,Obj_GetX(shot),Obj_GetY(shot),60);
     SetShotDataA(1,0,0,0,0,0,0,slavegraphic);
     SetShotKillTime(1,0.5);
     FireShot(1);
     count++;
     }
     yield;
     }
     }
     
}
