let S_Damage = 1.0;
let O_type = 2;

task TShot{
	let playerPower;
	ShotPower4;
}

//針
task TNeedle(x, y, speed, angle, Damage){
	let obj = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetPosition(obj, x, y);
	ObjMove_SetSpeed(obj, speed);
	ObjMove_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 2);
	ObjShot_SetDamage(obj, Damage);
	ObjShot_SetPenetration(obj, 1);
	ObjShot_Regist(obj);

	while(!Obj_IsDeleted(obj)){
		x = ObjMove_GetX(obj);
		y = ObjMove_GetY(obj);
		yield;
	}
	if(!IsOut(x, y, 64)){
		NeedleEffect(x, y);
	}
}

//爆風

task NeedleEffect(x, y){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, Texture);
	Obj_SetRenderPriority(obj, 0.45);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjSprite2D_SetSourceRect(obj, 16, 0, 32, 48);
	ObjSprite2D_SetDestRect(obj, -8, -24, 8, 24);
	let time = 6;
	descent(i in 1 .. time+1){
		let alpha = 63 * i/time;
		ObjRender_SetColor(obj, alpha, alpha, alpha);
		ObjRender_SetScaleX(obj, 1.0*i/time);
		ObjRender_SetPosition(obj, x, y-(time-i)*5, 0);
		yield;
	}
	Obj_Delete(obj);
}

task OptionA(obj, x, y, x2, y2){
	let s_a = 0;
	let angle = 0;
	let rx = (x-x2)/2;
	let ry = (y-y2)/2;
	let cx = (x+x2)/2;
	let cy = (y+y2)/2;

	let a = 0;
	while(!Obj_IsDeleted(obj)){
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD){
			a = min(a+1,5);
		}else{
			a = max(a-1,0);
		}
		s_a += 4;
		ObjRender_SetAngleZ(obj, angle);
		ObjRender_SetX(obj, GetPlayerX+cx+rx*cos(36*a));
		ObjRender_SetY(obj, GetPlayerY+cy+ry*cos(36*a));
		angle += 2;
		yield;
	}
}

//パワー400(Max)の時のショット
sub ShotPower4{
	loop(4){
 		objOpt = objOpt ~ [Option(O_type)];
	}
	OptionA(objOpt[0], 40*cos(240), 40*sin(240), 15*cos(240), 15*sin(240));
	OptionA(objOpt[1], 40*cos(300), 40*sin(300), 15*cos(300), 15*sin(300));
	OptionA(objOpt[2], 40*cos(180), 40*sin(180), 20*cos(210), 20*sin(210));
	OptionA(objOpt[3], 40*cos(360), 40*sin(360), 20*cos(330), 20*sin(330));
	let angle = 270;
	let a_r = 0;
	let dx = 0;
	let shotCount = -1;

	loop{
		if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD)
		 && GetPlayerState() == STATE_NORMAL && IsPermitPlayerShot){
			shotCount++;
		}else{
			shotCount = -1;
		}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD){
			a_r = 0;
			dx = 4;
		}else{
			a_r = 1.5;
			dx = 0;
		}
		if(shotCount%3 == 1){
			_PlaySE(SE_PSHOT);
			CreatePlayerShotA1(GetPlayerX()+8, GetPlayerY(), 20, 270, 3, 1, 1);
			CreatePlayerShotA1(GetPlayerX()-8, GetPlayerY(), 20, 270, 3, 1, 1);
			TNeedle(ObjRender_GetX(objOpt[0])-dx, ObjRender_GetY(objOpt[0]), 20, angle - a_r, S_Damage);
			TNeedle(ObjRender_GetX(objOpt[0])+dx, ObjRender_GetY(objOpt[0]), 20, angle + a_r, S_Damage);
			TNeedle(ObjRender_GetX(objOpt[1])-dx, ObjRender_GetY(objOpt[1]), 20, angle - a_r, S_Damage);
			TNeedle(ObjRender_GetX(objOpt[1])+dx, ObjRender_GetY(objOpt[1]), 20, angle + a_r, S_Damage);
			TNeedle(ObjRender_GetX(objOpt[2])-dx, ObjRender_GetY(objOpt[2]), 20, angle - a_r, S_Damage);
			TNeedle(ObjRender_GetX(objOpt[2])+dx, ObjRender_GetY(objOpt[2]), 20, angle + a_r, S_Damage);
			TNeedle(ObjRender_GetX(objOpt[3])-dx, ObjRender_GetY(objOpt[3]), 20, angle - a_r, S_Damage);
			TNeedle(ObjRender_GetX(objOpt[3])+dx, ObjRender_GetY(objOpt[3]), 20, angle + a_r, S_Damage);
		}
		yield;
	}
	descent(i in 0 .. 4){
		Obj_Delete(objOpt[i]);
	}
	objOpt = [];
}
