function CreateEnemy(x, y, frame){
	let enemy = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemy);
	
	ObjMove_SetPosition(enemy, bx, by);
	ObjMove_SetDestAtFrameWeight(enemy, x, y, frame);
	
	renderGhost(enemy, 1, 60*1/3, false); getshot(enemy);
	return enemy;
}

task getshot(me){
	while(!Obj_IsDeleted(me)){
		ObjEnemy_SetIntersectionCircleToShot(me, ObjMove_GetX(me), ObjMove_GetY(me), 10); 
		yield;
	}
}

//----------------------------------------------------------------------------------------------------
function accelLaser(x, y, ang, descentspeed){
	let L = CreateStraightLaserA1(x, y, ang, 400, 20, 60*999, 802, 3);
	ObjShot_SetAutoDelete(L, false); ObjStLaser_SetSource(L, false);
	ObjShot_SetIntersectionEnable(L, true);
	
	descend(L, descentspeed);
	return L;
}

//200 to 600
task descend(L, descentspeed){
	let len = 400;
	let t = 0;
	while(gety(L) < stgh+70){
		sety(L, gety(L) + descentspeed);
		ObjLaser_SetLength(L, len + sin(t)*250);
		
		t += 2.6;
		yield;
	}
	
	Obj_Delete(L);
}

//----------------------------------------------------------------------------------------------------
function CreateSTLaser(x, y, angle, len, width, graph, del){
	let st = CreateStraightLaserA1(x, y, angle, len, 0, 60*999, graph, 0);
	DLaser(st, width/3, 2); 
	size(st, width, del[0], 5, true);
	size(st, width*2, del[1], 9, false);
	
	return st;
}

function CreateDLaser(x, y, angle, len, width, graph, del){
	let st = CreateStraightLaserA1(x, y, angle, len, 0, 60*999, graph, 0);
	DLaser(st, width, 2); 
	size(st, width*1.5, del, 3, false);
	
	return st;
}

task DLaser(st, wid, n){
	ObjShot_SetIntersectionEnable(st, false); //ObjStLaser_SetSource(st, false);
	ascent(i in 0..wid/n){
		ObjLaser_SetIntersectionWidth(st, i*n);
		ObjLaser_SetRenderWidth(st, i*n - 3);
		yield;
	}
}

task size(st, wid, del, n, grow){
	if(grow){
		wait(del); if(Obj_IsDeleted(st)){return;}
		ObjShot_SetIntersectionEnable(st, true);
		
		ascent(i in 0..wid/n){
			ObjLaser_SetIntersectionWidth(st, i*n);
			ObjLaser_SetRenderWidth(st, i*n - 3);
			yield;
		}
	}
	else{
		wait(del); if(Obj_IsDeleted(st)){return;}
		ObjShot_SetIntersectionEnable(st, false);
		
		descent(i in 0..wid/n){
			ObjLaser_SetIntersectionWidth(st, i*n);
			ObjLaser_SetRenderWidth(st, i*n - 3);
			yield;
		}
		
		Obj_Delete(st);
	}

}

//----------------------------------------------------------------------------------------------------
let tshot = SoundSFX(GetCurrentScriptDirectory ~ "./../SFX/Shot02.wav");
task reflectN(obj, time){
	ObjShot_SetSpellResist(obj, true);
	while(time > 0){
		if(getx(obj) < 0 || getx(obj) > stgw){seta(obj, 180 - geta(obj)); time--; circ();}
		if(gety(obj) < 0 || gety(obj) > stgh){seta(obj, geta(obj) * -1); time--; circ();}
		
		if(getx(obj) < 0){setx(obj, 0);} else if(getx(obj) > stgw){setx(obj, stgw);}		
		if(gety(obj) < 0){sety(obj, 0);} else if(gety(obj) > stgh){sety(obj, stgh);}		
		yield;
	}
	
	task circ{
		let r = rand(0,360); PlaySFX_V(tshot, 50);
		setsp(obj, 0); ObjShot_SetGraphic(obj, 422);
		ObjMove_SetAcceleration(obj, 1/40);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		
		ascent(i in 0..8){ExplodeCircle(getrx(obj), getry(obj), 10+i*5, 189, 15, 15, BLEND_ADD_ARGB);}
		ascent(i in 0..22){
			let a = CreateShotA1(getx(obj), gety(obj), 2, r + 360/22*i, 202, 2);
			ObjMove_AddPatternA2(a, 6, NO_CHANGE, NO_CHANGE, -1/5, 0, 0.8);
			ObjRender_SetBlendType(a, BLEND_ADD_ARGB);
		}
	}
}

//----------------------------------------------------------------------------------------------------
function CreateWheelA2(x, y, speed, angle, accel, maxspeed, graphic, delay, turn){
	let mid = CreateShotA2(x, y, speed, angle, accel, maxspeed, graphic, delay); splel(mid, 8, 32, [123, 30], turn);
	return mid;
}

task splel(obj, num, cir, tx, v){
	let LS = []; let B = [];
	let an = geta(obj); let ax = geta(obj);
	
	ascent(i in 0..num){
		let a = an + 360/num*i;
		let x = getx(obj); let y = gety(obj);
		
		LS = LS ~ [CreateSTLaser(x, y, a, tx[0], tx[1], 121, [30, 60*999])];
		ObjShot_SetAutoDelete(LS[i], false);
	}
	ascent(i in 0..cir){
		let a = ax + 360/cir*i;
		let x = getx(obj); let y = gety(obj);
		
		B = B ~ [CreateShotA1(x + tx[0]*cos(a), y + tx[0]*sin(a), 0, a, 541, 2)];
		ObjShot_SetSpellResist(B[i], true); ObjShot_SetAutoDelete(B[i], false);
	}
	
	while(!Obj_IsDeleted(obj)){
		ascent(i in 0..num){
			let a = an + 360/num*i;
			let x = getx(obj); let y = gety(obj) + 5;
			
			ObjStLaser_SetAngle(LS[i], a);
			setpos(LS[i], x, y);
		}
		
		ascent(i in 0..cir){
			let a = ax + 360/cir*i;
			let x = getx(obj); let y = gety(obj) + 5;

			setpos(B[i], x + tx[0]*cos(a), y + tx[0]*sin(a));
			seta(B[i], a);
		}
		
		an += v; ax -= v;
		yield;
	}
	
	ascent(i in 0..num){size(LS[i], tx[1]*2, 30, 9, false);}
	ascent(i in 0..cir){ObjShot_SetFadeDeleteAtFrame(B[i], 30);}
}