#TouhouDanmakufu
#Title[Curse "River of Blood". Easy Mode.]
#Text[Remilia SC1.]
#Player[FREE]
#BGM[.\BGM1.wav]
#ScriptVersion[2]

script_enemy_main{
let CSD = GetCurrentScriptDirectory;
let niceshot = CSD~"\supershot\supershot.txt";
let laserSE = CSD~"Laser3.wav";
let shot = CSD~"Shot3.wav";
let shot2 = CSD~"Shot4.wav";
let death = CSD~"BossDeath.wav";
let time01 = CSD~"timeout01.wav";
let time02 = CSD~"timeout02.wav";
let remiliasheet = CSD~"boss15.png";
let remiliacutin = CSD~"remilia.png";
let circle = CSD~"circle.png";
let spellbg = CSD~"cdbg15.png";
let frame = 0;
#include_function ".\AnimationLib.dnh"
#include_function ".\FunctionLib.dnh"

 @Initialize{
                LoadUserShotData(niceshot);
                LoadGraphic(remiliasheet);
                LoadGraphic(spellbg);
                LoadGraphic(circle);
		SetLife(1000);
		SetTimer(60);
                SetScore(100000);
		SetInvincibility(100);
		SetMovePosition03(GetCenterX, GetCenterY-100, 12, 9);
                SetDamageRate(10,5);
                SetEffectForZeroLife(70,200,1);
                CutIn(YOUMU,"Curse"\""River of Blood"\",remiliacutin,0,0,256,512);
                mainTask;
                Support;
                MOVE;
                Timer;

    CreateAnimation("remilia", "idle", 1);
    SetAnimationFrame("remilia", "idle", 0, remiliasheet, 12, 0, 0, 64, 82);

    CreateAnimation("remilia", "move", 3);
    SetAnimationFrame("remilia", "move", 0, remiliasheet, 12, 0, 0, 64, 82);
    SetAnimationFrame("remilia", "move", 1, remiliasheet, 12, 64, 0, 128, 82);
    SetAnimationFrame("remilia", "move", 2, remiliasheet, 12, 128, 0, 192, 82);

  }


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

 let counter1=0;
 let counter2=0;
 let counter3=0;
 let graphicangle=0;
 let circlespin=0;
 let wave=0;
 let float=0;

 @DrawLoop{

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

  SetTexture(remiliasheet);
  SetGraphicScale(1,1);
  SetAlpha(255);


  if(GetSpeedX>0 && counter1==0){
  graphicangle=0;
  Animate("remilia","move",false);
  counter1++;
  counter2=0;
  counter3=0;}

  if(GetSpeedX<0 && counter2==0){
  graphicangle=180;
  Animate("remilia","move",false);
  counter2++;
  counter1=0;
  counter3=0;}

  if(GetSpeedX==0 && counter3==0){
  Animate("remilia","idle",true);
  counter3++;
  counter1=0;
  counter2=0;}

  //true makes it loop, false makes it continue on the last sprite.

  SetGraphicAngle(graphicangle,0,0);
  DrawAnimatedSprite("remilia", GetX, GetY+sin(float)*4);
  float += (1/((|GetSpeedX|)+1))*3;
 }

 @Finalize{
 }
 
 let bgalpha=0;
 let bgspin=0;

 @BackGround{
  if(bgalpha<150){bgalpha+=2;}
  SetTexture(spellbg);
  SetGraphicRect(0,0,256,256);
  SetGraphicScale(2.2,2.2);
  SetGraphicAngle(0,0,bgspin);
  SetAlpha(bgalpha);
  DrawGraphic(GetCenterX,GetCenterY);
  bgspin+=1;

 }

     task mainTask{
     wait(100);
     let wave=0;
     loop{
     PlaySE(shot);
     Bullet(1,270-sin(wave)*90,-0,239);
     Bullet(1,270+sin(wave)*90,-0,239);
     

     wave+=7.5;

     wait(31);
     }
     }

     task Support{
     wait(100);
     let addangle=90;
     let addangle2=0;
     let wave=0;
     loop{
     PlaySE(shot);
     Bullet(4,GetAngleToPlayer,-5,239);
     wait(150);
     }
     }

     task MOVE{
     wait(100);
     loop{
     wait(400);
     SetMovePosition03(rand(GetCenterX,GetClipMaxX-30), GetCenterY-100, 10, 4);
     wait(400);
     SetMovePosition03(rand(GetCenterX,GetClipMinX+30), GetCenterY-100, 10, 4);
     }
     }

     task Bullet(speed,angle,Yspeed,graphic){
     let id = Obj_Create(OBJ_SHOT);
 
     Obj_SetPosition(id,GetX,GetY);
     Obj_SetSpeed(id,speed);
     Obj_SetAngle(id,angle);
     ObjShot_SetGraphic(id,graphic);
     ObjShot_SetDelay(id,20);

     while(!Obj_BeDeleted(id)){

     if(Obj_GetX(id)>GetClipMaxX|| Obj_GetX(id)<GetClipMinX|| Obj_GetY(id)>GetClipMaxY||Obj_GetY(id)<GetClipMinY){
     PlaySE(shot2);
     ascent(i in 0..32){
     CreateShot12(Obj_GetX(id),Obj_GetY(id),-5+i/3,Yspeed,0,0.05,0,1,180,30);
     }
     Obj_Delete(id);
     }

     yield;
     }
     }

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