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


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


@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(life);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(80);
    }
    case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	
	animNon(objBoss);
	TFinalizeNon(objBoss);
	
    ObjMove_SetDestAtFrame(objBoss, width/2, 3*height/10, 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{
    Indicator(objBoss);
    takeDamage(objBoss, scene, life);
	ObjEnemy_SetDamageRate(objBoss, 0,0);
	wait(120);
    ObjEnemy_SetDamageRate(objBoss, 20, 0);
    wait(120);
	attack;
	wait(60);
	ObjEnemy_SetDamageRate(objBoss,100, 60);
}
task attack{
    let charge = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/Charge.WAV", 90);
    let shot1 = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK5.WAV", 40);
	let shot2 = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK4.WAV", 40);
	
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
	    ObjSound_Play(charge);
		wait(60);
		let ang = rand(0,360);
		shotSound(shot1, 240, 60, 6, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, ang, 7, -1, 300, 1, 60, 3, 0, 0, 0, 336, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 7, ang, 6, 1, 300, 1, 60, 3, 0, 0, 0, 339, objBoss, 0, false);
		wait(240);
		shotSound(shot1, 60, 60, 3, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, -45, 7, 1, 360, 1, 60, 3, 0, 0, 0, 336, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 7, -135, 6, -1, 360, 1, 60, 3, 0, 0, 0, 339, objBoss, 0, false);
		wait(60);
		shotSound(shot1, 300, 60, 6, objBoss,0);
		wait(360);
		
		ObjSound_Play(charge);
		wait(60);
		shotSound(shot2, 270, 40, 5, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 8, ang, 8, -1, 300, 1, 60, 1.4, 0, 0, 0, 152, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 7, ang, 6, 1, 300, 1, 60, 1.8, 0, 0, 0, 147, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, ang, 6, -1, 300, 1, 60, 2.5, 0, 0, 0, 141, objBoss, 0, false);
		wait(270);
		shotSound(shot2, 30, 40, 3, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, -45, 6, 1, 330, 1, 60, 2.5, 0, 0, 0, 141, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 7, -90, 4, 1, 330, 1, 60, 1.4, 0, 0, 0, 152, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 8, -45, 6, -1, 330, 1, 60, 1.8, 0, 0, 0, 147, objBoss, 0, false);
		wait(30);
		shotSound(shot2, 300, 40, 6, objBoss,0);
		wait(450);
		
		let col1= truncate(rand(75, 83));
		let col2 = truncate(rand(83,89));
		ang = rand(0,360);
		ObjSound_Play(charge);
		wait(60);
		shotSound(shot2, 200, 45, 7, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 10, ang, 5, 1, 300, 1, 60, 3, 0, 0, 0, col1, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 7, ang, 6, -1, 300, 1, 60, 4, 0, 0, 0, col2, objBoss, 0, false);
		
		wait(200);
		shotSound(shot2, 100, 45, 5, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, ang, 8, 1, 490, 1, 60, 1.5, 0, 0, 0, 153, objBoss, 0, false);
		wait(100);
		shotSound(shot2, 100, 45, 8, objBoss,0);
		wait(50);
		shotSound(shot2, 300, 45, 3, objBoss,0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, -45, 7, -1, 300, 1, 60, 1.5, 0, 0, 0, 153, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 10, -135,5 , 1, 300, 1, 60, 2, 0, 0, 0, col1, objBoss, 0, false);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 7, ang, 6, -1, 300, 1, 60, 2, 0, 0, 0, col2, objBoss, 0, false);
		wait(360);
	}
}
 
	    