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

script_enemy_main {
#include_function ".\Sakuyainclude.txt";

	@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(175, 55);
	SetMovePosition03(GetCenterX, GetClipMinY + 120, 10, 2);
	LoadGraphic(SP);
	LoadGraphic(MC);
	attack1;
	MagicCircle(false);
	SetShotAutoDeleteClip(50, 30, 50, 10);
	SetEnemyMarker(true);
	SetCommonData("lastattack", false);
	}


task attack1 {
	wait(180);
	
	loop{
	let randnum = 0;
	let PlayerLeft = GetAngleToPlayer-90;
	let PlayerRight = GetAngleToPlayer+90;
		 randnum = rand(GetAngleToPlayer+20, GetAngleToPlayer-20);
	loop(60){
		PlaySE(shot2);
		CreateShotReflectt(GetX, GetY, 3.5, PlayerLeft+angle, GREEN32, 0, 0);
		CreateShotReflectt(GetX, GetY, 3.5, PlayerRight-angle, GREEN32, 0, 0);
		angle+=6;
		wait(2);	
		}
	wait(60);
	ExMove;
	wait(30);
	PlaySE(shot);
	loop(30){
		
		
		CreateShotReflectt(GetX, GetY, 4, PlayerRight-angle, GREEN32, 0, 0);
		CreateShotReflectt(GetX, GetY, 3, PlayerRight-angle, GREEN32, 0, 0);
		CreateShotReflectt(GetX, GetY, 2, PlayerLeft-angle, GREEN32, 0, 0);
		angle+=360/30;
		wait(0);	
		}
	wait(60);
	}
		
}

 task CreateShotReflectt(x, y, v, ang, graphic, delay, moo) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = -10; let  counter = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); Obj_SetAngle(obj_id, ang); ObjShot_SetDelay(obj_id, delay);
		while(!Obj_BeDeleted(obj_id)) {
				
				if(Obj_GetX(obj_id) > GetClipMaxX+border) { CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2.5, 180-Obj_GetAngle(obj_id), BLUE32, 30); CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 3.5, 180-Obj_GetAngle(obj_id), BLUE32, 30); Obj_Delete(obj_id);  }
				else if(Obj_GetX(obj_id) < GetClipMinX-border) { CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2.5, 180-Obj_GetAngle(obj_id), BLUE32, 30); CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 3.5, 180-Obj_GetAngle(obj_id), BLUE32, 30); Obj_Delete(obj_id); }
				//else if(Obj_GetY(obj_id) < GetClipMinY-border) {  CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2, -Obj_GetAngle(obj_id), 218, 30); CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2.5, -Obj_GetAngle(obj_id), 218, 30); Obj_Delete(obj_id); }
				//else if(Obj_GetY(obj_id) > GetClipMaxY+border) { CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2, -Obj_GetAngle(obj_id), 218, 30); CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 2.5, -Obj_GetAngle(obj_id), 218, 30); Obj_Delete(obj_id); }
	yield;
			}
			
		}
	


}
