//東方弾幕風
//てんし
#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(1);
	system_SetEnemyDamageRate(1.0);
	once_system_LoadResourceBoss();
	SetLife(1500);
	system_SetEnemyLife(500);
	system_SetEnemyWeight(15);
	system_SetEnemyRadius(48);
	SetCommonDataEx("SPHERIA_ENEMY", "ENEMY_BOSSLIFE_MAX", 500);
	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(){

//	system_SpellCard();

	let angle_base = 0;
	loop(100){ yield; }
	boss_CreateKanameStoneA(GetX() + 100*cos(angle_base), GetY() + 100*sin(angle_base));
	boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 120), GetY() + 100*sin(angle_base + 120));
	boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 240), GetY() + 100*sin(angle_base + 240));

	loop(200){ yield; }
	angle_base = 60;
	boss_CreateKanameStoneA(GetX() + 100*cos(angle_base), GetY() + 100*sin(angle_base));
	boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 120), GetY() + 100*sin(angle_base + 120));
	boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 240), GetY() + 100*sin(angle_base + 240));

	let attack_count = 1;
	loop{
		loop(150){ yield; }
		angle_base += 40;
		boss_CreateKanameStoneA(GetX() + 100*cos(angle_base), GetY() + 100*sin(angle_base));
		boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 120), GetY() + 100*sin(angle_base + 120));
		boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 240), GetY() + 100*sin(angle_base + 240));
		if(system_GetEnemyLife() < 250){ break; }
		attack_count --;
		if(attack_count <= 0){
			boss_CreateKanameStoneB("TA");
			attack_count = 2;
		}
	}

	attack_count = 4;
	loop{
		loop(100){ yield; }
		angle_base += 30;
		boss_CreateKanameStoneA(GetX() + 100*cos(angle_base), GetY() + 100*sin(angle_base));
		boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 120), GetY() + 100*sin(angle_base + 120));
		boss_CreateKanameStoneA(GetX() + 100*cos(angle_base + 240), GetY() + 100*sin(angle_base + 240));
		attack_count --;
		if(attack_count <= 0){
			boss_CreateKanameStoneB("TB");
			attack_count = 3;
		}
	}


}//end task


task boss_CreateKanameStoneA(let x, let y){

	system_CreateDanger(x, y);
	loop(60){yield;}
	PlaySE(se_Create);
	CreateEnemyFromScript("KANAME", x, y, 0, 0, 0);

}//

task boss_CreateKanameStoneB(let type){

	SetColor(255, 0, 0);
	Concentration01(60);
	SetColor(255, 255, 255);
	loop(60){yield;}
	
	create_stone(true);
	loop(30){yield;}
	create_stone(false);

	task create_stone(let flag){
		let angle_base = rand(240, 300);
		ascent(i in 0..15){
			PlaySE(se_Create);
			let angle = angle_base + [-1,1][flag] * (i/15) * 270;
			CreateEnemyFromScript(type, GetX(), GetY(), rand(2,4), angle, [0]);
			loop(2){yield;}
		}
	}

}//

}//end script



////------------------------------------------
script_enemy KANAME{


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

let animation_counter = 0;
let initialize_counter = 0;

@Initialize{

	SetDamageRate(100,100);
	system_SetEnemyTexture("KANAME");
	system_SetEnemyType(1);
	once_system_LoadResource();
	system_SetEnemyLife(10);
	system_SetEnemyWeight(10);
	system_SetEnemyRadius(14);
	once_MainRoutine();
}

@MainLoop{
	SetCollisionA(GetX(), GetY(), 12);
	animation_counter++;
	if(initialize_counter < 10){ initialize_counter++; }
	//if( system_IsInvisible() ){ DeleteEnemyShotImmediatelyInCircle(CHILD, GetX(), GetY(), 300);}
	yield;
}

@DrawLoop{
	if(system_IsInvisible()){return;}
	SetTexture(img_Enemy);
	let scale_x = 0.7 * (initialize_counter/10);
	let scale_y = 0.7 + (1-initialize_counter/10);
	SetGraphicScale(scale_x, scale_y);
	system_SetGraphicRect(["ROCK_MAIN01","ROCK_MAIN02","ROCK_MAIN03","ROCK_MAIN04"][trunc(animation_counter/4)%4]);
	DrawGraphic(GetX(), GetY());
}

@Finalize{

}


task once_MainRoutine(){
	once_system_TaskSphereParameterChecker();
	once_system_TaskSphereHitTest();
	once_system_EnemyMain();
	once_MoveRoutine();
}

task once_MoveRoutine(){

	let random_seq = [0,13,6,10,1,3,12,8,5,2,11,9,14,4,7];
	loop(100){yield;}

	let base = rand(00,180);
	ascent(i in 0..15){
		create_shot(rand(1,2.5), base + random_seq[i] * (360/15));
		loop(3){ yield; }
	}

	loop(240){yield;}

	system_SetEnemyWeight(0);
	system_SetEnemyLife(0);
}


task create_shot(let speed, let angle){

	let obj = REMY_CreateMoveLaserObject(GetX(), GetY(), 32,  14, angle, speed, angle+180 ,_SHOT_RED, 10);
	while(!Obj_BeDeleted(obj)){
		if(system_IsInvisible() ){break;}
//		if( REMY_IsOutOfClip(Obj_GetX(obj), Obj_GetY(obj), -16)){ break; }
		yield;
	}
//	if(Obj_BeDeleted(obj)){ return; }

	system_burst01(Obj_GetX(obj),Obj_GetY(obj), 0.3);
/*	let angle_stone = 0;
	if(Obj_GetX(obj)<GetClipMinX()){angle_stone = 0;}
	if(Obj_GetX(obj)>GetClipMaxX()){angle_stone = 180;}
	if(Obj_GetY(obj)<GetClipMinY()){angle_stone = 90;}
	if(Obj_GetY(obj)>GetClipMaxX()){angle_stone = 270;}

	loop(20){yield;}
	//CreateEnemyFromFile(system_GetEnemyPath("TYPE_TA"), Obj_GetX(obj), Obj_GetY(obj), rand(0.5,1), angle_stone, [0]);
*/
	Obj_Delete(obj);

}

}//end script


//---------------------------------------


script_enemy TA{

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

let animation_counter = 0;

@Initialize{

	SetDamageRate(100,100);
	system_SetEnemyTexture("ROCK");
	system_SetEnemyType(1);
	once_system_LoadResource();
	system_SetEnemyLife(10);
	system_SetEnemyWeight(1);
	system_SetEnemyRadius(8);
	once_MainRoutine();
}

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

@DrawLoop{
	if(system_IsInvisible()){return;}
	SetTexture(img_Enemy);
	SetGraphicScale(0.4, 0.4);
	system_SetGraphicRect(["ROCK_MAIN01","ROCK_MAIN02","ROCK_MAIN03","ROCK_MAIN04"][trunc(animation_counter/4)%4]);
	DrawGraphic(GetX(), GetY());
}

@Finalize{

}


task once_MainRoutine(){
	once_system_TaskSphereParameterChecker();
	once_system_TaskSphereHitTest();
	once_system_EnemyMain();
	once_MoveRoutine();
}

task once_MoveRoutine(){
	system_MoveTypeSelect();
	system_StartMove();

}


}

//---------------------------------------


script_enemy TB{

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

let animation_counter = 0;

@Initialize{

	SetDamageRate(100,100);
	system_SetEnemyTexture("ROCK_B");
	system_SetEnemyType(3);
	once_system_LoadResource();
	system_SetEnemyLife(10000);
	system_SetEnemyWeight(1);
	system_SetEnemyRadius(8);
	once_MainRoutine();
}

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

@DrawLoop{
	if(system_IsInvisible()){return;}
	SetTexture(img_Enemy);
	SetGraphicScale(0.4, 0.4);
	system_SetGraphicRect(["ROCK_MAIN01","ROCK_MAIN02","ROCK_MAIN03","ROCK_MAIN04"][trunc(animation_counter/4)%4]);
	DrawGraphic(GetX(), GetY());
}

@Finalize{

}


task once_MainRoutine(){
	once_system_TaskSphereParameterChecker();
	once_system_TaskSphereHitTest();
	once_system_EnemyMain();
	once_MoveRoutine();
}

task once_MoveRoutine(){
	system_MoveTypeSelect();
	system_StartMove();

}


}

