#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["JunkoNon1"]
#Text["By Lusus"]
#include ".\Functions.dnh"
#Background[".\JunkoBackground.dnh"]
#BGM[".\se/junko.ogg"]
#System[".\default_system/Default_System.txt"]

let objBoss; //global variable, can be used anywhere
let objScene = GetEnemyBossSceneObjectID(); //declares global variable enemy boss scene object


@Event{
	alternative(GetEventType())
    case(EV_REQUEST_LIFE){ //Sets boss's life
        SetScriptResult(2000);
    }
    case(EV_REQUEST_TIMER){ //Sets attack time
        SetScriptResult(40);
    }
    case(EV_REQUEST_SPELL_SCORE){ //Spellcard bonus
        SetScriptResult(1000000);
    }
}

@Initialize{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS); //gives the variable a value, object ID that makes it a boss
	ObjEnemy_Regist(objBoss); //registers it as an enemy
	ObjMove_SetDestAtFrame(objBoss, GetCenterX(), 110, 60); //moves boss to destination

 //declares spellcard
	TDrawLoop; //calls TDrawLoop task
	TFinalize; //calls TFinalize task
	MainTask; //calls MainTask task
}

@MainLoop{
	ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
	// CircleToShot means any player shoot hitting this will damage the boss, CircleToPlayer kills the player on colission
	yield; //necessary for task functions to work
}

task MainTask {
	wait(90);
	chargeeffect;
	wait(55);
	ObjEnemy_SetDamageRate(objBoss, 60, 34);
	wait(30);
	fireA;
}

task fireA {
	let posneg = 1;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		let angleT = GetAngleToPlayer(objBoss);
		let c = 0;
		let n = 200;
		let acc = -0.01;
		let accp = -0.0015;
		let maxs = 0.9;
		let s = 3.3;
		loop(3){ 
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 0){return;}
			loop(n){
				let bullet = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), s, angleT, -0, 0.4, 539, 0);
				speed(bullet, acc, maxs);
				angleT += 360/n * posneg;
				acc += accp;
				c+= 1;
				if(c==4){acc = -0.01; c = 0;}
			}
			posneg *= -1;
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){SE_Play(shot1, shot1v);}
			wait(20);
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){SE_Play(kira3, kira3v);}
		}
		wait(30);
		bmovement(30, 50, 0, 0, 35);

		wait(60);
	}
}

task speed(bullet, acc, maxs){
	ObjMove_AddPatternA2(bullet, 5, NO_CHANGE, NO_CHANGE, acc, 0, maxs);
	enddelete(bullet);
}