//よく使うかもしれない関数

/////////////////////////////////////////////////////////////////////
//moveToPlayer(xの移動量, ｙの移動量, 移動時間, 左端, 上端, 右端, 下端);
//
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
//ReflectShot(発射点x,発射点y,速度,反射後速度,角度,属性,反射角度,反射回数,左端反射,上端反射,右端反射,下端反射,弾,反射後弾,遅延,端到達時遅延);
//
//第4引数~第7引数は true もしくは false
//属性は "default" で普通な反射角、"player" で自機狙い、"user" で反射角度で指定した角度
//使い辛い・・・
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
//wayShot(x座標,y座標,速度,発射角,角度間隔,way数,敵座標からの距離,弾画像,遅延);
//
//敵座標から離れた位置からway弾を発射
//角度間隔、way数は必ず0より大きい数にすること。
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
//wayShot2(x座標,y座標,速度,発射角,発射角2,角度間隔,way数,敵座標からの距離,弾画像,遅延);
//
//wayShotのもうちょっと便利なやつ。
//
/////////////////////////////////////////////////////////////////////


//移動制御　!弾幕風講座の丸写しです!

function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
		let x;
		let y;
	if(GetPlayerX < GetX) {
		x = GetX - xMove;
		if(x < left) {
			x = GetX + xMove;
			}
		}
	else {
		x = GetX + xMove;
		if(right < x) {
		x = GetX - xMove;
		}
	}
	y = GetY + yAdd;
	if(y < top) {
		y = top;
	}
	else if(bottom < y) {
		y = bottom;
	}
	SetMovePosition02(x, y, frame);
}

//待て

function wait(w) {
	loop(w) { yield; }
}

//反射弾　!END氏の汎用関数集の反射弾を改変して使用しています!

function ReflectShot(
	let x,	
	let y,
	let speed,
	let rspeed,
	let angle,
	let type,
	let rangle,
	let reflect,
	let L,
	let U,
	let R,
	let D,
	let graphic,
	let rgraphic,
	let delay,
	let rdelay,
){
	let totalFrame = 0;
	let reflectEdge = [U,D,L,R];
	SetShotDirectionType(ABSOLUTE);
	CreateShotA(0, x, y, delay);
	SetShotDataA(0, 0, speed, angle, 0, 0, 0, graphic);
	while(reflect >= 1){
		while(angle<0){angle += 360;}
		if(angle>=360){angle %= 360;}
		let angleLU=atan2(y - GetClipMinY, x - GetClipMinX) + 180;
		let angleRU=atan2(y - GetClipMinY, x - GetClipMaxX) + 180;
		let angleLD=atan2(y - GetClipMaxY, x - GetClipMinX) + 180;
		let angleRD=atan2(y - GetClipMaxY, x - GetClipMaxX) + 180;
		if(angleRU==0){angleRU = 360;}
		if(angleRD==360){angleRD = 0;}
		let rLength = 0;
		let rFrame = 0;
		let rx = 0;
		let ry = 0;
		let rAngle = 0;
		let rEdge = 0;
		if(angle >= angleRU || angle < angleRD){
			rLength = (GetClipMaxX - x)/cos(angle);
			rFrame = rLength/speed;
			rx = GetClipMaxX;
			ry = y+rLength*sin(angle);
			if(type == "default"){rAngle = 180 - angle;}
			else if(type == "player"){rAngle = 0;}
			else if(type == "user"){rAngle = rangle;}
			rEdge=3;
		}
		else if(angle >= angleLD && angle < angleLU){
			rLength = (GetClipMinX - x)/cos(angle);
			rFrame = rLength/speed;
			rx = GetClipMinX;
			ry = y + rLength*sin(angle);
			if(type == "default"){rAngle = 180 - angle;}
			else if(type == "player"){rAngle = 0;}
			else if(type == "user"){rAngle = rangle;}
			rEdge = 2;
		}
		else if(angle >= angleLU && angle < angleRU){
			rLength = (GetClipMinY - y)/sin(angle);
			rFrame = rLength/speed;
			rx = x + rLength*cos(angle);
			ry = GetClipMinY;
			if(type == "default"){rAngle = -angle;}
			else if(type == "player"){rAngle = 0;}
			else if(type == "user"){rAngle = rangle;}
			rEdge = 0;
		}
		else{
			rLength = (GetClipMaxY - y)/sin(angle);
			rFrame = rLength/speed;
			rx = x + rLength*cos(angle);
			ry = GetClipMaxY;
			if(type == "default"){rAngle = -angle;}
			else if(type == "player"){rAngle = 0;}
			else if(type == "user"){rAngle = rangle;}
			rEdge = 1;
		}
		if(!reflectEdge[rEdge]){break;}
		x = rx;
		y = ry;
		angle = rAngle;
		totalFrame += rFrame;
		
		if(type == "player"){
			SetShotDirectionType(PLAYER);
			SetShotDataA(0, totalFrame ,rspeed, 0, 0, 0, 0, rgraphic);
		}

		else if(type == "default" || "user"){
			SetShotDirectionType(ABSOLUTE);
			SetShotDataA(0, totalFrame ,rspeed, angle, 0, 0, 0, rgraphic);
		}

			CreateShotA(1, 0, 0, rdelay);
			SetShotDataA(1, 0, 0, 0, 0, 0, 0, rgraphic);
			SetShotKillTime(1,0);

		AddShot(totalFrame, 0, 1, 0);

		reflect--;
	}
	FireShot(0);
}

//nway弾

function wayShot(
	let x,
	let y,
	let speed,
	let angle,
	let interval,
	let way,
	let distance,
	let graphic,
	let delay

){
	let ANGLE = - (way - 1)*interval/2 + angle;
	while(ANGLE<(way - 1)*interval/2 + angle + 0.1){

	CreateShot01(x + cos(ANGLE)*distance, y + sin(ANGLE)*distance, speed, ANGLE, graphic, delay);

	ANGLE += interval;
	}
}

//nway弾

function wayShot2(
	let x,
	let y,
	let speed,
	let angle,
	let angle2,
	let interval,
	let way,
	let distance,
	let graphic,
	let delay

){
	let ANGLE = - (way - 1)*interval/2 + angle;
	while(ANGLE<(way - 1)*interval/2 + angle + 0.1){

	CreateShot01(x + cos(ANGLE)*distance, y + sin(ANGLE)*distance, speed, ANGLE+angle2, graphic, delay);

	ANGLE += interval;
	}
}

function wayShot3(
	let x,
	let x_distance,
	let y,
	let y_distance,
	let speed,
	let angle,
	let angle2,
	let interval,
	let way,
	let graphic,
	let delay

){
	let ANGLE = - (way - 1)*interval/2 + angle;
	while(ANGLE<(way - 1)*interval/2 + angle + 0.1){

	CreateShot01(x + cos(ANGLE)*x_distance, y + sin(ANGLE)*y_distance, speed, ANGLE+angle2, graphic, delay);

	ANGLE += interval;
	}
}


//nwayレーザー

function wayShotL(
	let x,
	let y,
	let speed,
	let angle,
	let angle2,
	let interval,
	let way,
	let distance,
	let length,
	let thick,
	let graphic,
	let delay

){
	let ANGLE = - (way - 1)*interval/2 + angle;
	while(ANGLE<(way - 1)*interval/2 + angle + 0.1){

	CreateLaser01(x + cos(ANGLE)*distance, y + sin(ANGLE)*distance, speed, ANGLE+angle2, length, thick, graphic, delay);

	ANGLE += interval;
	}
}
