#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS3"]
#Text["WATER AND MOAR WATER"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;
let BossX;
let BossY;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	HitSound(objBoss, 80, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 120);
	EnemyMarker(objBoss);
	Aura(objBoss, [25, 0, 0]);
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	OxigenController;
	WorldBG;
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(50);
	}
	/*case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}*/
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
	yield;
} 

@Finalize {
} 

let gAng = 90;

task Main { 
wait(180);
let bub = Bubble(GetPlayerX, GetPlayerY, 0.15);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 45);
Move(bub);
Height;
let obj = CreateStraightLaserA1(BossX, BossY, gAng, 100, 50, 99999999999, ARROW_RED, 0);
Follow(obj);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/barrage.wav", 90, 0);
wait(60);
AngleManager;
Movement;
loop{
let random = rand(80, 100);
let random2 = rand(0,360);
ascent(j in 0..12){
let a = FireShotA1(BossX+random*cos(j*360/12), BossY+random*sin(j*360/12), 2, gAng, ORB_R_RED, 25);
Angler(a);
}
ascent(j in 0..32){
let a = FireShotA1(BossX+random*cos(random2+j*360/32), BossY+random*sin(random2+j*360/32), 2.5, random2+j*360/32, ORB_M_RED, 25);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
wait(60);
}

task Move(obj){
loop{
ObjMove_SetDestAtWeight(obj, GetPlayerX, GetPlayerY, 5, 0.4);
yield;
}
}

task Movement{
loop{
ObjMove_SetDestAtWeight(objBoss, GetPlayerX+rand(-50, 50), GetStgFrameHeight/2-100-rand(-25, 25), 5, 4);
wait(120);
}
}

task AngleManager{
let a = 0;
loop{
gAng = GetAngleToPlayer(objBoss)+5*sin(a);
a++;
yield;
}
}

task Height{
	loop{
	SetCommonData("CameraHeight", GetCommonData("CameraHeight", 0)+0.25);
	yield;
	} 
}

task Angler(obj){
	loop{
	ObjMove_SetAngle(obj, gAng);
	yield;
	}
}
}

task Follow(obj){
loop{
ObjMove_SetPosition(obj, BossX, BossY);
ObjStLaser_SetAngle(obj, gAng);
yield;
}
}

/*
ascent(i in 0..180){
//SetCommonData("CameraHeight", i);
yield;
}
*/

task end{

     while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("bossx", BossX);
	SetCommonData("bossy", BossY);
	SetCommonData("RipNon", 1);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
	
} 


