#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP4"]
#Text["No UT reference intended"]
#System["./default_system/Default_System.txt"]
#Background["./default_System/Default_Background.txt"]
#include"./default_system/Default_Index.txt"

let objBoss;
let BossX;
let BossY;

@Initialize {
	SetPlayerClip(126, 12, 510, 468);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-85, 5, 4);

	Initialization;
	
	Main;
	end;
} 

task Initialization{
	RenderKaisen(objBoss);
	MagicRing(objBoss);
	//WaveCircle(true, false, true, 156);
	HitSound(objBoss,60,500);
	TimerCountdown;
	SetArmor(objBoss, [90, 80], 180);
	EnemyMarker(objBoss);
	//ColorChange;
}

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(4000);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000);}
	//case(EV_REQUEST_IS_DURABLE_SPELL){SetScriptResult(true);}
	//case(EV_REQUEST_IS_LAST_SPELL){SetScriptResult(true);}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	SetCommonData("BossX", BossX);
	SetCommonData("BossY", BossY);
	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(45);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Kaisen.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Kaisen.png";
SetCommonData("SP", "Kaisen");
SetCommonData("StgFrameColor", [255, 126, 0]);
SpellCard(180, "Spear Tactics &quot;Drunken-Style Rush&quot;", [255, 126, 0], path, path2, 0, 0, 1);
Spears;
loop{
let a = rand(0, 100);
ascent(i in 0..22){
	let obj = FireShotA1(GetStageRight-10, GetStageUp+a, 4, 5, DB_BULLET_GREY, 10);
	ObjRender_SetColor(obj, 255, 126, 0);
	BounceX(obj, 12);
	let obj2 = FireShotA1(GetStageLeft+10, GetStageUp+a, 4, 180-5, DB_BULLET_GREY, 10);
	ObjRender_SetColor(obj2, 255, 126, 0);
	BounceX(obj2, 12);
	PlaySound("lensmbullet", 65, 0);
	wait(2);
}
wait(60);
}

}

task Spears{
wait(60*4);
loop{
	loop(3){
		let p = Spear(BossX, BossY, 0.5);
		Rotate(p);
		ObjMove_SetDestAtWeight(p, BossX+100*cos(GetAngleToPlayer(objBoss)+180), BossY+100*sin(GetAngleToPlayer(objBoss)+180), 5, 4);
	PlaySound("warning", 75, 0);
	wait(45);
	}
wait(60*3);
}
task Rotate(p){
let a = -90;
	loop(60*2){
	Obj_SetValue(p, "Angle", 180+ObjMove_GetAngle(p)+360*cos(a));
	if(a != 0){a+=1;}
	yield;
	}
	Obj_SetValue(p, "Angle", 180+ObjMove_GetAngle(p));
	PlaySound("lensmlaser", 75, 0);
	ObjMove_AddPatternA2(p, 0, 0, 180+ObjMove_GetAngle(p), 0.1, 0, 10);
	while(!Obj_IsDeleted(p)){
	let aa = CreateShotB2(GetX(p), GetY(p), 1*cos(ObjMove_GetAngle(p)+90), 1*sin(ObjMove_GetAngle(p)+90), 0, -0.5, 10, -10, KNIFE_GREY, 5);
	let ab = CreateShotB2(GetX(p), GetY(p), 1*cos(ObjMove_GetAngle(p)-90), 1*sin(ObjMove_GetAngle(p)-90), 0, -0.5, 10, -10, KNIFE_GREY, 5);
	BounceY(aa, 1);
	BounceY(ab, 1);
	PlaySound("lensmbullet", 55, 0);
	wait(4);
	}
}

}

task BounceY(obj, time){
	let count = 0;
	while(!Obj_IsDeleted(obj) && count < time){
	if(true){
		if(GetY(obj) < GetStageUp){
		ObjMove_SetY(obj,GetStageUp);
		let spd = 1;
		let ang = ObjMove_GetAngle(obj);
		let ran = rand(-10, 10);
		ObjMove_AddPatternB2(obj, 0, spd*cos(360 - ang), spd*sin(360 - ang), ran/150, 0.02, ran, 10);
		PlaySound("spirit", 55, 0);
		count++;
		}
	}
	else{}
	yield;
	}
}

task BounceX(obj, time){
	let count = 0;
	while(!Obj_IsDeleted(obj) && count < time){
	if(true){
		if(GetX(obj) < GetStageLeft){
		ObjMove_SetX(obj,GetStageLeft);
		let spd = 12;
		let ang = ObjMove_GetAngle(obj);
		ObjMove_AddPatternB2(obj, 0, spd*cos(180 - ang), spd*sin(180 - ang), -0.2, 0, -10, 10);
		PlaySound("spirit", 35, 0);
		count++;
		}
	}
	else{}
	if(true){
		if(GetX(obj) > GetStageRight){
		ObjMove_SetX(obj,GetStageRight);
		let spd = 12;
		let ang = ObjMove_GetAngle(obj);
		ObjMove_AddPatternB2(obj, 0, spd*cos(180 - ang), spd*sin(180 - ang), 0.2, 0, 10, 10);
		PlaySound("spirit", 35, 0);
		count++;
		}
	}
	else{}
	yield;
	}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("BossX2", BossX);
	SetCommonData("BossY2", BossY);
	NotifyEvent(GetStageID, EV_USER_STAGE, [true, true, true, false, false, false]); //smexplosion, smparticles, items, bigexplosion, bigparticles, shake+slow
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 