#東方弾幕風
#Title[幻花「向日葵畑の幻想花」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "幻花「向日葵畑の幻想花」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_yuka.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
    let imgBG  = csd ~ "..\img\st4bg1.png";
    let imgBG2  = csd ~ "..\img\st4bg2.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;

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

	let bgy=0;
	let BGangle=0;
    @Initialize {

       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(52);

        SetLife(900);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        LoadGraphic(imgBG);
        LoadGraphic(imgBG2);
	InitializeAction();
        TMain;
    }

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

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

    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(52);
	loop(25)
	{
		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,1280,1920+bgy);
		SetGraphicAngle(0,0,0);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
		SetTexture(imgBG2);
		SetGraphicRect(0,0,640,640);
		SetGraphicAngle(0,0,BGangle);
		SetColor(150,150,150);
		SetAlpha(50);
		DrawGraphic(224, 240);	

	}
    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	Shot;
	summon;
}

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

task summon
{
	CreateEnemyFromScript("Familiar", GetX,GetY,2,180, 1);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,0, -1);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,180, 2);
	CreateEnemyFromScript("Familiar", GetX,GetY,2,0, -2);
}


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 Shot
{
let dir=rand_int(0,1)*2-1;
let w=60;
let angle=atan2(GetPlayerY-GetClipMinY,60);
let dx;
let dy;
	loop
	{
	ascent(let i in 0..12)
	{
		CreateLaserA(0,GetX,GetY,400,60,161,60);		
		SetLaserDataA(0,0,GetAngleToPlayer+30*i,0,0,0,0);
		SetShotKillTime(0,180);
		FireShot(0);
	}
		wait(240);
	}
}


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

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
	let numY=0;;
	if(absolute(num)==1)
	{
		numY=75;
	}
    @Initialize {
        SetLife(2000);
        SetScore(10000);
        SetDamageRate(50, 50);
      //  SetTexture(imgFam);
        setGraphic;
	SetSpeed(speed);
	SetAngle(angle);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
	shot;
	move;
    }

task move
{
	SetMovePosition02(GetEnemyX+75*num, GetEnemyY-numY, 60);
}

task shot
{
wait(60);
let dx;
let dy;
let CR=255;
let CG=255;
let CB=100;
loop
{
let rangle=rand(0,360);
ascent(let j in 0..24)
{
CB=150;
	ascent(let i in -1..5)
	{
	SetShotColor(CR,CG,CB);
/*	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,speed+i,angle+j*15+rangle,0,0,0,33);
	SetShotDataA(0,20,0,angle+j*15+rangle,0,0,0,33);
	SetShotDataA(0,60,2,angle+j*15+rangle,0,0.03,8,33);
	FireShot(0);
*/	ShotGen(GetX,GetY,speed+i,2,0.03,angle+j*15+rangle,5,33);
	CB+=20;
	}
//wait(1);
}
wait(120);
}
}

task ShotGen(let x,let y,let Pspeed,let speed,let aspeed,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)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	loop(20)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, 0);
	loop(40)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, speed);
	while(!Obj_BeDeleted(obj))
	{
		speed+=aspeed;
		Obj_SetSpeed(obj, speed);
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}


    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"
}
