#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP9"]
#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-110, 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");
	
	Stars;
	
	wait(120);
	loop{
	ELR;
	wait(180);
	ELR2;
	wait(180);
	}
}

task ELR{
	ascent(j in -12..13){
	let obj = FireShotB2(BossX, BossY, 0+j/2.5, 2, 0, -0.04, 10, -10, STAR_S_YELLOW, 10);
	Laser(obj);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
	wait(2);
	}
}
task ELR2{
	descent(j in -12..13){
	let obj = FireShotB2(BossX, BossY, 0+j/2.5, -2, 0, 0.04, 10, 10, STAR_S_YELLOW, 10);
	Laser(obj);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
	wait(2);
	}
}
		task Laser(obj){
			while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetY(obj)<GetStageUp){LaserDown(obj);}
			if(ObjMove_GetY(obj)>GetStageDown){LaserUp(obj);}
			yield;
			}
		}
		task LaserDown(obj){
		let las = CreateStraightLaserA1(GetX(obj), GetY(obj), 90+rand(-5, 5), 500, 15, 60, LASER_YELLOW, 50);
		ObjStLaser_SetSource(las, 1);
		ring(obj);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser1.wav", 90, 0);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
		Obj_Delete(obj);
		}
		task LaserUp(obj){
		let las = CreateStraightLaserA1(GetX(obj), GetY(obj), 270+rand(-5, 5), 500, 15, 60, LASER_YELLOW, 50);
		ObjStLaser_SetSource(las, 1);
		ring(obj);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/laser1.wav", 90, 0);
		PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
		Obj_Delete(obj);
		}
		
		task ring(obj){
		let random = rand(0,360);
			ascent(i in 0..12){
			let shot = FireShotA2(GetX(obj), GetY(obj), 2, random+i*360/12, -0.05, 0, ORB_S_YELLOW_ADD, 10);
			ObjMove_AddPatternA2(shot, 60, NO_CHANGE, NO_CHANGE, 0.01, 0, 1);
			}
		}

task Stars{
let a = 0;
loop{
ascent(i in 0..32){
FireShotA1(BossX, BossY, 3, i*360/32+a*360/64, ORB_R_BLUE, 10);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
wait(30);
a++;
}
}

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


