let B_Damage = 0.5;
let S_Damage = 2.0;
let O_type = 2;

task TShot{
	let playerPower;
	loop{
		playerPower = truncate(min(GetPlayerPower(),400)/100);
		alternative(playerPower)
		case(1){ShotPower1;}
		case(2){ShotPower2;}
		case(3){ShotPower3;}
		case(4){ShotPower4;}
		while(GetPlayerState != STATE_NORMAL){
			yield;
		}
	}
}

//風神録風のミサエル
task TSpreadBomb(x, y, speed, angle, Damage, B_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)){
		Burst(x, y, B_Damage);
	}
}

//爆風
task Burst(x, y, B_Damage){
	let obj = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetPosition(obj, x, y);	
	ObjShot_SetGraphic(obj, 3);
	ObjShot_SetDamage(obj, B_Damage);
	ObjShot_SetPenetration(obj, 9999);
	ObjShot_Regist(obj);
	
	BurstEffect(x, y);
	loop(9){
		yield;
	}
	Obj_Delete(obj);
}

task BurstEffect(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, 192, 0, 240, 48);
	ObjSprite2D_SetDestRect(obj, -24, -24, 24, 24);
	let time = 20;
	let alpha = 192;
	let alpha_r = alpha/(time-10);
	let scale = 2.0;
	ObjRender_SetColor(obj, alpha, alpha, alpha);
	ascent(i in 0 .. 10){
		ObjRender_SetScaleXYZ(obj, scale*sin(9*i), scale*sin(9*i), 1.0);
		alpha -= alpha_r;
		yield;
	}
	ObjRender_SetScaleXYZ(obj, scale, scale, 1.0);
	ascent(i in 10 .. time){
		ObjRender_SetColor(obj, alpha, alpha, alpha);
		alpha -= alpha_r;
		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;
		let scale = 1.1+0.1*cos(s_a);
		ObjRender_SetScaleX(obj, scale);
		ObjRender_SetScaleY(obj, scale);
		ObjRender_SetX(obj, GetPlayerX+cx+rx*cos(36*a));
		ObjRender_SetY(obj, GetPlayerY+cy+ry*cos(36*a));
		angle += 2;
		yield;
	}
}

//パワー100〜199の時のショット
sub ShotPower1{
	loop(1){
 		objOpt = objOpt ~ [Option(O_type)];
	}
	OptionA(objOpt[0], 40*cos(270), 40*sin(270), 20*cos(270), 20*sin(270));
	let angle = 270;
	let shotCount = -1;

	let playerPower = 1;
	while(playerPower == 1){
		if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD)
		 && GetPlayerState() == STATE_NORMAL && IsPermitPlayerShot){
			shotCount++;
		}else{
			shotCount = -1;
		}
		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);
		}
		if(shotCount%12 == 10){
			TSpreadBomb(ObjRender_GetX(objOpt[0]), ObjRender_GetY(objOpt[0]), 8, angle, S_Damage, B_Damage);
		}
		playerPower = truncate(GetPlayerPower/100);
		yield;
	}
	descent(i in 0 .. 1){
		Obj_Delete(objOpt[i]);
	}
	objOpt = [];
}

//パワー200〜299の時のショット
sub ShotPower2{
	loop(2){
 		objOpt = objOpt ~ [Option(O_type)];
	}
	OptionA(objOpt[0], 40*cos(225), 40*sin(225), 20*cos(225), 20*sin(225));
	OptionA(objOpt[1], 40*cos(315), 40*sin(315), 20*cos(315), 20*sin(315));
	let angle = 270;
	let a_r = 0;
	let shotCount = -1;

	let playerPower = 2;
	while(playerPower == 2){
		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 = 2;
		}else{
			a_r = 5;
		}
		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);
		}
		if(shotCount%12 == 10){
			TSpreadBomb(ObjRender_GetX(objOpt[0]), ObjRender_GetY(objOpt[0]), 8, angle - a_r, S_Damage, B_Damage);
			TSpreadBomb(ObjRender_GetX(objOpt[1]), ObjRender_GetY(objOpt[1]), 8, angle + a_r, S_Damage, B_Damage);
		}
		playerPower = truncate(GetPlayerPower/100);
		yield;
	}
	descent(i in 0 .. 2){
		Obj_Delete(objOpt[i]);
	}
	objOpt = [];
}

//パワー300〜399の時のショット
sub ShotPower3{
	loop(3){
 		objOpt = objOpt ~ [Option(O_type)];
	}
	OptionA(objOpt[0], 40*cos(270), 40*sin(270), 20*cos(270), 20*sin(270));
	OptionA(objOpt[1], 40*cos(210), 40*sin(210), 20*cos(210), 20*sin(210));
	OptionA(objOpt[2], 40*cos(330), 40*sin(330), 20*cos(330), 20*sin(330));
	let angle = 270;
	let a_r = 0;
	let shotCount = -1;

	let playerPower = 3;
	while(playerPower == 3){
		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 = 2;
		}else{
			a_r = 8;
		}
		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);
		}
		if(shotCount%12 == 4){
			TSpreadBomb(ObjRender_GetX(objOpt[0]), ObjRender_GetY(objOpt[0]), 8, angle, S_Damage, B_Damage);
		}
		if(shotCount%12 == 10){
			TSpreadBomb(ObjRender_GetX(objOpt[1]), ObjRender_GetY(objOpt[1]), 8, angle - a_r, S_Damage, B_Damage);
			TSpreadBomb(ObjRender_GetX(objOpt[2]), ObjRender_GetY(objOpt[0]), 8, angle + a_r, S_Damage, B_Damage);
		}
		playerPower = truncate(GetPlayerPower/100);
		yield;
	}
	descent(i in 0 .. 3){
		Obj_Delete(objOpt[i]);
	}
	objOpt = [];
}

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

	let playerPower = 4;
	while(playerPower == 4){
		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 = 1.5;
		}else{
			a_r = 5;
		}
		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);
		}
		if(shotCount%12 == 4){
			TSpreadBomb(ObjRender_GetX(objOpt[0]), ObjRender_GetY(objOpt[0]), 8, angle - a_r, S_Damage, B_Damage);
			TSpreadBomb(ObjRender_GetX(objOpt[1]), ObjRender_GetY(objOpt[1]), 8, angle + a_r, S_Damage, B_Damage);
		}
		if(shotCount%12 == 10){
			TSpreadBomb(ObjRender_GetX(objOpt[2]), ObjRender_GetY(objOpt[0]), 8, angle - 2*a_r, S_Damage, B_Damage);
			TSpreadBomb(ObjRender_GetX(objOpt[3]), ObjRender_GetY(objOpt[1]), 8, angle + 2*a_r, S_Damage, B_Damage);
		}
		playerPower = truncate(GetPlayerPower/100);
		yield;
	}
	descent(i in 0 .. 4){
		Obj_Delete(objOpt[i]);
	}
	objOpt = [];
}
