#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS1"]
#Text["Blep"]
#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, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 120);
	EnemyMarker(objBoss);
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	WorldBG;
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(45);
	}
	/*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 {
} 

task Main { 
wait(90);

	loop{
	Attack(60+120);
	Charge(BossX, BossY, 60, 2, [122, 0, 122]);
	wait(60);
	Shot(1);
	wait(60*3.5);
	Attack(60+120);
	wait(60);
	Shot(-1);
	wait(60*3.5);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-150, 5, 4);
	wait(120);
	Attack(240+90);
		loop(2){
		Shot2(1);
		wait(120+45);
		Shot2(-1);
		wait(120+45);
		}
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);
	wait(120);
	}
	
}

task Shot(mult){
let chn = 79;
let time = 75;
	ascent(j in 0..time){
		ascent(i in 0..8){
		FireShotA1(BossX+(time-j)*cos((j*chn*mult)+i*360/8), BossY+(time-j)*sin((j*chn*mult)+i*360/8), 4, (j*chn*mult)+i*360/8, ORB_M_YELLOW_ADD, 10);
		}
	if(j>time/2){chn = 74;}
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	wait(2);
	}
}

task Shot2(mult){
let chn = 68;
let time = 75;
	ascent(j in 0..time){
		ascent(i in 0..8){
		FireShotA2(BossX+(time-j)*cos((j*chn*mult)+i*360/8), BossY+(time-j)*sin((j*chn*mult)+i*360/8), 2, (j*chn*mult)+i*360/8, 0.05, 8, ORB_M_BLUE_ADD, 10);
		}
	if(j>time/2){chn = 78;}
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	wait(2);
	}
}

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());
	
} 


