#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS9"]
#Text["Blep"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;
let BossX;
let BossY;

@Initialize {
	WinterBG;
	SeasonEffect;
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	EnemyMarker(objBoss);
	HitSound(objBoss, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 120);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 10, 4);
	
	if(GetCommonData("IsStage", false)==false){
	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(60*2);
	
	ascent(j in 0..3){
	let obj = CreateShotA1(BossX, BossY, 0, 0, ORB_L2_SKY, 10);
	ObjShot_SetSpellResist(obj, 1);
	Rotate(obj, j*360/3);
	Shoot(obj, ORB_S_BLUE);
	}
	ascent(j in 0..3){
	let obj = CreateShotA1(BossX, BossY, 0, 0, ORB_L2_BLUE, 10);
	ObjShot_SetSpellResist(obj, 1);
	Rotate(obj, j*360/3+60);
	Shoot(obj, ORB_S_SKY);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
	
	loop{
	ascent(j in 0..6){
	let random = rand(0,360);
	ascent(k in 0..24){
	FireShotA2(BossX, BossY, 6, random+k*360/24, -0.08, 1.2, KUNAI_SKY, 10);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
	wait(12);
	}
	wait(60);
	}
}

task Shoot(obj, graph){
wait(60);
	loop{
	let a = 0;
	let randy = rand(0,360);
		loop(20){
			ascent(j in 0..6){
			FireShotA1(GetX(obj), GetY(obj), 2, randy+a+j*360/6, graph, 10);
			}
		a+=12;
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
		wait(8);
		}
		wait(120);
		loop(3){
		let random = rand(0,360);
		loop(12){
			ascent(j in 0..3){
			FireShotA1(GetX(obj), GetY(obj), 2, random+a+j*360/3, graph, 10);
			}
		a+=6;
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
		wait(2);
		}
		wait(60);
		}
		wait(120);
		loop(8){
		let random = rand(0,360);
		loop(12){
			ascent(j in 0..3){
			FireShotA1(GetX(obj), GetY(obj), 2, random+a+j*360/3, graph, 10);
			}
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
		a+=0.2;
		wait(2);
		}
		wait(15);
		}
	}
}

task Rotate(obj, off){
let rad = 0;
let a = 2;
loop{
ObjMove_SetPosition(obj, BossX+rad*cos(off), BossY+rad*sin(off) );
if(rad<75){rad+=a; a-=0.025;}
off++;
yield;
}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 


