#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP2"]
#Text["Challenger[r]&quot;36.000 Feet Under the Sea&quot;"]
#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+210+90);
	EnemyMarker(objBoss);
	Aura(objBoss, [0, 25, 0]);
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	OxigenController;
	WorldBG;
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(3000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	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 {
if(GetCommonData("IsStage", false)==true){
	ascent(i in 0..90){
	SetCommonData("CameraHeight", GetCommonData("CameraHeight", 0)+2);
	yield;
	} 
}
wait(90);
let bub = Bubble(GetCenterX, GetCenterY, 0.15);
ascent(i in 0..2){
let obj = Bubble(GetCenterX+200*cos(i*360/2+90), GetCenterY+200*sin(i*360/2+90), 0.75);
Movement(obj, i*360/2+90);
ClearBullets(obj);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 45);

wait(120);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg2.png";
SpellCard(210, "Challenger &quot;36.000 Feet Under the Sea&quot;", [5,255,5], path, path2, 25, 100, 1, "Megumi");
Shoot(bub);
MovementBoss;
Shoot2;
}

task Shoot2{
wait(240);
loop{
	ascent(i in 0..8){
	FireShotA1(BossX, BossY, 1, i*360/8, ORB_L_GREEN_ADD, 20)
	}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 90, 0);
wait(180);
}
}

task MovementBoss{
let a = 0;
	loop{
	ObjMove_SetDestAtWeight(objBoss, GetCenterX+50*cos(270+a), GetCenterY+50*sin(270+a), 5, 6);
	a++;
	yield;
	}
}


task ClearBullets(obj){
loop{
let bul = GetShotIdInCircleA2(GetX(obj), GetY(obj), 90, TARGET_ENEMY);
	ascent(i in 0..length(bul)){
		if(ObjShot_GetImageID(bul[i]) == ORB_R_GREEN){
		ObjShot_FadeDelete(bul[i]);
		}
	}
yield;
}
}

task Shoot(obj){
loop{
let random = rand(0,360);
ascent(i in 0..12){
FireShotA1(GetX(obj)+10*cos(random+i*360/12), GetY(obj)+10*sin(random+i*360/12), 2, random+i*360/12, ORB_R_GREEN, 10);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
wait(15);
}
}

task Movement(obj, off){
wait(120+210+120);
let spd = 0;
loop{
ObjMove_SetPosition(obj,GetCenterX+200*cos(off), GetCenterY+200*sin(off));
if(spd < 0.75){spd+=0.01;}
off+=spd;
yield;
}
}

task end{
	/*
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("UnderwaterSpell", false);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
	*/

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


