#include_function ".\AnimationLib.dnh";
let m = 0;
let r = 0;
let alpha = 0;
let alpha2 = 0;
let slided = 0;
let check = 0;
let direct = "idle";
let CSD = GetCurrentScriptDirectory;
let ci = CSD ~ "system\NMM.png";
let ImgBoss = GetCurrentScriptDirectory~"img\boss_medicine.png";
let bg1 = CSD ~ "system\bg8.png";
let bg2 = CSD ~ "system\bg3.png";

LoadGraphic(bg1);
LoadGraphic(bg2);
LoadGraphic(ci);
LoadGraphic(ImgBoss);

    CreateAnimation("reimu", "idle", 3);
    SetAnimationFrame("reimu", "idle", 0, ImgBoss, 12, 28,32,100,96);
    SetAnimationFrame("reimu", "idle", 1, ImgBoss, 12, 28,158,100,226);
    SetAnimationFrame("reimu", "idle", 2, ImgBoss, 12, 28,284,100,356);

    CreateAnimation("reimu", "start move left", 2);
    SetAnimationFrame("reimu", "start move left", 0, ImgBoss, 8, 286,32,358,96);
    SetAnimationFrame("reimu", "start move left", 1, ImgBoss, 8, 286,158,358,226);

    CreateAnimation("reimu", "stop move left", 1);
    SetAnimationFrame("reimu", "stop move left", 0, ImgBoss, 8, 286,32,358,96);

    CreateAnimation("reimu", "start move right", 2);
    SetAnimationFrame("reimu", "start move right", 0, ImgBoss, 8, 286,284,358,358);
    SetAnimationFrame("reimu", "start move right", 1, ImgBoss, 8, 286,412,358,488);

    CreateAnimation("reimu", "stop move right", 1);
    SetAnimationFrame("reimu", "stop move right", 0, ImgBoss, 8, 286,284,358,358);

    CreateAnimation("reimu", "start spell", 3);
    SetAnimationFrame("reimu", "start spell", 0, ImgBoss, 8, 416,32,480,96);
    SetAnimationFrame("reimu", "start spell", 1, ImgBoss, 8, 416,158,480,226);
    SetAnimationFrame("reimu", "start spell", 2, ImgBoss, 8, 416,284,480,356);

    CreateAnimation("reimu", "stop spell", 2);
    SetAnimationFrame("reimu", "stop spell", 0, ImgBoss, 8, 416,158,480,226);
    SetAnimationFrame("reimu", "stop spell", 1, ImgBoss, 8, 416,32,480,96);

    CreateAnimation("reimu", "start shoot", 3);
    SetAnimationFrame("reimu", "start shoot", 0, ImgBoss, 8, 544,32,608,96);
    SetAnimationFrame("reimu", "start shoot", 1, ImgBoss, 8, 544,158,608,226);
    SetAnimationFrame("reimu", "start shoot", 2, ImgBoss, 8, 544,284,608,356);

    CreateAnimation("reimu", "stop shoot", 2);
    SetAnimationFrame("reimu", "stop shoot", 0, ImgBoss, 8, 544,158,608,226);
    SetAnimationFrame("reimu", "stop shoot", 1, ImgBoss, 8, 544,32,608,96);

    CreateAnimation("reimu", "start attack", 3);
    SetAnimationFrame("reimu", "start attack", 0, ImgBoss, 8, 672,32,736,96);
    SetAnimationFrame("reimu", "start attack", 1, ImgBoss, 8, 672,158,736,226);
    SetAnimationFrame("reimu", "start attack", 2, ImgBoss, 8, 672,284,736,356);

    CreateAnimation("reimu", "stop attack", 2);
    SetAnimationFrame("reimu", "stop attack", 0, ImgBoss, 8, 672,158,736,226);
    SetAnimationFrame("reimu", "stop attack", 1, ImgBoss, 8, 672,32,736,96);

    Animate("reimu", "idle", true); //true makes it loop

task drawmini(x,y,scale,check)
	{
    	 let e = Obj_Create(OBJ_EFFECT);
	 let c = 0;
	 let a = 0;
    	 Obj_SetPosition   (e, x, y);
	 ObjEffect_SetScale(e,scale,scale);
	 ObjEffect_SetTexture(e,ImgBoss);
	 ObjEffect_SetRenderState(e,ALPHA);
	ObjEffect_SetLayer(e,2);
	 ObjEffect_SetPrimitiveType(e,PRIMITIVE_TRIANGLESTRIP);
	 ObjEffect_CreateVertex(e, 4);
	Obj_SetAlpha(e,255);
	ObjEffect_SetVertexXY(e,0,-18,-18);
	ObjEffect_SetVertexXY(e,1,18,-18);
	ObjEffect_SetVertexXY(e,2,-18,18);
	ObjEffect_SetVertexXY(e,3,18,18);
		 while(! Obj_BeDeleted(e)) 
		{
		c++;
		a++;
		Obj_SetCollisionToPlayer(e,true);
		Obj_SetAlpha(e,255);
		if(c<8){
		ObjEffect_SetVertexUV(e,0,770,0);
		ObjEffect_SetVertexUV(e,1,798,0);
		ObjEffect_SetVertexUV(e,2,770,32);
		ObjEffect_SetVertexUV(e,3,798,32);
		}
		if(c>=8 && c<16){
		ObjEffect_SetVertexUV(e,0,770,32);
		ObjEffect_SetVertexUV(e,1,798,32);
		ObjEffect_SetVertexUV(e,2,770,64);
		ObjEffect_SetVertexUV(e,3,798,64);
		}
		if(c>=16 && c<24){
		ObjEffect_SetVertexUV(e,0,770,64);
		ObjEffect_SetVertexUV(e,1,798,64);
		ObjEffect_SetVertexUV(e,2,770,96);
		ObjEffect_SetVertexUV(e,3,798,96);
		}
		if(c>=24){c=0;}
		if((a%360)==0){ObjEffect_SetLayer(e,2);}
		if((a%360)==180){ObjEffect_SetLayer(e,1);}
		Obj_SetPosition   (e, GetX+40*cos(a), GetY+20*sin(a*2));
		yield;
		}
	}

task draw2{
		if(alpha<250){alpha+=10;}
		SetTexture(bg1);
		SetRenderState(ALPHA);
		SetAlpha(alpha);
		SetGraphicRect(0,0,256,256);
		SetGraphicScale(2,2);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY);
		if(slided>0){
		if(alpha2<250){alpha2+=10;}
		SetTexture(bg2);
		SetRenderState(ALPHA);
		SetAlpha(alpha2/5);	
		SetGraphicRect(0,0,416,464+slided);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY);
		}
		slided+= 1.5;
	}

task drawall{
		DrawAnimatedSprite("reimu", GetX, GetY);
	}

task drawcc(x,y,v,dir)
	{
    	 let e = Obj_Create(OBJ_EFFECT);
	 let c = 0;
	 let s = 0;
	 let change = 0;
    	 Obj_SetPosition   (e, x, y);
    	 Obj_SetSpeed      (e, v);
    	 Obj_SetAngle      (e, dir);
	 ObjEffect_SetTexture(e,ci);
	ObjEffect_SetScale(e,1.2,1.2);
	 ObjEffect_SetRenderState(e,ALPHA);
	ObjEffect_SetLayer(e,1);
	 ObjEffect_SetPrimitiveType(e,PRIMITIVE_TRIANGLESTRIP);
	 ObjEffect_CreateVertex(e, 4);
	Obj_SetAlpha(e,100);
	ObjEffect_SetVertexXY(e,0,-64,-64);
	ObjEffect_SetVertexXY(e,1,64,-64);
	ObjEffect_SetVertexXY(e,2,-64,64);
	ObjEffect_SetVertexXY(e,3,64,64);
	ObjEffect_SetVertexUV(e,0,0,0);
	ObjEffect_SetVertexUV(e,1,128,0);
	ObjEffect_SetVertexUV(e,2,0,128);
	ObjEffect_SetVertexUV(e,3,128,128);
		 while(! Obj_BeDeleted(e)) 
		{
		c++;
		if(s<1.6){s+=0.04;}
		ObjEffect_SetScale(e,s+0.15*sin(c*3),s+0.15*sin(c*3));
		 ObjEffect_SetAngle(e,0,0,c*5);
		 Obj_SetPosition   (e, GetX, GetY);
		 yield;
		}
	}

task SetFlandreMoveAnimation(direction) {
	yield;
    if(direction == "left"){
      Animate("reimu", "start move left", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("reimu", "stop move left", false);
    }
    if(direction == "right"){
      Animate("reimu", "start move right", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("reimu", "stop move right", false);
    }
   if(direction== "idle"){
    Animate("reimu", "idle", true);
   }
    wait(6);
    Animate("reimu", "idle", true);
  }

task spellcardattack{
	Animate("reimu", "start spell", false);
	wait(70);
	Animate("reimu", "stop spell", false);
	wait(20);
	Animate("reimu", "idle", true);
	}

task shoot{
	Animate("reimu", "start shoot", false);
	}

task attack{
	Animate("reimu", "start attack", false);
	}

task stopshoot{
	Animate("reimu", "stop shoot", false);
	wait(16);
	Animate("reimu", "idle", true);
	}

task stopattack{
	Animate("reimu", "stop attack", false);
	wait(16);
	Animate("reimu", "idle", true);
	}

task checkmove{
		wait(1);
		if(GetSpeedX>0){direct = "right";}
		else if(GetSpeedX<0){direct = "left";}
		else{Animate("reimu", "idle", true);}
		SetFlandreMoveAnimation(direct);
	}