#TouhouDanmakufu
#Title[Chi Sign"Rainbow Walls".]
#Text[Try to not get trapped. I dare you. Normal mode.]
#Player[FREE]
#BackGround[User(.\world05b.png,0,1)]
#BGM[.\BGM1.wav]
#ScriptVersion[2]

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

 @Initialize{
                LoadUserShotData(niceshot);
		SetLife(1000);
		SetTimer(70);
		SetInvincibility(140);
		SetMovePosition03(GetCenterX, GetCenterY-120, 5, 6);
                LoadGraphic(china);
                LoadGraphic(bg);
                LoadGraphic(overlaybg);
                SetScore(100000);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
                CutIn(YOUMU,"Chi Sign"\""Rainbow Walls"\",chinacutin,0,0,191,319);
                movement;
                Timer;
  }

  @MainLoop{
  frame++;
  SetCollisionA(GetX,GetY,30);
  SetCollisionB(GetX,GetY,20);
    if(frame==60){
      SetColor(15,200,19);
      Concentration01(80);
      SetColor(255,255,255);
      PlaySE(charge);  
     }
    if(frame==140){
    PlaySE(summon);
    CreateEnemyFromFile(familiar,GetX,GetY,0,0,90);
    CreateEnemyFromFile(familiar,GetX,GetY,0,0,270);
  }
   if(frame==900){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{
  PlaySE(death);
 }
 
 @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 movement{
   wait(140);
   loop{
   wait(280);
   SetMovePosition03(GetClipMinX+20, GetCenterY-120, 10, 6);
   ascent(j in 0..11){
   wait(5);
   ascent(i in 0..10){
   CreateShot02(GetX,GetY,-3,90,0.05,2+i/4,21+i,55-j*5);}}
   wait(15);
   PlaySE(shot);
   wait(280);
   SetMovePosition03(GetClipMaxX-20, GetCenterY-120, 10, 6);
   ascent(j in 0..11){
   wait(5);
   ascent(i in 0..10){
   CreateShot02(GetX,GetY,-3,90,0.05,2+i/4,21+i,55-j*5);}}
   wait(15);
   PlaySE(shot);
   }
   }
     task Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }
}
