//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Wavy spiral"]
#System["./../../system/NSystem.dnh"]
#Player["./../../player/Reimu by plasmaflame22/Reimu_A.txt", "./../../player/Reimu by plasmaflame22/Reimu_C.txt"]
#include "./../../ZUNShot/ZUNShot_Const.txt"
#include "./../sharedFuncSaul.dnh"


let objBoss;
let width = 444;
let height = 448;
let life = 4000;
let time= 55;
let scene = GetEnemyBossSceneObjectID();
let path = GetCurrentScriptDirectory~"./../../SFX/";

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


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	SetCommonData("non1", "yes");
	
	animNon(objBoss, 1);
	TFinalizeNon(scene, objBoss);
	
	ObjMove_SetDestAtFrame(objBoss, width/2, height/3, 60);
	Main;
}

@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 28);
    yield;
}



task Main{

    Name(1, objBoss);
    Indicator(objBoss, 1);
    takeDamage(objBoss, scene, life);
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	let shot = LoadEffect(path~"ATTACK4.WAV", 70);
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 20, 0);
	ObjSound_Play(LoadEffect(path ~"Charge.WAV", 80));
	wait(60);
	ObjEnemy_SetDamageRate(objBoss, 100, 50);
	let dir =1; if(rand(0,1)>1/2){dir=-1;}
	let delayBetweenBul = 12; let speed = rand(2,2.4); let wvel = 4; 
	let delayBetweenWvel = 35; let col1 = 285; let col2 = 292;
	shotSound(shot, 300, 65, delayBetweenBul, objBoss, false, 0, scene, 0);
	wavySpiral(4,300,dir,delayBetweenBul, speed, wvel,delayBetweenWvel,col1,col2,objBoss, 0);
	wait(300);
	dir*=-1;
	move(width/4, 3*width/4, height/5, 2*height/5, 0, 60, 390, objBoss, 0, scene, 0);
	wait(90);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    delayBetweenBul = floor(rand(12,14)); wvel = rand(3.4,4.2); delayBetweenWvel = rand(30, 38);
		speed = rand(2.2,2.4); if(wvel<4.2){speed = rand(2.6,2.8);} let period = rand(220,300);
		shotSound(shot, period, 65, delayBetweenBul, objBoss, false, 0, scene, 0);
		wavySpiral(5,period,dir,delayBetweenBul, speed, wvel,delayBetweenWvel,col1,col2,objBoss, 0); 
		wait(390);
	}
}


	
	
	
	
	
	
	