let is_ex = 0;
let is_hit = 1;

//{[hɂ
function SetExMode(){ is_ex = 1; }

//{[hǂ擾
function IsExMode(){ return is_ex; }

//蔻̗LEݒ
function SetHitState(s){ is_hit = s; }

//~`ɓ_ACeo
function CreateItemCircle(cx, cy, num, r)
{
	if( num > r / 6 + 3 ){
		let cn = trunc(r / 6 + 3);
		let angle = rand(0, 360);
		loop(cn){
			CreateItem(ITEM_SCORE, cx + r * cos(angle), cy + r * sin(angle));
			angle += 360 / cn;
		}
		num -= cn;
	}
	loop(num){
		let pr = rand(0, r ^ 2) ^ 0.5;
		let angle = rand(0, 360);
		CreateItem(ITEM_SCORE, cx + pr * cos(angle), cy + pr * sin(angle));
	}
}

//_~[G𐶐֐
function CreateSubEnemy(x, y, type)
{
	ascent( let i in 0..100 ){
		let label = ToString(i);
		if( GetCommonDataDefault("sub_state" ~ label, -1) == -1 ){
			SetCommonData("sub_state" ~ label, 1);
			SetCommonData("sub_x" ~ label, x);
			SetCommonData("sub_y" ~ label, y);
			SetCommonData("sub_type" ~ label, type);
			return i;
		}
	}
	return -1;
}

//_~[GɏIbZ[Wʒm֐
function ExitSubEnemy(id)
{
	let label = ToString(id);
	if( GetCommonDataDefault("sub_state" ~ label, -1) != -1 ){
		SetCommonData("sub_state" ~ label, 3);
	}
}

//_~[G̃f[^֐
function DeleteSubEnemy(id)
{
	let label = ToString(id);
	if( GetCommonDataDefault("sub_state" ~ label, -1) != -1 ){
		DeleteCommonData("sub_state" ~ label);
		DeleteCommonData("sub_x" ~ label);
		DeleteCommonData("sub_y" ~ label);
		DeleteCommonData("sub_type" ~ label);
	}
}

//GwʒuɁAw莞ԂŌړ^XN
task SetMovePositionDC(tx, ty, count)
{
	if( count <= 0 ){
		return;
	}
	let x = GetX();
	let y = GetY();
	let vx = (tx - x) * 2 / count;
	let vy = (ty - y) * 2 / count;
	let v = hypot(vy, vx);
	let a = -v / count;
	let angle = atan2(vy, vx);
	v += a / 2;
	loop(count){
		SetSpeed(v);
		SetAngle(angle);
		v += a;
		yield;
	}
	SetSpeed(0);
}

//_[WCg𒲐^XN
task T_DamageRate(dr_shot, dr_bomb, count1, count2)
{
	if( is_ex ){
		dr_bomb = 0;
	}

	SetDamageRate(dr_shot / 5, dr_bomb / 5);

	loop( count1 ){
		yield;
	}
	SetDamageRate(dr_shot, dr_bomb);

	if( count2 > count1 ){
		loop( count2 - count1 ){
			yield;
		}
		SetDamageRate(dr_shot * 5, dr_bomb);
	}
}

//蔻o^^XN
task T_HitTest(hit_r)
{
	yield;

	loop{
		if( is_hit && (! (is_ex && OnBomb())) ){
			SetCollisionA(GetX(), GetY(), hit_r);
			SetCollisionB(GetX(), GetY(), hit_r * 0.5);
		}
		yield;
	}
}

@MainLoop{ yield; }
