#東方弾幕風
#Title[水符「スプラッシュウォーターガン」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

let Norma=5;//撮影枚数の設定
let SpellTimer=9000;//制限時間の設定（フレーム単位）
let StepUp=[1,2,3,4,5];//段階移行する枚数を設定（五つまで設定可能）。StepUp1〜5（boolean）まであり、入力枚数撮るとtrueになる

#include_function ".\..\txt/DoubleSpoilerData.txt"

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot-kaze-ti2.png"; 

    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetCenterY-50;


    @Initialize {
	SetShotAutoDeleteClip(96,128,96,48);
	SetBulletScorePoint(12,100);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,342,464,368);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	SetX(GetCenterX-32);
//	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	DoubleSpoilerYield;
    }

let appearecount=0;

    @DrawLoop {
	if(appearecount<30)
	{
	appearecount+=1;
	}
	SetAlpha(255/30*appearecount);
	SetTexture(imgBoss);
	SetGraphicScale(1.1,1.1);
	SetGraphicRect(192,64,256,128);
	DrawBossAndShadow( imgBoss,0,239,255);
	DrawGraphic(GetX,GetY);
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	FinalizeDoubleSpoiler;
    }
	@BackGround
	{


	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowPosition(0);
	standBy;
	Shot;
	Shot2;
}


sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 30);
	let wIni = 40;
	SetMovePosition03(xIni, yIni, 8,5);
	SetInvincibility(wIni);
	wait(wIni);
}


let watetime=120;
let waterframe=25;

task Shot2
{
loop
{
	let angle=rand(0,360);
	ascent(let i in 0..12)
	{
		DoubleSpoilerCreateShot02(GetX,GetY,0.5,GetAngleToPlayer+360*i/12,0.025,5,229,10,"CYAN",100,3);
	}
wait(60);
}
}

task Shot
{
	loop
	{//
		if(StepUp2)
		{
			WaterGun(GetPlayerX,GetY,rand(4.0,5.0));
			wait(60);
		}
		if(StepUp4)
		{
			WaterGun(GetPlayerX,GetY,rand(4.0,5.0));
			wait(60);
		}
		WaterGun(GetPlayerX,GetY,rand(4.0,5.0));
		wait(120);
		DoubleSpoilermoveToPlayer(rand(40, 60), rand(-10, 10), 30,
                     GetClipMinX + 48, GetClipMinY +  64,
                     GetClipMaxX - 48, GetClipMinY + 160);
		MagicCircleEffectTask;
		wait(watetime-60);
	}
}

task WaterGun(let x,let y,let Speed)
{
Laser(x,y);
wait(waterframe);
let arg=rand(0,360);
loop(waterframe)
{
	ascent(let i in 0..4)
	{
		WaterGunBullet(x,GetClipMaxY+20,Speed,270,108,5,i*90+arg,245,0);
	}
yield;
}
}

task Laser(let x,let y)
{
	let dis=((GetClipMaxY-GetY)^2+(x-GetX)^2)^0.5;
	let speed=dis/waterframe;
	let angle=atan2(GetClipMaxY-GetY,x-GetX);
	let length=0;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,GetX,GetY);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,5);
	ObjShot_SetGraphic(obj, 157);
	ObjLaser_SetSource(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAngle(obj,angle);
	Obj_SetAlpha(obj,150);
	ObjShot_SetBombResist(obj,true);

	loop(waterframe)
	{
		length+=speed;
		ObjLaser_SetLength(obj,length);
		yield;
	}
	loop(waterframe)
	{
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle), Obj_GetY(obj)+speed*sin(angle));
		yield;
	}
	Obj_Delete(obj);
}

task WaterGunBullet(let x, let y, let speed, let angle,
            let amp, let om, let arg, let graphic, let delay)
{
	let t = 0;
	let px = speed*t;
	let py = amp*sin(om*t + arg);
	let a = amp*om*pi/(180*speed);
	let r=20;
	let dis=speed*90+r*cos(arg);
	speed=dis/90;
	let obj = Obj_Create(OBJ_SHOT);

	Obj_SetPosition(obj, x + px*cos(angle) - py*sin(angle),
                             y + px*sin(angle) + py*cos(angle)+r*cos(arg));
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, angle + atan(a*cos(om*t + arg)));
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
    
	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);

	loop(delay){ yield; }
	let Alpha=255;

	loop(90)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetAlpha(obj,180+75*cos(om*t + arg));
		amp-=1.2;
        	//(px,py)座標での弾の位置を計算
		px=speed*t;
		py=amp*sin(om*t + arg);
       		//回転・平行移動して実際の位置に
		Obj_SetPosition(obj,x+px*cos(angle)-py*sin(angle),y+px*sin(angle)+py*cos(angle)+r*cos(arg));
		//弾の方向にもangleを足す
		Obj_SetAngle(obj, angle + atan(a*cos(om*t + arg)));
       		t++;
		yield;
	}
	Obj_SetAlpha(obj,255);
	speed=rand(0.5,2.0);
	let aspeed=0;
	angle=rand(0,360);
	let angle2=90;
	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle)+aspeed*cos(angle2), Obj_GetY(obj)+speed*sin(angle)+aspeed*sin(angle2));
		aspeed+=0.010;
		wait(1);
	}
	//Obj_Delete(obj);
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		BulletColor("CYAN");
		EffectSet(X,Y,"CYAN");
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		EffectSet(X,Y,"CYAN");
	}
}

#include_function ".\..\txt/Data.txt"
#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
