#Title[妖通常５]
#Text[]
#Image[]
#BackGround[]
#PlayLevel[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let count = 0;
	#include_function ".\弾幕集.txt"

	@Initialize{
	SetX(GetCenterX);
	SetY(GetClipMinY + 120);
	SetLife(5000);
	SetTimer(99);
	SetDamageRate(100,50);

	LoadGraphic(imgboss73);
	LoadGraphic(imgknight);
	SetTexture(imgboss73);
	SetGraphicRect(0,0,127,127);
	Shot(2);
	SetText("禁生「人間創術　-剣士 Lv.66-」");
	}

	@MainLoop{
	count++;
	if(count == 120){CreateEnemyFromScript("KNIGHT",104,GetClipMinY + 32,0,0,1);}
	if(count == 240){SetText("");}
	ChackBonus;
	SetCollisionA(GetX,GetY,24);
	SetCollisionB(GetX,GetY,24);
	yield;
	}

	@DrawLoop{
	DrawGraphic(GetX,GetY);
	}

	@Finalize{
	MasicPointAddNormal(10);
	DeleteGraphic(imgboss73);
	DeleteGraphic(imgknight);
	}

	task Move(){
	loop{
	yield;
	}
	}

	task Shot(level){
	function Wait(time){loop(time){yield;}}

	Wait(260);
	loop{
	AroundToShot(GetX + rand(-160,160),GetY + rand(-70,70),rand(48,96),12 + level * 8,20,1.2,rand(0,360),0,false,false,RED01,20);
	Wait(50 - level * 5);
	}
	}
}

script_enemy KNIGHT
{
#include_function ".\弾幕集.txt"


	//初期位置
	let xini    =GetX;
	let yini    =GetCenterY - 120;

	@Initialize{
	SetLife(50000);
	SetScore(10000);
	SetDamageRateEx(100,0,10,0);

	SetTexture(imgknight);
	SetGraphicRect(0,0,127,127);
	Shot(GetArgument);
	Move();
	SetMovePosition02(xini,yini,60);
	}

	@MainLoop{
	SetCollisionA(GetX,GetY,16);
	SetCollisionB(GetX,GetY,8);
	yield;
	}

	@DrawLoop{
	DrawGraphic(GetX,GetY);
	}

	@Finalize{
	}



	task Shot(level){

	function SwordShotA(level){
	let speed = 1;
	let angle = GetAngleToPlayer - level * 20;
	loop(1 + level * 2){
	loop(25 + level * 10){
	CreateShot02(GetX,GetY,0.2,angle,0.04,speed,BLUE21,20);
	speed += 0.04;
	angle += 0.73;
	}
	speed = 1;
	angle -= 0.73 * (25 + level * 10);
	angle += 20;
	}
	}


	function SwordShotB(level){
	let speed = 1;
	let angle = GetAngleToPlayer - level * 20;
	loop(1 + level * 2){
	loop(25 + level * 10){
	CreateShot02(GetX,GetY,0.2,angle,0.04,speed,AQUA21,20);
	speed += 0.04;
	angle -= 0.73;
	}
	speed = 1;
	angle += 0.73 * (25 + level * 10);
	angle += 20;
	}
	}

	let wait = 200;
	loop{
	loop(wait){yield;}
	SwordShotA(level);
	loop(wait){yield;}
	SwordShotB(level);
	loop(wait){yield;}
	SwordShotB(level);
	loop(wait){yield;}
	SwordShotA(level);
	wait -= 10;
	if(wait < 100){wait = 100;}
	}
	}

	task Move{
let mx =GetClipMinX();
let Mx =GetClipMaxX();
let cx =GetCenterX();
let my =GetClipMinY();
let My =GetClipMaxY();
let cy =GetCenterY();

	loop(60){yield;}
	loop{
	loop(200){yield;}
	if(GetX >= mx + 64&&GetX <= Mx - 64&&GetY >= my + 96){
	SetMovePosition03(rand(GetX-32,GetX+32),rand(GetY-64,GetPlayerY),4,2);
	}
	if(GetX >= Mx + 64){SetMovePosition03(rand(GetX-32,0),GetY,4,2);}
	if(GetX <= mx + 64){SetMovePosition03(rand(0,GetX+32),GetY,4,2);}
	if(GetY <= my + 96){SetMovePosition03(GetX,GetPlayerY,4,2);
}
	}
	}
}