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


let objBoss;
let width = 384;
let height = 448;
let life = 5000;
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, 2*height/5, 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);
    ObjEnemy_SetDamageRate(objBoss, 0,0);
	takeDamage(objBoss, scene, life);
	let charge = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/Charge.WAV", 90);
    wait(60);
	ObjEnemy_SetDamageRate(objBoss, 20,0);
	snakes;
	wait(120);
	ObjSound_Play(charge);
	wait(60);
	ObjEnemy_SetDamageRate(objBoss, 100,60);
	attack;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/2){yield;}
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK3.WAV", 80));
}

task attack{
    let shot= LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK5.WAV", 60);
	let col = [[140, 68], [150, 63], [145, 61], [148,60], [144, 71], [152, 65], [147, 59]];
	let i=0;
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    ObjSound_Play(shot);
	    let graphic = col[truncate(rand(0,6.9))];
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/2){
		    launch(objBoss, 45, -90-45*i, 60, 3.5, -0.05, -0.01, 1.1, graphic[0], 0, false, 30, 0, 0.01, 0.02, 1, false, objBoss);
		    launch(objBoss, 35, -90-45*i, 60, 3, -0.06, -0.02, 1, graphic[1], 0, false, 30, 0, 0.01, 0.02, 1, false, objBoss);
		}
		else{
		    launch(objBoss, 40, -90-45*i, 60, 3.5, -0.05, -0.01, 1.3, graphic[0], 0, false, 30, 0, 0.01, 0.02, 1, false, objBoss);
			launch(objBoss, 45, -90-45*i, 60, 3, -0.06, -0.02, 1, graphic[1], 0, false, 30, 0, 0.01, 0.02, 1, false, objBoss);
		}
		i++;
		wait(20);
	}
}


task snakes{
    let s =LoadEffect(GetCurrentScriptDirectory~ "./../SFX/snakehiss.WAV", 80);
	ObjSound_SetRestartEnable(s, true);
    let y;
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    ObjSound_Play(s);
	    y = rand(height/5, 2*height/5);
	    if(rand(0,1)>=1/2){
		    let ang = rand(-45, -10);
			ascent(i in 0..6){
				let obj = CreateShotA1(0, y, 4, ang, 333, 3*i); 
				controlWvel(obj, 3, 20, 400, 4);
				Obj_SetRenderPriorityI(obj, 60);
			}
	    }
		else{
		    let ang = rand(190, 230);
		    ascent(i in 0..6){
				let obj = CreateShotA1(width, y, 4, ang, 333, 3*i); 
				controlWvel(obj, -3, 20, 400, 4);
				Obj_SetRenderPriorityI(obj, 60);
			}
		}
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)> life/2){wait(20);}
		else{wait(10);}
	}
}
    