let imgzako = GetCurrentScriptDirectory~"\Img\dot-kaze-ti.png";

#include_function ".\Enemy function.txt"

let scorebonus = GetCommonData("SCOREBONUS");
let spellbonus = GetCommonData("SPELLBONUS");

//ボム耐性のCreateShot01。引数はCreateShot01と全く同じ。
//一応オブジェクト弾です。ループしないのでfunctionと同様な感じで呼べます
task DefenceBombShot01(x,y,speed,angle,bullet,delay){
let obj = Obj_Create(OBJ_SHOT);
Obj_SetX(obj, x);
Obj_SetY(obj, y);
Obj_SetSpeed(obj, speed);
Obj_SetAngle(obj, angle);
ObjShot_SetGraphic(obj, bullet);
ObjShot_SetDelay(obj, delay);
ObjShot_SetBombResist(obj,true);
			
while( !Obj_BeDeleted(obj) ){yield;}
}

//紅３面雑魚のクナイ弾の挙動のような関数。(暫定)
	//x		発射Ｘ座標
	//y		発射Ｙ座標
	//minspeed	最低速度	
	//maxspeed	最大速度
	//shots		発射数
	//bullet	弾画像

	task LineToPlayerShot(x,y,minspeed,maxspeed,shots,bullet){
	let angle = GetAngleToPlayer;
	let speedA = minspeed + (maxspeed - minspeed) / shots;
	let speed = minspeed;
	loop(shots){
	CreateShot02(x,y,speed,angle,0.3,speedA,bullet,15);
	speedA += (maxspeed - minspeed) / shots;
	yield;
	}
	}

	//地ＥＸの妖精・風５面全方位自機のような弾幕に使える関数
	//応用すればアンカーゴーストや風３面花のような弾にも使えそう
	//地ＥＸのような感じにしたい時はstoptimeを０にして、changeangle
	//をfalseにしてください
	//functionですがobj弾を内部で使っていますのでyield;必須
	//引数は１１。以下詳細
	//cx		中心Ｘ座標
	//cy		中心Ｙ座標
	//radius	中心からの初期距離
	//way		Ｗａｙ数
	//stoptime	停止時間
	//speed		速度
	//angle		初期角度
	//afterangle	変化後の角度
	//changeangle	角度変化の有無をtrue、falseで指定
	//afterchange	変化後角度も変化させるかtrue,falseで指定
	//（changeangleがfalseの場合、afterangle、afterchangeは無視されます。）
	//bullet	弾画像
	//delay		遅延時間

	task StopToMoveShot(x,y,time,speed,angleA,angleB,bullet,delay){
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetX(obj, x);
	Obj_SetY(obj, y);
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, angleA);
	ObjShot_SetGraphic(obj, bullet);
	ObjShot_SetDelay(obj, delay);

	loop(time){yield;}
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angleB);
	while( !Obj_BeDeleted(obj) ){yield;}
	}

	function AroundToShot(cx,cy,radius,way,stoptime,speed,angle,afterangle,changeangle,afterchange,bullet,delay){
	let Angle = angle;
	let addAngle = 360 / way;
	let x = cx + radius * cos(Angle);
	let y = cy + radius * sin(Angle);
	let AfterAngle = afterangle;
	let angleA;

	loop(way){
	if(changeangle == false){angleA = Angle;}
	else if(changeangle == true){angleA = AfterAngle;}

	StopToMoveShot(x,y,stoptime,speed,Angle,angleA,bullet,delay);
	Angle += addAngle;
	if(afterchange == true&&changeangle == true){AfterAngle += addAngle;}
	x = cx + radius * cos(Angle);
	y = cy + radius * sin(Angle);
	}
	}

	//星３面のくの字になって飛んでいく弾の関数のつもり。違うか…
	//x		発射Ｘ座標
	//y		発射Ｙ座標
	//speed		初速度（0.1位が見栄えが良いかと）
	//maxspeed	最高速度
	//angle		発射角度
	//bullet	弾画像
	//delay		遅延時間

	function KunojiShot(x,y,speed,maxspeed,angle,bullet,delay){
	CreateShot02(x,y,speed,angle+3,0.0285,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle+6,0.087,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle+9,0.1455,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle+12,0.194,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle,0.23,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle-3,0.0285,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle-6,0.087,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle-9,0.1455,maxspeed,bullet,delay);
	CreateShot02(x,y,speed,angle-12,0.194,maxspeed,bullet,delay);
	}

	//一定時間で停止し、ｎWay弾に分裂する弾を放つ関数（雑魚用？引数…１６）
	//x		発射Ｘ座標
	//y		発射Ｙ座標
	//speed		発射初期速度
	//angle		発射角度
	//bullet	分裂前弾弾画像
	//delay		遅延時間
	//movetime	移動時間
	//（movetimeは減速の時間も含むためstoptotime以下には出来ません）
	//stoptotime	減速時間
	//stoptime	停止時間
	//spway		分裂弾Ｗａｙ数
	//spspeed	分裂弾初期速度
	//spfast	分裂弾加速度
	//spmaxspeed	分裂弾最高速度
	//spangle	分裂弾中心角度
	//spspan	分裂弾間隔角度（spwayが１の時は意味無し）
	//spbullet	分裂弾弾画像

	task SplitShot(x,y,speed,angle,bullet,delay,movetime,stoptotime,stoptime,spway,spspeed,spfast,spmaxspeed,spangle,spspan,spbullet){

	let obj		= Obj_Create(OBJ_SHOT);
	let fullspeed	= movetime - stoptotime;
	let Speed	= speed;
	let decspeed	= speed / stoptotime;
	let Angle	= spangle - spspan * (spway - 1) / 2;

	Obj_SetX(obj, x);
	Obj_SetY(obj, y);
	Obj_SetSpeed(obj, Speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, bullet);
	ObjShot_SetDelay(obj, delay);

	loop(fullspeed){yield;}
	loop(stoptotime){
	Speed-= decspeed;
	Obj_SetSpeed(obj, Speed);
	yield;}
	loop(stoptime){yield;}
	loop(spway){
	CreateShot02(Obj_GetX(obj),Obj_GetY(obj),spspeed,Angle,spfast,spmaxspeed,spbullet,0);
	Angle+= spspan;
	}
	yield;
	Obj_Delete(obj);
	}

//一定距離で破裂する弾を放つ。全方位になります。
//wait　　　攻撃間隔
//angle　 　角度
//atk 　　　破裂後の弾の数

function BreakShotA(angle,atk){
let i= 90;
CreateShotA(1,GetX(),GetY(),30);
SetShotDataA(1,0,1.5,i,0,0,0,RED03);
let j = 0;
let addangle = 360 / atk;
	while(j<= atk){
	CreateShotA(2,0,0,10);
	SetShotDataA(2,0,0.1,angle,0,0.02,3,RED04);
	j++;
	angle += addangle;
	AddShot(45,1,2,0);}
SetShotKillTime(1,46);
FireShot(1);
}


//ここは素材ですので、上記の弾幕以外での使用禁止

function Allshot(speed,dir,way,bullet,delay){

ascent(let i in 0..way){
CreateShot01(GetX,GetY,speed,dir+(360/way*i),bullet,delay);
}
}

function ReflectShot(x,y,speed,angle,reflectNum,reflectL,reflectU,reflectR,reflectD,graphic,delay){
	
let minX = GetClipMinX();
let maxX = GetClipMaxX();
let minY = GetClipMinY();
let maxY = GetClipMaxY();
let totalFrame = 0;
CreateShotA( 0, x, y, delay );
SetShotDataA( 0, 0, speed, angle, 0, 0, 0, graphic );
while( reflectNum >= 1 ){
	while( angle < 0 ){ angle += 360; }
	if( angle >= 360 ){ angle %= 360; }
	let angleLU = atan2( y - minY, x - minX ) + 180;
	let angleRU = atan2( y - minY, x - maxX ) + 180;
	let angleLD = atan2( y - maxY, x - minX ) + 180;
	let angleRD = atan2( y - maxY, x - maxX ) + 180;
	if( angleRU == 0 ){ angleRU = 360; }
	if( angleRD == 360 ){ angleRD = 0; }
	let reflectLength = 0;
	let reflectX = 0;
	let reflectY = 0;
	let reflectAngle = 0;
	let reflect = false;
	if( angle >= angleRU || angle < angleRD ){
		reflectLength = ( maxX - x ) / cos( angle );
		reflectX = maxX;
		reflectY = y + reflectLength * sin( angle );
		reflectAngle = 180 - angle;
		reflect = reflectR;}
	else if( angle >= angleLD && angle < angleLU ){
	reflectLength = ( minX - x ) / cos( angle );
	reflectX = minX;
	reflectY = y + reflectLength * sin( angle );
	reflectAngle = 180 - angle;
	reflect = reflectL;}
	else if( angle >= angleLU && angle < angleRU ){
	reflectLength = ( minY - y ) / sin( angle );
	reflectX = x + reflectLength * cos( angle );
	reflectY = minY;
	reflectAngle = - angle;
	reflect = reflectU;}
	else{reflectLength = ( maxY - y ) / sin( angle );
	reflectX = x + reflectLength * cos( angle );
	reflectY = maxY;
	reflectAngle = - angle;
	reflect = reflectD;}
	if( !reflect ){ break; }
	x = reflectX;
	y = reflectY;
	angle = reflectAngle;
	totalFrame += reflectLength / speed;
	SetShotDataA( 0, totalFrame, NULL, angle, 0, 0, 0, graphic );
	reflectNum --;}
	FireShot( 0 );}

function WideShot01(x,y,speed,angle,wideAngle,way,graphic,delay){
let wayAngle = 0;
if( way > 1 ){
	wayAngle = wideAngle / ( way - 1 );
	angle -= wideAngle / 2;}
loop( way ){CreateShot01( x, y, speed, angle, graphic, delay );
	angle += wayAngle;}
}

function RoundWideShot01(x,y,speed,angle,wideAngle,wideWay,roundWay,graphic,delay)
{let roundWayAngle = 360 / roundWay;
let wideWayAngle = 0;
if( wideWay > 1 ){ wideWayAngle = wideAngle / ( wideWay - 1 ); }
loop( roundWay ){
	let _angle = angle;
	if( wideWay > 1 ){ _angle -= wideAngle / 2; }
	loop( wideWay ){
		CreateShot01( x, y, speed, _angle, graphic, delay );
		_angle += wideWayAngle;}
	angle += roundWayAngle;}
}

function GravityShot(x,y,speed,angle,grvSpeed,grvAngle,graphic,delay){
let xSpeed = speed * cos( angle );
let ySpeed = speed * sin( angle );
let accXSpeed = grvSpeed * cos( grvAngle );
let accYSpeed = grvSpeed * sin( grvAngle );
let maxXSpeed = [ 99, - 99 ][ accXSpeed < 0 ];
let maxYSpeed = [ 99, - 99 ][ accYSpeed < 0 ];
CreateShot12( x, y, xSpeed, ySpeed, accXSpeed, accYSpeed, maxXSpeed, maxYSpeed, graphic, delay );}

function GetGapAngle(xA,yA,xB,yB){
return atan2( yB - yA, xB - xA );
}

//おたまじゃくし弾を撃つ関数（弾種類固定、ディレイなし）
  //X, Y, しっぽの数, 基準速度（あたまの速度）, 速度変化量, 角度, しっぽのゆらぎ
  function CreateShotSK2otama(_X, _Y, _TailNum, _BaseSpeed, _ChangeSpeed, _BaseDir, _ShakeDir)
  {
    CreateShot01(_X, _Y, _BaseSpeed, _BaseDir, AQUA02, 0);
    
    let _count = 1; //カウンタ
    
    loop(_TailNum)
    {
      let _speed = _BaseSpeed + _ChangeSpeed*_count;
      let _dir = _BaseDir + rand(-_ShakeDir, _ShakeDir);
      
      CreateShot01(_X, _Y, _speed, _dir, GREEN12, 0);
      
      _count ++;
    }
  }