#TouhouDanmakufu
#Title[SakuyaN4_H]
#Text[SakuyaN4_H]
#Player[FREE]
#ScriptVersion[2]
#BGM[.\mu\bgm.mp3]

script_enemy_main {
#include_function ".\Sakuyainclude.txt";
let angle2 = 0;
let argument = 0;
	@Initialize{
	InitializeAction;
	LoadMusic(bgm);
	PlayMusic(bgm);
	LoadSE(shot3);
	LoadSE(time1);
	LoadSE(teleport);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(wtf);
	shotinit;
	LoadSE(charge);
	SetAction(ACT_MOVE, 120);
	LoadSE(shot);
	LoadSE(shot2);
	LoadSE(laser);
	LoadSE(familiarspawn);
	LoadGraphic(imglifebar); 
	SetLife(6000);
	LoadSE(shot2);
	SetTimer(45);
	SetInvincibility(260);
	SetDamageRate(150, 55);
	SetMovePosition03(GetCenterX, GetClipMinY + 120, 10, 2);
	LoadGraphic(SP);
	LoadGraphic(MC);
	
	MagicCircle(false);
	SetShotAutoDeleteClip(50, 30, 50, 10);
	SetEnemyMarker(true);
	SetCommonData("lastattack", false);
	Spell;
	SpellDos;
	}



task SpellDos{
	wait(120);
	loop{
	loop(8){
		loop(15){
		PlaySE(shot2);
		CreateShot01(GetX, GetY, 3, 90+angle-angle2, ORANGE32, 0);
		angle+=360/15;
		
		}
		angle2+=1.5;
		wait(6);
		}
		wait(20);
		loop(8){
		loop(15){
		PlaySE(shot2);
		CreateShot01(GetX, GetY, 3, 90+angle+angle2, YELLOW32, 0);
		angle+=360/15;
		
		}
		angle2+=1.5;
		wait(6);
		}
		wait(60);
	}
}
		

task Spell{
	wait(120);
	loop{
PlaySE(familiarspawn);
loop(8){
argument++;
if(argument>1){
argument=0;
}
CreateEnemyFromScript("familiar", GetX+30*cos(angle), GetY+30*sin(angle), 0.4, angle, argument);
angle+=360/8;
}
wait(180);
ExMove;
wait(130);
ExMove;
	
}
}
}

script_enemy familiar {
	let anim = 0;
	let vanished = false;
	let img = GetCurrentScriptDirectory~"sprites\familiar.png";
	let graphic = 76;
	let ang = atan2(GetPlayerY - GetY, GetPlayerX-GetX);
	let www = 0;
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame=0;
	let angle=0;
	let frame2 = 0;
	@Initialize{
	LoadGraphic(img);
	Attack;
	if(GetArgument==0){
	graphic = BLUE31;
	}
	if(GetArgument==1){
	graphic = RED31;
	}
	
	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
		wait(0);
		loop(32){
		PlaySE(shot);
		CreateShot01(GetX, GetY, 2, ang+angle, graphic, 10);
		CreateShot01(GetX, GetY, 2, ang+angle+1, graphic, 10);
		CreateShot01(GetX, GetY, 2, ang+angle+2, graphic, 10);
		CreateShot01(GetX, GetY, 2, ang+angle-1, graphic, 10);
		CreateShot01(GetX, GetY, 2, ang+angle-2, graphic, 10);
		
		if(GetArgument==0){
		
		angle+=23;
		}
		else if(GetArgument==1){
		angle-=23;
		}
		wait(10);
		}
		vanished = true;		VanishEnemy;
}
	@MainLoop{
	

	
	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	
	SetTexture(img);
	SetGraphicScale(1, 1);
	SetAlpha(255);
	SetGraphicRect(0, 0, 64, 64);
	SetGraphicAngle(0, 0, anim);
	DrawGraphic(GetX, GetY);
}

	
	function wait(w){ loop(w){ yield;}}
	@Finalize{
	PlaySE(GetCurrentScriptDirectory~"sfx\explode.wav");
	}

}


