#東方弾幕風
#Title[死神「彼岸への先導-Lunatic」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "死神「彼岸への先導-Lunatic」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_komachi.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st5bg1.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 bgx=0;
	let bgy=0;
    @Initialize {

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

        SetLife(800);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
        DeleteGraphic(imgBG);
		EndSpellHistory(78);
	loop(30)
	{
		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+bgx,960+bgy);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);
		bgx+=3;
		bgy+=3;
	}
    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	loop(3)
	{
	ascent(let i in 0..120)
	{
		shotL(GetX, GetY, 20, i*3);
	}
	wait(5);
	}
	Distance;
	Shot;
	//SubShot;
	//SubShot2;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
	loop
	{
		if(!OnBomb)
		{
			SetDamageRate(25, 25);
		}
		else
		{
			SetDamageRate(10, 10);
		}
		yield;
	}
}

task Distance
{
let distance=300;
let angle=90;
loop
{
SetPlayerX(GetX+distance*cos(angle));
SetPlayerY(GetY+distance*sin(angle));
	if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
	{
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			angle+=0.5;
			if(GetClipMinX+16>GetPlayerX)
			{
				angle-=0.5;
			}
			if(GetClipMinY+20>GetPlayerY)
			{
				angle-=0.5;
			}
		}
		else
		{
			angle+=1;
			if(GetClipMinX+16>GetPlayerX)
			{
				angle-=1;
			}
			if(GetClipMinY+20>GetPlayerY)
			{
				angle-=1;
			}
		}
	}
	if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
	{
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			angle-=0.5;
			if(GetClipMaxX-16<GetPlayerX)
			{
				angle+=0.5;
			}
			if(GetClipMinY+20>GetPlayerY)
			{
				angle+=0.5;
			}
		}
		else
		{
			angle-=1;
			if(GetClipMaxX-16<GetPlayerX)
			{
				angle+=1;
			}
			if(GetClipMinY+20>GetPlayerY)
			{
				angle+=1;
			}
		}
	}
yield;
distance-=0.075;
}

}


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 angle=rand(0,360);
	surround(angle,104,0);
	surround(angle+60,102,0);
	surround(angle+120,99,0);
	surround(angle+180,100,0);
	surround(angle+240,97,0);
	surround(angle+300,104,1);
}

task surround(let angle,let color,let judg)
{
	let r=80;
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, RED01);
        Obj_SetPosition(obj,GetX+r*cos(angle), GetY+r*sin(angle));
	ObjShot_SetBombResist(obj,true);
	surround2(obj,color,judg);
	Obj_SetAlpha(obj,0);
	while(!Obj_BeDeleted(obj))
	{
      		Obj_SetPosition(obj,GetX+r*cos(angle), GetY+r*sin(angle));
		angle+=1;
		yield;
	}
}

task surround2(let parent,let color,let judg)//ko
{
	let r=40;
	let angle=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj,Obj_GetX(parent)+r*cos(angle), Obj_GetY(parent)+r*sin(angle));
	ObjShot_SetGraphic(obj, BLUE01);
	ObjShot_SetDelay(obj, 0);
	ObjShot_SetBombResist(obj,true);
	surroundshot(obj,color,judg);
	Obj_SetAlpha(obj,0);
	while(!Obj_BeDeleted(obj))
	{
      		Obj_SetPosition(obj,Obj_GetX(parent)+r*cos(angle), Obj_GetY(parent)+r*sin(angle));
		angle+=2;
		yield;
    	}

}

task surroundshot(let parent,let color,let judg)//ko
{
let way=6;
loop
{
	ascent(let i in 0..way)
	{
if(color==104 && judg==1)
{
SetShotColor(200,200,200)
}
else
{
SetShotColor(255,255,255)
}
		CreateShot01(Obj_GetX(parent), Obj_GetY(parent),3,atan2(GetY-Obj_GetY(parent),GetX-Obj_GetX(parent))+i*360/way,color,5);
	}
	wait(20);
}
}

task shotL(let x, let y, let speed, let angle) 
{
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, RED01);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        Obj_SetPosition(obj,x, y);
       Obj_SetCollisionToPlayer(obj, false);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
 
        let objE = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(objE, RED01);
        Obj_SetAngle(objE, angle);
        Obj_SetSpeed(objE, speed);
        Obj_SetPosition(objE, x, y);
       Obj_SetCollisionToPlayer(objE, false);
	Obj_SetAlpha(objE,0);
	ObjShot_SetBombResist(objE,true);
        loop(90)
	{
	ObjShot_SetDelay(objE,30);
            Obj_SetPosition(objE, Obj_GetX(obj) + speed * cos(angle),
                                  Obj_GetY(obj) + speed * sin(angle));
            yield;
        }
        Obj_Delete(objE);
        Obj_Delete(obj);
    }

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