#東方弾幕風
#Title[狂歌「セイレーンソング-Lunatic」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "狂歌「セイレーンソング-Lunatic」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mystia.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
    let imgBG  = csd ~ "..\img\st2bg1.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 {
	StartSpellHistory(26);
        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,255,0,0);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
	SetCommonData("MoveReverse",false);
        DeleteGraphic(imgBoss);
        DeleteGraphic(imgBG);
	EndSpellHistory(26);
	loop(15)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(bgx,bgy,1280,960);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
	bgx-=1;
	bgy-=1;
	}

    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	loop(3)
	{
	ascent(let i in 0..120)
	{
		shotL(GetX, GetY, 20, i*3);
	}
	wait(5);
	}
	wait(20);
	Seiren;
	wait(30);
	shot;
}

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

task Seiren
{
SetCommonData("MoveReverse",true);
loop
{
	if(GetLife<=20)
	{
		SetCommonData("MoveReverse",false);
	}
	let hspeed=GetPlayerInfo(PLAYER_SPEED_HIGH);
	let lspeed=GetPlayerInfo(PLAYER_SPEED_LOW);
	if(GetKeyState(VK_UP) == KEY_PUSH || GetKeyState(VK_UP) == KEY_HOLD && GetPlayerMoveState==MOVE_NORMAL)
	{
		SetPlayerY(GetPlayerY+hspeed*2);
		if(GetKeyState(VK_LEFT) == KEY_PUSH || GetKeyState(VK_LEFT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY+hspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_RIGHT) == KEY_PUSH || GetKeyState(VK_RIGHT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY+hspeed*(2^0.5-2));
		}
	}
	if(GetKeyState(VK_UP) == KEY_PUSH || GetKeyState(VK_UP) == KEY_HOLD && GetPlayerMoveState==MOVE_SLOW)
	{
		SetPlayerY(GetPlayerY+lspeed*2);
		if(GetKeyState(VK_LEFT) == KEY_PUSH || GetKeyState(VK_LEFT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY+lspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_RIGHT) == KEY_PUSH || GetKeyState(VK_RIGHT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY+lspeed*(2^0.5-2));
		}
	}
	if(GetKeyState(VK_DOWN) == KEY_PUSH || GetKeyState(VK_DOWN) == KEY_HOLD && GetPlayerMoveState==MOVE_NORMAL)
	{
		SetPlayerY(GetPlayerY-hspeed*2);
		if(GetKeyState(VK_LEFT) == KEY_PUSH || GetKeyState(VK_LEFT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY-hspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_RIGHT) == KEY_PUSH || GetKeyState(VK_RIGHT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY-hspeed*(2^0.5-2));
		}
	}
	if(GetKeyState(VK_DOWN) == KEY_PUSH || GetKeyState(VK_DOWN) == KEY_HOLD && GetPlayerMoveState==MOVE_SLOW)
	{
		SetPlayerY(GetPlayerY-lspeed*2);
		if(GetKeyState(VK_LEFT) == KEY_PUSH || GetKeyState(VK_LEFT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY-lspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_RIGHT) == KEY_PUSH || GetKeyState(VK_RIGHT) == KEY_HOLD)
		{
			SetPlayerY(GetPlayerY-lspeed*(2^0.5-2));
		}
	}
	if(GetKeyState(VK_LEFT) == KEY_PUSH || GetKeyState(VK_LEFT) == KEY_HOLD && GetPlayerMoveState==MOVE_NORMAL)
	{
		SetPlayerX(GetPlayerX+hspeed*2);
		if(GetKeyState(VK_UP) == KEY_PUSH || GetKeyState(VK_UP) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX+hspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_DOWN) == KEY_PUSH || GetKeyState(VK_DOWN) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX+hspeed*(2^0.5-2));
		}
	}
	if(GetKeyState(VK_LEFT) == KEY_PUSH || GetKeyState(VK_LEFT) == KEY_HOLD && GetPlayerMoveState==MOVE_SLOW)
	{
		SetPlayerX(GetPlayerX+lspeed*2);
		if(GetKeyState(VK_UP) == KEY_PUSH || GetKeyState(VK_UP) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX+lspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_DOWN) == KEY_PUSH || GetKeyState(VK_DOWN) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX+lspeed*(2^0.5-2));
		}
	}
	if(GetKeyState(VK_RIGHT) == KEY_PUSH || GetKeyState(VK_RIGHT) == KEY_HOLD && GetPlayerMoveState==MOVE_NORMAL)
	{
		SetPlayerX(GetPlayerX-hspeed*2);
		if(GetKeyState(VK_UP) == KEY_PUSH || GetKeyState(VK_UP) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX-hspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_DOWN) == KEY_PUSH || GetKeyState(VK_DOWN) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX-hspeed*(2^0.5-2));
		}
	}
	if(GetKeyState(VK_RIGHT) == KEY_PUSH || GetKeyState(VK_RIGHT) == KEY_HOLD && GetPlayerMoveState==MOVE_SLOW)
	{
		SetPlayerX(GetPlayerX-lspeed*2);
		if(GetKeyState(VK_UP) == KEY_PUSH || GetKeyState(VK_UP) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX-lspeed*(2^0.5-2));
		}
		if(GetKeyState(VK_DOWN) == KEY_PUSH || GetKeyState(VK_DOWN) == KEY_HOLD)
		{
			SetPlayerX(GetPlayerX-lspeed*(2^0.5-2));
		}
	}
yield;
}
}


sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	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 speed=2.5;
loop
{
let angle1=rand(0,360);

	ascent(let i in 0..20)
	{
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle1+i*18,2,0,0,RED01);
		SetShotDataA(1,60,2,NULL,0,0,0,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle1+i*18+2,2,0,0,RED01);
		SetShotDataA(1,60,2.2,NULL,0,0,0,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle1+i*18+4,2,0,0,RED01);
		SetShotDataA(1,60,2.4,NULL,0,0,0,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle1+i*18+6,2,0,0,RED01);
		SetShotDataA(1,60,2.6,NULL,0,0,0,RED21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle1+i*18+8,2,0,0,RED01);
		SetShotDataA(1,60,2.8,NULL,0,0,0,RED21);
		FireShot(1);
	}
	wait(30);
	let angle2=rand(0,360);
	ascent(let i in 0..20)
	{
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle2+i*18,-2,0,0,BLUE01);
		SetShotDataA(1,60,2,NULL,0,0,0,BLUE21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle2+i*18-2,-2,0,0,BLUE01);
		SetShotDataA(1,60,2.2,NULL,0,0,0,BLUE21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle2+i*18-4,-2,0,0,BLUE01);
		SetShotDataA(1,60,2.4,NULL,0,0,0,BLUE21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle2+i*18-6,-2,0,0,BLUE01);
		SetShotDataA(1,60,2.6,NULL,0,0,0,BLUE21);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,speed,angle2+i*18-8,-2,0,0,BLUE01);
		SetShotDataA(1,60,2.8,NULL,0,0,0,BLUE21);
		FireShot(1);
	}
	wait(30);
	speed+=0.05;
}
}

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_Patchouli.txt"
}
