#東方弾幕風[Single]
#ScriptVersion[3]
#Title["Mid1"]
#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);
	
	HitSound(objBoss, 50, 450);
	RenderNue(objBoss);
	DamageReduction(objBoss, 120);
	EnemyMarker(objBoss);
	
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 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(120);

let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/nue1.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/nue2.png";
SpellCard(160, "Unknown &quot;Objects of Unknown State&quot;", [255, 0, 255], path, path2, 5, 150, 0.4, "Nue");

	Trigger;
	BulletsComingFromTheBottomOfTheScreen;
	loop{
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-84, 84), GetStgFrameHeight/2-100, 5, 4);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 70, 0);
	Cross;
	wait(180);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-84, 84), GetStgFrameHeight/2-100, 5, 4);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 70, 0);
	Cross2;
	wait(180);
	}
	
	task Cross{
		ascent(i in 0..4){
		let obj = CreateShotA1(0+128*i, -10, 1, 90, ORB_L2_PURPLE_ADD, 10);
		CrossMake(obj, i*360/4, -1);
		}
	}
	task Cross2{
		ascent(i in 0..3){
		let obj = CreateShotA1(128/2+128*i, -10, 1, 90, ORB_L2_PURPLE_ADD, 10);
		CrossMake(obj, i*360/4, 1);
		}
	}
	
	task CrossMake(obj, off, mult){
		ascent(i in 0..4){
		let a = CreateStraightLaserA1(GetX(obj), GetY(obj), 0, 75, 15, 9999999, LASER_C_PURPLE, 0);
		Triggered(a,1);
		rot(a,obj,i*360/4, mult);
		bullets(a);
		}
	}
	task bullets(a){
	let len = ObjLaser_GetLength(a);
		ascent(i in 1..3){
		let obj = CreateShotA1(GetX(a), GetY(a), 0, ObjStLaser_GetAngle(a), FIREBALL_PURPLE_ADD, 0);
		Triggered(obj,0);
		ObjShot_SetAutoDelete(obj, 0);
		ObjShot_SetSpellResist(obj, 0);
		Stick(obj, a, len, i);
		}
	}
	task Stick(obj, a, len, i){
	while(!Obj_IsDeleted(a)){
	ObjMove_SetPosition(obj, GetX(a)+len/i*cos(ObjStLaser_GetAngle(a)), GetY(a)+len/i*sin(ObjStLaser_GetAngle(a)) );
	ObjMove_SetAngle(obj, GetAngleToObject(a, obj)+180);
	yield;
	}
	Obj_Delete(obj)
	}
	task rot(a,obj, off, mult){
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(a, GetX(obj), GetY(obj));
		ObjStLaser_SetAngle(a, off);
		off+=1*mult;
		yield;
		}
		Obj_Delete(a);
	}
}

task BulletsComingFromTheBottomOfTheScreen{
loop{
let X = GetPlayerX;
let A = 0;
if(GetPlayerY < 350){ 
	ascent(i in 0..15){
		let a1 = FireShotA1(X+A, GetStageDown, 0, 270+rand(-5, 5), RICE_S_PURPLE, 10);
		let a2 = FireShotA1(X-A, GetStageDown, 0, 270+rand(-5, 5), RICE_S_PURPLE, 10);
		ObjMove_AddPatternA2(a1, 60, 0, NO_CHANGE, 0.005, 0, 1);
		ObjMove_AddPatternA2(a2, 60, 0, NO_CHANGE, 0.005, 0, 1);
		A+=24;
		wait(3);
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 70, 0);
	}
}
wait(60);
}
}

task Triggered(obj, num){
let alpha = 255;
loop{
if(GetCommonData("Unknown", 0) == num){
ObjShot_SetIntersectionEnable(obj, 0);
ObjRender_SetAlpha(obj, alpha);
if(alpha>0){alpha-=5;}
}
else{
ObjShot_SetIntersectionEnable(obj, 1);
ObjRender_SetAlpha(obj, alpha);
if(alpha<255){alpha+=15;}
}
yield;
}
}

task Trigger{
loop{
wait(180);
SetCommonData("Unknown", 1);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage.wav", 70, 0);
wait(180);
SetCommonData("Unknown", 0);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage.wav", 70, 0);
}
}


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


