#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP1"]
#Text["Yaobi-Style Dance[r]&quot;Mermaid's Swim&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, 0, 25]);
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-200, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	OxigenController;
	WorldBG;
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2500);
     	}
	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 {
} 

let stage = 0;

task Main { 
wait(90);
let obj = Bubble(GetCenterX, GetCenterY, 0.75);
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, "Yaobi-Style Dance &quot;Mermaid's Swim&quot;", [5,5,255], path, path2, 25, 100, 1, "Megumi");
Movement;
BubbleMovement(obj);
}

task BubbleMovement(obj){
loop{
ObjMove_SetDestAtWeight(obj, GetPlayerX, GetPlayerY, 5, 0.2);
yield;
}
}

task Movement{
let a = 0;
loop{
Spiral;
ascent(i in 0..45){
ObjMove_SetDestAtWeight(objBoss, GetCenterX+200*cos(270+a), GetCenterY+200*sin(270+a), 5, 6);
a++;
yield;
}
wait(60);
}
}

task Spiral{
stage++;
let random = rand(0,360);
ascent(i in 0..25){
	ascent(j in 0..2){
	FireShotA1(BossX+(i*2)*cos(random+i*22.5+j*180), BossY+(i*2)*sin(random+i*22.5+j*180), 2, random+i*22.5+j*180, SCALE_SKY, 10);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
	wait(2);
}
if(stage > 8){
let random = rand(0,360);
	ascent(i in 0..8){
	FireShotA1(BossX+25*cos(i*360/8), BossY+25*sin(i*360/8), 1.5, random+i*360/8, ORB_M_BLUE_ADD, 10);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 90, 0);
}
}

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


