#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP8"]
#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);
	
	EnemyMarker(objBoss);
	HitSound(objBoss, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 320);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 10, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(55);
	}
	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 { 
	let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/cutin.png";
	SpellCard(210, "", [255, 60, 60], path, path, 20, 0.75, "Okina");
	
	ascent(j in 1..8){
	IceBall(j*360/16+180, 2);
	}
	wait(60*4);
	loop{
	loop(8){
	IceBall(GetAngleToPlayer(objBoss)+180, 3);
	wait(45);
	}
	ascent(j in 1..8){
	IceBall(j*360/16+180, 2);
	}
	ascent(j in 0..16){
	let las = CreateStraightLaserA1(BossX, BossY, GetAngleToPlayer(objBoss)+j*360/16, 500, 15, 60, LASER_BLUE, 60);
	ObjCrLaser_SetTipDecrement(las, 0);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser1.wav", 80, 0);
	}
	
	task IceBall(ang, spd){
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
	let obj = FireShotA1(BossX, BossY, spd, ang, ORB_L2_BLUE_ADD, 20);
	Ice(obj);
		task Ice(obj){
			while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetY(obj)<GetStageUp){IceCrystals(obj);}
			if(ObjMove_GetY(obj)>GetStageDown){IceCrystals(obj);}
			if(ObjMove_GetX(obj)<GetStageLeft){IceCrystals(obj); ObjMove_SetX(obj, 5);}
			if(ObjMove_GetX(obj)>GetStageRight){IceCrystals(obj);ObjMove_SetX(obj, GetStageRight-5);}
			yield;
			}
		}
		
		task IceCrystals(obj){
		let X = GetX(obj);
		let Y = GetY(obj);
		let angle = ObjMove_GetAngle(obj);
		let switch = -1;
		let switch2 = 0;
		ObjMove_AddPatternA1(obj, 0, 2, 90);
			ascent(j in 0..24){
			switch2 = 0;
			let shot = FireShotA1(X+5*switch, Y+5*j, 0, angle+180+j*4*switch, ICE_SKY, 10);
			ObjMove_AddPatternA2(shot, 60, NO_CHANGE, NO_CHANGE, 0.05, 0, 2);
			if(switch == -1 && switch2 == 0){switch = 1; switch2 = 1;}
			if(switch == 1 && switch2 == 0){switch = -1; switch2 = 1;}
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
			wait(2);
			}
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 2500){
			ascent(i in 0..12){
			let las = CreateStraightLaserA1(GetX(obj), GetY(obj), 90+i*360/12+i*360/24, 750, 25, 60, LASER_SKY, 60);
			ObjCrLaser_SetTipDecrement(las, 0);
			}
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser1.wav", 80, 0);
		}
		ObjShot_FadeDelete(obj);
		}
	}
}

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


