//東方弾幕風
//てんし
#ScriptVersion[2]

script_enemy_main{

#include_function".\lib\include_std.txt"
#include_function".\system\include_enemy_boss.txt"

let animation_counter = 0;
let boss_state = _STATE_STAND;

@Initialize{
	SetDamageRate(20,50);
	system_SetEnemyTexture("KANAME");
	system_SetEnemyType(0);
	system_SetEnemyDamageRate(1.1);

	once_system_LoadResourceBoss();
	SetLife(1200);
	system_SetEnemyLife(200);
	SetCommonDataEx("SPHERIA_ENEMY", "ENEMY_BOSSLIFE_MAX", 200);

	system_SetEnemyWeight(64);
	system_SetEnemyRadius(48);
	LoadUserShotData(GetCurrentScriptDirectory() ~ "UserShot_tenshi.txt");
	once_MainRoutine();
}

@MainLoop{
	SetCollisionA(GetX(), GetY(), 24);
	animation_counter++;
	yield;
}

@DrawLoop{
	if(system_IsInvisible()){return;}

	SetTexture(img_Enemy);
	SetGraphicScale(1.5,1.5);
	system_SetGraphicRect(["ROCK_MAIN01","ROCK_MAIN02","ROCK_MAIN03","ROCK_MAIN04"][trunc(animation_counter/5)%4]);
	DrawGraphic(GetX(), GetY());
}

@Finalize{

}



task once_MainRoutine(){
	boss_state = _STATE_STAND;

	once_system_TaskDrawTenshi();
	once_system_TaskSphereParameterChecker();
	once_system_TaskSphereHitTest();
	once_system_EnemyMain();
	once_MoveRoutine();
}

task once_MoveRoutine(){

	loop(60){yield;}
//	system_SpellCard();
	loop(60){yield;}

	loop{
		shot_laser();
		loop(100){yield;}
		shot_laser();
		loop(170){yield;}
		shot_circle(3);
		loop(90){yield;}
		if(system_GetEnemyLife() < 100){ break; }
	}

	loop{
		shot_laser();
		loop(100){yield;}
		shot_laser();
		loop(70){yield;}
		shot_circle(5);
		loop(70){yield;}
		shot_laser();
		loop(180){yield;}
	}

}//end task


task shot_circle(let num){

	ascent(i in 0..num){
		ascent(j in 0..30){
			let id = 1;
			let angle = 360 * (j/30);
			CreateShotA(id, GetX() + cos(angle) * 40, GetY() + sin(angle) * 40, 10);
			SetShotDataA(id, 0, 1, angle, [-0.11,0.11][i%2], 0.02, 3, _SHOT_RED);
			FireShot(id);
		}
		loop(30){yield;}
	}

}


task shot_laser(){


	loop(20){yield;}

	SetColor(255,0,0);
	Concentration01(50);
	SetColor(255,255,255);
	
	loop(30){yield;}

	let angle = GetAngleToPlayer();
	let id2 = 0;
	CreateLaserA(id2, GetX(), GetY(), 500, 50, _SHOT_RED, 45);
	SetLaserDataA(id2, 00, angle, 0, 0, 0, 0);
	SetShotKillTime(id2, 40);
	FireShot(id2);

	REMY_TaskDelaySE(se_Laser, 36);
	loop(25){yield;}

		ascent(j in 0..80){
			ascent(i in 0..4){
				loop(2){
					let id = 1;
					CreateShotA(id, GetX() + cos(angle) * 40+ cos(angle-90) * 2 *(2-i), GetY() + sin(angle) * 40+ sin(angle-90) * 2 *(2-i), 10);
					SetShotDataA(id, 0, 13 + rand(-4,4), angle -6+ 12 * (i/6), 0.10 * (2-i), 0, 15, _SHOT_RED);
					FireShot(id);
				}
			}
			yield;
		}

	loop(60){yield;}


}//end task






}

