#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["animation"]
#Text["animation"]
#include "script/default_system/Default_ShotConst.txt"
#include "./3dextrastage2.txt"
#include "./extrabossanimation.txt"

let bossObj;
let bossX = 0;
let bossY = 0;
let objScene = GetEnemyBossSceneObjectID();
let imgBoss = GetCurrentScriptDirectory ~ "sprite/reignsheet.png";
let animFrame = 0; 
let animFrame2 = 0;
let spellcardSFX = GetCurrentScriptDirectory ~ "SFX/SPELLCARD.wav";
let bossdeathSFX = GetCurrentScriptDirectory ~ "SFX/DEFEATED.wav";
let objText = ObjText_Create();
let circleObj = ObjPrim_Create(OBJ_SPRITE_2D);

let count = 0;




@Initialize {

  


  SetAutoDeleteObject(true); //automatically deletes object when THIS script ends

        bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
        ObjEnemy_Regist(bossObj); 

        ObjMove_SetPosition(bossObj,182,200); //warps the boss

        ObjMove_SetDestAtSpeed(bossObj,180,120,10); //movement function
   renderStage;
	scrollStage;
    
     mainTask;

}




@MainLoop {
     bossX = ObjMove_GetX(bossObj);
     bossY = ObjMove_GetY(bossObj);
     
//enemy collision
  
   
        ObjEnemy_SetIntersectionCircleToShot(bossObj, ObjMove_GetX(bossObj), ObjMove_GetY(bossObj), 32); 
        ObjEnemy_SetIntersectionCircleToPlayer(bossObj, ObjMove_GetX(bossObj), ObjMove_GetY(bossObj), 24);
      
          
		
		
  
        yield;
    
    }
    


task mainTask { 
    MagicCircle;
	renderBoss; 
	movement;
        TEnd;


} 
task MagicCircle
{    let alpha = 0;
      let spin = 0;
	  let path = GetCurrentScriptDirectory ~ "sprite/reigncircle.png";
	  

     ObjPrim_SetTexture(circleObj,path);
     ObjRender_SetBlendType(circleObj,BLEND_ADD_ARGB);
     Obj_SetRenderPriorityI(circleObj,40);
     ObjRender_SetAlpha(circleObj,120);
     ObjRender_SetScaleXYZ(circleObj,0.6,0.6,0);
     ObjSprite2D_SetSourceRect(circleObj,0,0,490,490);
     ObjSprite2D_SetDestCenter(circleObj);
     
   while(!Obj_IsDeleted(bossObj)){

       ObjRender_SetPosition(circleObj,bossX,bossY,0);
       ObjRender_SetAngleZ(circleObj,spin);
       ObjRender_SetAlpha(circleObj,alpha);

         alpha = 120;
		 spin+=-1;
		yield;
        }
    
       yield;
  
 }

task movement {
	wait(200);
	loop { 
		ObjMove_SetDestAtSpeed(bossObj,100,120,5);		// move to the left
		wait(45);
		
		ObjMove_SetDestAtSpeed(bossObj,280,120,5);		// move to the right
		
		wait(30);
	}
}


@Event {
//boss health and timer
       alternative(GetEventType())
	   
	   
       case(EV_REQUEST_LIFE) {
          SetScriptResult(1000);
       }
	   
       case(EV_REQUEST_TIMER) {
          SetScriptResult(30);
     }
	 


}

@Finalize {

}


function wait(w) { loop(w) { yield; } }


function angleToPlayer {
	let dir = atan2(GetPlayerY-bossY,GetPlayerX-bossX);
	return dir;
}

	

task TDrawLoop {
    let imgBoss = GetCurrentScriptDirectory() ~ "sprite/testsheet.png";
    ObjPrim_SetTexture(bossObj, imgBoss);
    ObjSprite2D_SetSourceRect(bossObj, 64, 1, 127, 64);
    ObjSprite2D_SetDestCenter(bossObj);
}


task TEnd 
{
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0) {
		yield;
	}
        
	Obj_Delete(bossObj);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);	
	wait(20);	
	CloseScript(GetOwnScriptID());

}