#東方弾幕風[Single]
#ScriptVersion[3]
#Title["And something else too."]
#Text["No, I won't leave[r]my memes to Zaro."]
#System["./default_system/Meem_Default.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-100, 5, 4);

	Initialization;
	
	Main;
	end;
} 

task Initialization{
	RenderKaisen(objBoss);
	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(1337);}
	//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{
SetCommonData("StgFrameColor", [255, 255, 255]);
ascent(i in 0..32){
SetCommonData("StgFrameColor", [255-i*4, 255-i*8, 255-i*8]);
yield;
}
loop{
ascent(i in 0..32){
SetCommonData("StgFrameColor", [126, 0+i*4, 0]);
yield;
}
ascent(i in 0..32){
SetCommonData("StgFrameColor", [126-i*4, 126, 0]);
yield;
}
ascent(i in 0..32){
SetCommonData("StgFrameColor", [0, 126, 0+i*4]);
yield;
}
ascent(i in 0..32){
SetCommonData("StgFrameColor", [0, 126-i*4, 126]);
yield;
}
ascent(i in 0..32){
SetCommonData("StgFrameColor", [0+i*4, 0, 126]);
yield;
}
ascent(i in 0..32){
SetCommonData("StgFrameColor", [126, 0, 126-i*4]);
yield;
}
}
}

task Main { 
wait(60);
SetCommonData("Memery", 1);
NotifyEventAll(EV_USER+1, 0);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Kaisen.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Kaisen.png";
SetCommonData("SP", "Kaisen");
SpellCard(180, "&quot;Spear of Justice&quot;", [255, 255, 255], path, path2, 0, 150, 1);

loop{
RotateSpears;
FloorSpears;
ShootSpears;
}
}

function ShootSpears{
let a = 1;
loop(12){
let angle = rand(0,360);
	ascent(j in 0..7){
	let p = Spear(GetPlayerX+200*cos(j*360/7+angle), GetPlayerY+200*sin(j*360/7+angle), 0.5);
	Rotate(p, j*360/7+angle);
	}
	PlaySound("spawn", 100, 10);
a = -a;
wait(30);
}
wait(60);
task Rotate(p, ang){
let a = -90;
	loop(60){
	Obj_SetValue(p, "Angle", ang+360*cos(a*2));
	if(a != 0){a+=1;}
	yield;
	}
	Obj_SetValue(p, "Angle", 180+ang);
	wait(30);
	ObjMove_AddPatternA2(p, 0, 10, ang+180, 0.1, 0, 10);
	PlaySound("fire", 100, 0);
	wait(20);
	Obj_Delete(p);
}

}

function FloorSpears{
let a = 1;
loop(16){
	ascent(i in 0..3){
	let p = Spear(rand(GetStageLeft, GetStageRight), GetStageDown, 0.5);
	Go(p);	
	}
	PlaySound("spawn", 100, 10);
wait(15);
}
task Go(p){
	Obj_SetValue(p, "Angle", 270);
	wait(60);
	ObjMove_AddPatternA2(p, 0, 10, 270, 0.1, 0, 10);
	PlaySound("fire", 100, 0);
}

}

function RotateSpears{
let a = 1;
loop(6){
let angle = rand(0,360);
	ascent(j in 0..7){
	let p = Spear(GetPlayerX+100*cos(j*360/7+angle), GetPlayerY+100*sin(j*360/7+angle), 0.5);
	Rotate(p, GetPlayerX, GetPlayerY, j*360/7+angle, a);
	}
	PlaySound("spawn", 100, 10);
a = -a;
wait(60);
}
task Rotate(p, x, y, off, mult){
	let rad = 400;
	let spd = 2;
	loop(60*2){
	ObjMove_SetPosition(p, x+rad*cos(off), y+rad*sin(off));
	Obj_SetValue(p, "Angle", GetAngleToPoint(GetX(p), GetY(p), x, y)+180);
	rad-= 3;
	off += spd*mult;
	spd -= 0.005;
	yield;
	}
	Obj_Delete(p);
}

}


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
	SetCommonData("BossX2", BossX);
	SetCommonData("BossY2", BossY); 
	Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 