#TouhouDanmakufu
#Title[Non-spell 1]
#Text[Normal Mode.]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
let CSD = GetCurrentScriptDirectory;
let patch = CSD~"Event_Patchouli.txt";
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 SE1 = CSD~"Shot1.WAV";
let SE2 = CSD~"Shot4.WAV";
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"


 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(circle);
                LoadGraphic(booksheet);
		SetLife(500);
                SetX(-100);
                SetY(-100);
		SetInvincibility(200);
                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;
  frame++;
  
  if(OnEvent){
  ForbidShot(true);
  ForbidBomb(true);
  }
  
  if(!OnEvent){
  SetCollisionA(GetX,GetY,10);
  ForbidShot(false);
  ForbidBomb(false);
  }
  
  if(frame==200){
  CreateEventFromScript("intro");
   CreateEnemyFromFile(patch,0,0,0,0,1);
    SetMovePosition03(GetCenterX+50, GetCenterY-80, 10, 4);
  }
  
  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(500);
     let addangle=0;
     let wave=0;
	 WaitForNoEvent;
	 SetMovePosition03(GetCenterX, GetCenterY-50, 10, 4);
	 SetTimer(40);
     loop{
     ascent(i in 0..10){
     CreateShotA(1,GetX,GetY,20);
     SetShotDataA(1,0,5+sin(wave)*3,i*360/10+addangle,0,-0.2,0,223);
     SetShotDataA(1,30,NULL,NULL,9,0,0,NULL);
     SetShotDataA(1,70,NULL,NULL,0,0.1,4,NULL);
     

     ascent(l in 0..15){
     CreateShotA(2,0,0,0);
     SetShotDataA(2,0,-4,l*360/15+addangle,0,0.5,0,99);
     SetShotDataA(2,80-l*2,NULL,NULL,0,0.1,2,NULL);
     AddShot(30+l*2,1,2,0);}


     FireShot(1);
	 PlaySE(SE1);}

     addangle+=37.5;
     wave+=93.5;

     wait(120);

     }
     }



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

script_event intro{
let CSD = GetCurrentScriptDirectory;
let patch = CSD~"Event_Patchouli.txt";
let cutin1 = CSD~"photo1.png";
let cutin2 = CSD~"photo2.png";


 @Initialize{
 LoadGraphic(cutin1);
 LoadGraphic(cutin2);
 }
 
 @MainLoop{
 Wait(60);
 MoveChar(LEFT, BACK);
 SetChar(RIGHT,cutin2);
 SetGraphicRect(RIGHT,0,0,191,319);
 MoveChar(RIGHT,FRONT);
 TextOutA("I don't have time to deal with you, and Koakuma isn't here right now...");
 SetChar(RIGHT,cutin1);
 SetGraphicRect(RIGHT,0,0,191,319);
 TextOutA("So i'll let you play with this magical danmaku anti-intruder book \n i made instead!");
 TextOutA("Have fun!");
 End;
 }

 @Finalize{
 }
 
}
