#TouhouDanmakufu
#Title[Devils Gardener "Davids Flower".]
#Text[Meilings reference to Remilia. Hard mode]
#Player[FREE]
#BackGround[User(.\world05b.png,0,1)]
#BGM[.\BGM1.wav]
#ScriptVersion[2]

script_enemy_main{
let CSD = GetCurrentScriptDirectory;
let china = CSD~"boss10.png";
let charge = CSD~"se_ch00.wav";
let chinacutin = CSD~"Meiling.png";
let niceshot = CSD~"\Thaws_ShotSheet\shotdata.txt";
let bg = CSD~"cdbg10.png";
let overlaybg = CSD~"overlaybg.png";
let f = 0;
let f2 = 0;
let f3 = 0;
let shot = CSD~"Shot4.wav";
let shot2 = CSD~"Shot3.wav";
let death = CSD~"BossDeath.wav";
let time01 = CSD~"timeout01.wav";
let time02 = CSD~"timeout02.wav";
let frame = 0;
function wait(t){loop(t){yield;}}

 @Initialize{
                LoadUserShotData(niceshot);
		SetLife(1000);
		SetTimer(65);
		SetInvincibility(140);
		SetMovePosition03(GetCenterX, GetCenterY, 5, 6);
                LoadGraphic(china);
                LoadGraphic(bg);
                LoadGraphic(overlaybg);
                SetScore(100000);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
                CutIn(YOUMU,"Devils Gardener"\""Flower of David"\",chinacutin,0,0,191,319);
                mainTask;
                Move;
                Timer;
  }

  @MainLoop{
  if(frame<900){frame++;}
  if(frame==800){SetDamageRate(50,50);}
  SetCollisionA(GetX,GetY,30);
  SetCollisionB(GetX,GetY,20);
   yield;
 }

  let kicktime=0;

 @DrawLoop{
 
  kicktime++;
  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); }
  }

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

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

  if(GetSpeedX()<0){
  if(f2<10){SetGraphicRect(0,0,64,64); }
  if(f2>=10 && f2<20){SetGraphicRect(64,0,128,64); }
  if(f2>=20 && f2<30){SetGraphicRect(128,0,192,64); }
  if(f2>=30 && f2<40){SetGraphicRect(192,0,256,64); }
  }}

  DrawGraphic(GetX,GetY);
  f+=1;
  f2+=1;
  if(f3<=200){f3++;}
  if(f==40){f=0;}
  if(f2==40){f2=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 mainTask{
   let angle=0;
   let angle2=0;
   wait(140);
   loop{
   loop(60){
   wait(6);
   PlaySE(shot);
   ascent(j in 0..6){
   CreateShotA(j,GetX,GetY,20);
   SetShotDataA(j,0,2,angle,4,0,0,81+j);
   SetShotDataA(j,110,2,NULL,0,0,0,NULL);
   SetShotDataA(j,160,2,NULL,222,0,0,NULL);
   SetShotDataA(j,161,2,NULL,0,0,0,NULL);
   FireShot(j);
   angle+=360/6+0.5}}
     ascent(i in 0..12){
     CreateShotA(i,GetX,GetY,5);
     SetShotDataA(i,0,6,GetAngleToPlayer+i*30,0,-0.2,0,181);
     SetShotDataA(i,180,0,NULL,0,0.1,6,181);
     FireShot(i);}
   PlaySE(shot2);
   wait(70); 
   loop(60){
   wait(6);
   PlaySE(shot);
   ascent(j in 0..6){
   CreateShotA(j,GetX,GetY,20);
   SetShotDataA(j,0,2,angle2,-4,0,0,81+j);
   SetShotDataA(j,110,2,NULL,0,0,0,NULL);
   SetShotDataA(j,160,2,NULL,-222,0,0,NULL);
   SetShotDataA(j,161,2,NULL,0,0,0,NULL);
   FireShot(j);
   angle2+=360/6-0.5}}
     ascent(i in 0..12){
     CreateShotA(i,GetX,GetY,5);
     SetShotDataA(i,0,6,GetAngleToPlayer+i*30,0,-0.2,0,181);
     SetShotDataA(i,180,0,NULL,0,0.1,6,181);
     FireShot(i);}
   PlaySE(shot2); 
   wait(70);
   }
   }
     task Move{
     wait(300);
     loop{
     wait(1);
     SetMovePosition03(GetPlayerX, GetPlayerY, 10, 0.07);
     }
     }
     task Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }
}
