#東方弾幕風
#Title[雪符「スノウフォール-Hard」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "雪符「スノウフォール-Hard」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_cirno.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st1bg2.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let imgeffect = csd ~ "\img\shot_all.png";

	let wIni=60;
	let DrawY=330;
	let count=-wIni;

	#include_function ".\..\txt\SpellCardBonusDefine.txt"
	let SpellTimer=50;

	let BGangle=0;
    @Initialize {
	SetShotAutoDeleteClip(128,128,128,64);
	StartSpellHistory(9);
        SetLife(900);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
	LoadGraphic(imgeffect);
	LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

    @MainLoop {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;

    }

    @DrawLoop {
	DrawBossShadow( imgBoss,150,0,0,255);
	SetGraphicAngle(0,0,0);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
        DeleteGraphic(imgBoss);
        DeleteGraphic(imgBG);
	EndSpellHistory(9);
	loop(10)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,0,896,636);
		SetGraphicAngle(0,0,BGangle);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
		BGangle+=0.2;
	}

    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	Mainshot;
	SubShot;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
        SetDamageRate(25, 25);
}




sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, wIni);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

sub spell//発動モーション
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(SpellTimer);
        SetScore(SpellBonus);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task Mainshot
{
loop
{
let angle=0;
		loop(24)
		{
		/*	CreateShotA(0,GetX,GetY,30);
			SetShotDataA(0,0,5,angle,0,0.0,0,BLUE12);
			SetShotDataA(0,25,0,angle,0,0.0,0,BLUE12);
			SetShotDirectionType(PLAYER);
			SetShotDataA(0,60,3,0,0,0.0,0,BLUE12);
			SetShotDirectionType(ABSOLUTE);
			FireShot(0);
		*/	ShotSnow(GetX,GetY,5,3,angle,30,BLUE12);
		angle+=15;
		}

wait(120);
}

}

task ShotSnow(let x,let y,let Pspeed,let Sspeed,let angle,let delay,let graphic)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, Pspeed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);

	loop(delay)
	{
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	loop(25)
	{
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, 0);
	loop(35)
	{
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, Sspeed);
	Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj)));
	while(!Obj_BeDeleted(obj))
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

task SubShot
{
let angle=0;
	wait(30);
	loop
	{
		let dir=rand_int(0,1)*2-1;
		shot(rand(GetClipMinX-60,GetClipMaxX+60),GetClipMinY,rand(1.5,2.5),rand(60,120),BLUE05,30,dir);
		wait(8);

	}
}

task shot(let x, let y,let speed,let angle, let graphic,let delay,let dir)//oya
{
	let count=0;
	let count1=0;
	let r=5;
	let w=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	Obj_SetAlpha(obj, 0);
	Obj_SetCollisionToPlayer(obj,false);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);

		ascent(let i in 0..6)
		{
	shot2(obj,r,w+i*60,i*60,graphic,30,dir);
	laser(obj,r,w+i*60,i*60,graphic,30,dir);
		}

}


task shot2(let parent,let r,let w,let angle,let graphic,let delay,let dir)//ko
{
	let itemx=Obj_GetX(parent)+r*cos(w);
	let itemy=Obj_GetY(parent)+r*sin(w);
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, Obj_GetX(parent)+r*cos(w), Obj_GetY(parent)+r*sin(w));
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(parent) && !Obj_BeDeleted(obj))
	{
	Obj_SetPosition(obj, Obj_GetX(parent)+r*cos(w), Obj_GetY(parent)+r*sin(w));
	r+=0.05;
	w+=1*dir;
	itemx=Obj_GetX(obj);
	itemy=Obj_GetY(obj);
	yield;
    	}
	CreateShotChengeToItem(itemx,itemy);
	Obj_Delete(obj);
}

task laser(let parent,let r,let w,let angle,let graphic,let delay,let dir)
{
	let length=5;
        let obj = Obj_Create(OBJ_LASER);
	ObjLaser_SetSource(obj, false);
        Obj_SetPosition(obj, Obj_GetX(parent), Obj_GetY(parent));
        ObjLaser_SetLength(obj, length);
        ObjLaser_SetWidth(obj, 3);
        Obj_SetAngle(obj,angle);
	Obj_SetCollisionToPlayer(obj,false);
        ObjShot_SetGraphic(obj,graphic);
	Obj_SetAlpha(obj,100);
	ObjShot_SetDelay(obj, 0);
	while(!Obj_BeDeleted(parent))
	{
	Obj_SetPosition(obj, Obj_GetX(parent), Obj_GetY(parent));
        Obj_SetAngle(obj,angle);
        ObjLaser_SetLength(obj, length);
	angle+=1*dir;
	length+=0.05;
	yield;
    	}
	Obj_Delete(obj);
}

#include_function ".\..\txt\data.txt"
#include_function ".\..\txt\Spelldata.txt"
#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
