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


let objBoss;
let width = 384;
let height = 448;
let life = 6000;
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, 20, 0);
    let shot2 = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK5.WAV", 70);
	let shot1 = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK4.WAV", 60);
	let twinkle = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/TWINKLE.WAV", 70);
	let twinkle2 = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/TWINKLE2.WAV", 70);
    wait(60);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../SFX/Charge.WAV", 90));
	wait(60);
	ObjEnemy_SetDamageRate(objBoss, 100,60);
	let col = [[365, 367], [367,365], [366, 369], [369,366]];
	let t=0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
	    let col1 = truncate(rand(363,370));
		let col2= truncate(rand(293, 300));
		let col3= truncate(rand(59,73));
	    let graphic = col[truncate(rand(0,3.9))];
		shotSound(shot1, 120, 60, 10, objBoss,0);
	    spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 4, 90, 10, -1, 300, 1, 60, 4, 0, 0, 0, graphic[0], objBoss, 0, false);
	    wait(120);
		shotSound(shot1, 180, 60, 5, objBoss,0);
	    spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, GetAngleToPlayer(objBoss), 12, 1, 180, 1, 60, 3, 0, 0, 0, graphic[1], objBoss, 0, false);
		wait(300);
		let ang= rand(0,360);
		loop(4){
		    ObjMove_SetDestAtFrame(objBoss, rand(width/5, 4*width/5), rand(height/10, 3*height/10), 30);
			wait(30);
			ObjSound_Play(shot2);
			ascent(i in 0..30){CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 4, ang + i*360/29, 370, 0);}
		}
		loop(4){
		    ObjMove_SetDestAtFrame(objBoss, rand(width/5, 4*width/5), rand(height/10, 2*height/5), 60);
			wait(80);
			ObjSound_Play(shot2);
			ascent(i in 0..45){
			    ascent(j in 0..10){CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5-4*j/9, GetAngleToPlayer(objBoss) + i*360/44, 93+j, 0);}
			}
			wait(10);
			ObjSound_Play(twinkle);
		}
		wait(60);
        loop(4){
        	ObjMove_SetDestAtFrame(objBoss, rand(width/5, 4*width/5), rand(height/10, 3*height/10), 60);
			wait(60);
			ObjSound_Play(shot2);
			CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, GetAngleToPlayer(objBoss), col1, 0);
			wait(10);
			ObjSound_Play(twinkle2);
			launch(objBoss, 10, GetAngleToPlayer(objBoss), 20, 4, -0.06, -0.02, 2.5, col2, 0, false, 0,0,0,0,0,false, objBoss);
			wait(10);
			launch(objBoss, 35, GetAngleToPlayer(objBoss), 50, 3, -0.05, -0.01, 1.2, col3, 0, false, 0,0,0,0,0,false, objBoss);
		}
		ObjMove_SetDestAtFrame(objBoss, rand(width/5, 4*width/5), rand(height/10, 2*height/5), 60);
        wait(120);		
	}
}

