#TouhouDanmakufu
#Title[Spell Card 6]
#Text[Hard Mode.]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
let CSD = GetCurrentScriptDirectory;
let niceshot = CSD~"\supershot\supershot.txt";
let death = CSD~"BossDeath.wav";
let time01 = CSD~"timeout01.wav";
let time02 = CSD~"timeout02.wav";
let frame = 0;
let spellbg = CSD~"spellbg.png";
let spellbg2 = CSD~"spellbg2.png";
let circle = CSD~"Circle.png";
let booksheet = CSD~"servant.png";
let SE1 = CSD~"Laser1.WAV";
let SE5 = CSD~"Shot5.WAV";
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"


 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(circle);
                LoadGraphic(booksheet);
				LoadGraphic(spellbg2);
                LoadGraphic(spellbg);
		SetLife(1000);
		SetTimer(80);
                SetScore(100000);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-120, 10, 4);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
				SetText("Devilish Magic"\""Blinding Stare"\");
                mainTask;
                Timer;

    CreateAnimation("book", "intro", 4);
    SetAnimationFrame("book", "intro", 0, booksheet, 12, 0, 2, 31, 30);
    SetAnimationFrame("book", "intro", 1, booksheet, 12, 31, 2, 62, 30);
    SetAnimationFrame("book", "intro", 2, booksheet, 12, 62, 2, 93, 30);
    SetAnimationFrame("book", "intro", 3, booksheet, 12, 93, 2, 124, 30);

    Animate("book","intro",false);

  }


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

 let circlespin = 0;
 let wave = 0;
 let float = 0;

 @DrawLoop{

  SetTexture(circle);
  SetGraphicRect(64,64,192,192);
  SetGraphicScale(1+sin(wave)*0.5,1+sin(wave)*0.5);
  SetGraphicAngle(0,0,circlespin);
  SetAlpha(150);
  DrawGraphic(GetX,GetY);
  circlespin+=5;
  wave+=2;

  SetTexture(booksheet);
  SetGraphicScale(1,1);
  SetAlpha(255);
  SetGraphicAngle(0,0,0);
  DrawAnimatedSprite("book", GetX, GetY+sin(float)*4);
  float += (1/((|GetSpeedX|)+1))*3;

 }

 @Finalize{
  PlaySE(death);
 }

 let bgalpha=0;
 let bgalpha2=0;
 let bgscroll=0;
 
 @BackGround{
  if(bgalpha<100){bgalpha+=2;}
  if(bgalpha2<70){bgalpha2+=2;}
  
  SetTexture(spellbg);
  SetGraphicRect(0,0,256,256);
  SetGraphicScale(2,2);
  SetAlpha(bgalpha);
  DrawGraphic(GetCenterX,GetCenterY);
  
  SetTexture(spellbg2);
  SetGraphicRect(0+bgscroll,0+bgscroll,256+bgscroll,256+bgscroll);
  SetGraphicScale(2,2);
  SetAlpha(bgalpha2);
  DrawGraphic(GetCenterX,GetCenterY);
  
  bgscroll+=2;
 }

     task mainTask{
     wait(100);
     let addangle=0;
	 Bullet(0,2);
	 Bullet(180,1);
     loop{
     
         yield;
	 
	 }
     }	 
     
	


     task Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }
		
	task Bullet(angle,argument){
	let ID = Obj_Create(OBJ_SHOT);
	let frame = 200;
	let addangle = 0;
	
	Obj_SetPosition(ID,GetX,GetY);
	Obj_SetSpeed(ID,5);
	Obj_SetAngle(ID,angle);
	Obj_SetAlpha(ID,200);
	ObjShot_SetDelay(ID,30);
	ObjShot_SetBombResist(ID,true);
	ObjShot_SetGraphic(ID,2);
	
	wait(30);
	while(!Obj_BeDeleted(ID)){
	frame++;
	
	if(Obj_GetSpeed(ID)>0){Obj_SetSpeed(ID,Obj_GetSpeed(ID)-0.1);}
	
	if(Obj_GetSpeed(ID)<0){Obj_SetSpeed(ID,0);}
	
	if(frame==310 && argument==1){
	PlaySE(SE1);
	ascent(i in 0..18){
	CreateLaserA(1,Obj_GetX(ID)+cos(i*360/18)*80,Obj_GetY(ID)+sin(i*360/18)*50,0,20,2,300);
	SetLaserDataA(1,0,addangle+i*360/20,3,2,0,0);
	SetLaserDataA(1,250,NULL,0,0,0,0);
	SetLaserDataA(1,300,NULL,0,0,0,0);
	SetShotKillTime(1,500);
	
	PlaySE(SE5);
	ascent(m in 0..2){
    ascent(l in 0..8){
	CreateShotA(2,0,0,40);
	SetShotDataA(2,0,3,90+m*180,0,0.05,1,121);
	AddShot(310,1,2,l*500/8);
	}}
	
	FireShot(1);
	}
	addangle+=87.5;
	frame=0;
	}
	
    if(frame==310 && argument==2){
    PlaySE(SE1);
	ascent(i in 0..18){
	CreateLaserA(1,Obj_GetX(ID)+cos(i*360/18)*80,Obj_GetY(ID)+sin(i*360/18)*50,0,20,2,300);
	SetLaserDataA(1,0,addangle+i*360/20,-3,2,0,0);
	SetLaserDataA(1,250,NULL,0,0,0,0);
	SetLaserDataA(1,300,NULL,0,0,0,0);
	SetShotKillTime(1,500);
	
	PlaySE(SE5);
	ascent(m in 0..2){
	ascent(l in 0..8){
	CreateShotA(2,0,0,40);
	SetShotDataA(2,0,0,90+m*180,0,0.05,1,121);
	AddShot(310,1,2,l*500/8);
	}}
	
	FireShot(1);
	}
	addangle+=87.5;
	frame=0;
	}
	
	yield;
	
	}
    }
	 
}



