//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["BGMChange"]
#include "./../ZUNShot/ZUNShot_Const.txt"
#include "./sharedfuncJames.dnh"

let objBoss;
let width = 384;
let height = 448;
let life = 1;
let scene= GetEnemyBossSceneObjectID();


@Event{                                
    alternative(GetEventType())       
    case(EV_REQUEST_LIFE){           
        SetScriptResult(life); 
    }
    case(EV_REQUEST_TIMER){        
        SetScriptResult(23);
    }
}


@Initialize{                                  
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);   
    ObjEnemy_Regist(objBoss);
	anim;
	
	ObjMove_SetDestAtFrame(objBoss, width/2, 3*height/10, 60);
	TFinalizeNon(objBoss);
	
    MainTask;
}



@MainLoop{     
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32);            // boss hurtbox (what the player must shoot)
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 28);          // boss hitbox (what the player must avoid)
	yield;
}

task MainTask{
    Indicator(objBoss);
    SetForbidPlayerShot(true);
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	wait(60);
	NotifyEventAll(EV_USER_STAGE + 2, 0);
	wait(180);
	let shot = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK4.WAV", 30);
	while(ObjEnemyBossScene_GetInfo(scene, INFO_TIMER)> 1){
		let col1 = truncate(rand(91, 99));
		let col2 = truncate(rand(99, 105));
		shotSound(shot, 240, 20, 3, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 13, rand(0,360), 7, -1, 300, 0.5, 60, 2, 0, 0, 0, col1, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 11, rand(0,360), 5, 1, 300, 0.5, 60, 2, 0, 0, 0, col2, objBoss, 0, false);
		wait(240);
		shotSound(shot, 60, 20, 2, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 16, rand(0,360), 7, 1, 300, 0.5, 60, 2, 0, 0, 0, col1, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 13, rand(0,360), 5, -1, 300, 0.5, 60, 2, 0, 0, 0, col2, objBoss, 0, false);
		wait(60);
		shotSound(shot, 240, 20, 3, objBoss,0);
		wait(300);
	}
	ObjEnemy_SetLife(objBoss, 0);
}


task anim{
    let img = GetCurrentScriptDirectory() ~ "../img/NonSpell.png";
	ObjPrim_SetTexture(objBoss, img);
	ObjSprite2D_SetSourceRect(objBoss, 316, 70, 436, 410); 
	ObjSprite2D_SetDestRect(objBoss, -25, -70, 25, 70);
}