#TouhouDanmakufu
#Title[Non-spell 3]
#Text[Easy 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 circle = CSD~"Circle.png";
let booksheet = CSD~"servant.png";
let SE2 = CSD~"Shot2.WAV";
let SE4 = CSD~"Shot4.WAV";
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"


 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(circle);
                LoadGraphic(booksheet);
		SetLife(500);
		SetTimer(40);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-100, 10, 4);
                SetDamageRate(20,20);
                SetEffectForZeroLife(70,200,1);
                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);
 }

 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{
 }

     task mainTask{
     wait(100);
     let addangle=0;
     loop{
     PlaySE(SE4);
	 Bullet(addangle,152,99);
	 
	 addangle+=15.3;
	 
	 wait(11);
     }
     }
	 


     task Timer{
     loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	wait(60);
	}
        }
		
	task Bullet(angle,graphic,newgraphic){
	let ID = Obj_Create(OBJ_SHOT);
	
	Obj_SetPosition(ID,GetX,GetY);
	Obj_SetSpeed(ID,4);
	Obj_SetAngle(ID,angle);
	ObjShot_SetGraphic(ID,graphic);
	ObjShot_SetDelay(ID,10);
	
	while(!Obj_BeDeleted(ID)){
	
	if(Obj_GetSpeed(ID)>0){Obj_SetSpeed(ID,Obj_GetSpeed(ID)-0.05);}
	
	if(Obj_GetSpeed(ID)<=0){
	
	ascent(i in -4..4){
	CreateShot01(Obj_GetX(ID),Obj_GetY(ID),1.5,Obj_GetAngle(ID)+i*360/14,newgraphic,20);}
	
	ascent(i in -4..4){
	CreateShot01(Obj_GetX(ID),Obj_GetY(ID),1.7,Obj_GetAngle(ID)+180+i*360/14,newgraphic-3,20);}
	
	Obj_Delete(ID);
	}
	
	yield;
	}
	}
     

}
