#東方弾幕風[Single]
#ScriptVersion[3]
#Title["NS4"]
#Text["And that's a froggo"]
#System["./default_system/Default_System.txt"]
#Background["./default_System/Default_Background.txt"]
#include"./default_system/Default_Index.txt"

let objBoss;
let objEn;
	
let BossX;
let BossY;

@Initialize {
	SetPlayerClip(126, 12, 510, 468);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	objEn = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objEn);
	
	ObjMove_SetPosition(objEn, GetCommonData("BossX", 0), GetCommonData("BossY", 0));
	ObjMove_SetDestAtWeight(objEn, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);

	Initialization;
	
	Main;
	end;
} 

task Initialization{
	SetCommonData("StgFrameColor", [0, 126, 255]);
	RenderKujiru(objEn);
	MagicRing(objEn);
	HitSound(objEn,60,500);
	TimerCountdown;
	SetArmor(objEn, [90, 80], 180);
	EnemyMarker(objEn);
	
	RenderKaisen(objBoss);
	MagicRing(objBoss);
	HitSound(objBoss,60,500);
	SetArmor(objBoss, [90, 80], 180);
	EnemyMarker(objBoss);
	
}

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(5000);}
	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 ColorChange{
ascent(i in 0..64){
SetCommonData("StgFrameColor", [0+i*4, 126, 255-i*4]);
yield;
}
}

task Main { 
wait(120);

ObjMove_SetDestAtWeight(objEn, -120, -120, 8, 4);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 8, 4);
ColorChange;
wait(120);
Pattern;
}

task Pattern{

	loop{
		ascent(j in 0..24){
		let obj = FireShotA2(BossX, BossY, 0, 0+j/2, 0.24, 10, KNIFE_GREY, 10);
		BounceX(obj, 4);
		let obj2 = FireShotA2(BossX, BossY, 0, 180-j/2, 0.24, 10, KNIFE_GREY, 10);
		BounceX(obj2, 4);
		PlaySound("lensmbullet", 75, 0);
		yield;
		}
		ascent(j in 0..48){
		let obj3 = FireShotA2(BossX, BossY, 0, 270, 0.12, 10, KNIFE_BLACK, 10);
		BounceY2(obj3, 4);
		BounceX(obj3, 4);
		PlaySound("lensmbullet", 75, 0);
		yield;
		}
		
		wait(60*4);
		ascent(j in 0..40){
		let obj = FireShotA2(BossX, BossY, 0, 0, 0.24, 10, KNIFE_GREY, 10);
		BounceX2(obj, 3);
		let obj2 = FireShotA2(BossX, BossY, 0, 180, 0.24, 10, KNIFE_GREY, 10);
		BounceX2(obj2, 3);
		PlaySound("lensmbullet", 75, 0);
		yield;
		}
		wait(60*4);
		ascent(i in 0..8){
		let random = rand(0,360);
			ascent(j in 0..24){
			let obj = FireShotB2(BossX, BossY, 2*cos(j*360/24+random), 2*sin(j*360/24+random), 0, -0.05, 0, -10, KNIFE_GREY, 10);
			BounceY(obj, 4);
			}
		PlaySound("lenlabullet", 75, 0);
		wait(30);
		}
		wait(60);
	}
}

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 = ObjMove_GetSpeed(obj);
		let ang = ObjMove_GetAngle(obj);
		ObjMove_AddPatternB2(obj, 0, spd*cos(360 - ang), spd*sin(360 - ang), 0, 0.2, 10, 5);
		PlaySound("spirit", 45, 0);
		count++;
		}
	}
	else{}
	yield;
	}
}

task BounceY2(obj, time){
	let count = 0;
	while(!Obj_IsDeleted(obj) && count < time){
	if(true){
		if(GetY(obj) < GetStageUp){
		ObjMove_SetY(obj,GetStageUp);
		let spd = rand(1, 4);
		let ang = ObjMove_GetAngle(obj)+rand(-90, 90);
		ObjMove_AddPatternB2(obj, 0, spd*cos(360 - ang), spd*sin(360 - ang), 0, 0.04, 10, 5);
		PlaySound("spirit", 45, 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 = 8;
		let ang = ObjMove_GetAngle(obj)+rand(-(10-count*2.5), (10-count*2.5));
		ObjMove_AddPatternB2(obj, 0, spd*cos(180 - ang), spd*sin(180 - ang), -0.2, 0, -10, 10);
		PlaySound("spirit", 60, 0);
		count++;
		}
	}
	else{}
	if(true){
		if(GetX(obj) > GetStageRight){
		ObjMove_SetX(obj,GetStageRight);
		let spd = 8;
		let ang = ObjMove_GetAngle(obj)+rand(-(10-count*2.5), (10-count*2.5));
		ObjMove_AddPatternB2(obj, 0, spd*cos(180 - ang), spd*sin(180 - ang), 0.2, 0, 10, 10);
		PlaySound("spirit", 60, 0);
		count++;
		}
	}
	else{}
	yield;
	}
}

task BounceX2(obj, time){
	let count = 0;
	while(!Obj_IsDeleted(obj) && count < time){
	if(true){
		if(GetX(obj) < GetStageLeft){
		ObjMove_SetX(obj,GetStageLeft);
		let spd = 8;
		let spd2 = rand(1, 3);
		let ang = ObjMove_GetAngle(obj)+rand(-(10-count*2.5), (10-count*2.5));
		if(count == 2){
		ObjMove_AddPatternB2(obj, 0, spd2*cos(180 - ang), spd2*sin(180 - ang), 0, 0, -10, 10);
		}
		else{
		ObjMove_AddPatternB2(obj, 0, spd*cos(180 - ang), spd*sin(180 - ang), 0, 0.02, -10, 10);
		}
		PlaySound("spirit", 60, 0);
		count++;
		}
	}
	else{}
	if(true){
		if(GetX(obj) > GetStageRight){
		ObjMove_SetX(obj,GetStageRight);
		let spd = 8;
		let spd2 = rand(1, 3);
		let ang = ObjMove_GetAngle(obj)+rand(-(10-count*2.5), (10-count*2.5));
		if(count == 2){
		ObjMove_AddPatternB2(obj, 0, spd2*cos(180 - ang), spd2*sin(180 - ang), 0, 0, -10, 10);
		}
		else{
		ObjMove_AddPatternB2(obj, 0, spd*cos(180 - ang), spd*sin(180 - ang), 0, 0.02, 10, 10);
		}
		PlaySound("spirit", 60, 0);
		count++;
		}
	}
	else{}
	yield;
	}
}



task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	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());
} 