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

script_enemy_main {

	#include_function ".\Sakuyainclude.txt";
	let i = 0;
	let wp = 0;
	let pp = -1;
	let one = 0;
	let playx = 0;
	let playy = 0;
	let color = 0;
	let acc = 1;
	let anim3 = 0;
	let color = 0;
	let x = 0;
let y = 0;
let one = 0;
let spd = 0;
let firsttime = true;
let slowed = false;
let slow = 0;
let randx = 0;
let randy = 0;




	@Initialize{
	shotinit;
	LoadSE(time1);
	LoadGraphic(background);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(ping);
	LoadSE(shot);
	DelayedStart;
	LoadSE(shot2);
	LoadSE(phase);
	LoadSE(charge2);
	LoadSE(die);
	LoadGraphic(background);
	SetTimer(199);
	SetEnemyMarker(true);
	SetInvincibility(270);
	LoadSE(avoidancesfx);
	SetDamageRate(30, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(90, 90, 90, 20);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(dream);
	LoadSE(die);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	SetCommonData("lastattack", false);
	}

task DelayedStart {
let radius = 30;
//PlaySE(avoidancesfx);
wait(70);
SetCommonData("spells", GetCommonDataDefault("spells", 0)+1);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Recursion "\""Absente Muros (Mobius Strip)"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
Spell;
SetTimer(59);
}


task Spell{
wait(120);
loop{

Concentration01(60);
PlaySE(charge2);
wait(45);
SetAction(ACT_SHOT_B, 135);
playx = GetPlayerX;
playy = GetPlayerY;

	angle = 90+(360/16/2);
	SetAction(ACT_SHOT_B, 100);
	SetCommonData("makelasers", true);
	loop(16){
	CreateWarningLaser(GetX, GetY, angle, BLUE60, 30);
	angle+=360/16;
	}
		ascent(i in 0..20){
		loop(16){
	
	CreateTrickster(GetX, GetY, 1.25+(i/3), angle, RED32, 10);
	angle+=360/16;
		}
	wait(5);
		}
	
	firsttime = false;
wait(30);
SetCommonData("makelasers", false);
wait(90);
angle = rand(0, 360);
	SetAction(ACT_SHOT_A, 240);
	ascent(i in 0..12){
loop(12){
	CreateTrickster(GetX, GetY, 2-(i/24), angle+rand(-1.5, 1.5), BLUE32, 10);
	angle+=360/12;
	}
angle+=360/12/3.45+rand(-1, 4);
wait(20);
}
wait(60);
ExMove;
wait(60);
Concentration01(60);
PlaySE(charge2);
wait(60);
angle = rand(0, 360);
SetAction(ACT_SHOT_B, 240);
ascent(w in 1..16){
	loop(4){
			ascent(w in -2..3){
		CreateTrickster(GetX, GetY, 2, angle+(w*(1+(w/60))), GREEN31, 10);
			}
		angle+=360/4;
		}
	angle+=18.216745;
	wait(15);
	}
wait(90);
SetAction(ACT_MOVE, 90);
if(pp == -1){
SetMovePosition02(GetClipMinX+10, GetClipMinY+120, 90);
}
if(pp == 1){
SetMovePosition02(GetClipMaxX-10, GetClipMinY+120, 90);
}
wait(90);
PlaySE(charge2);
Concentration01(60);
wait(60);
SetAction(ACT_MOVE, 240);
if(pp == -1){
SetMovePosition02(GetClipMaxX-10, GetClipMinY+rand(110, 120), 240);
}
if(pp == 1){
SetMovePosition02(GetClipMinX+10, GetClipMinY+rand(110, 120), 240);
}
angle = 90;
loop(16){
		loop(8){
	CreateTrickster(GetX, GetY, 2.5, angle, WHITE32, 10);
	angle+=360/8;
	}
	wait(15);
	}
loop(8){
	CreateTrickster(GetX, GetY, 2.5, angle, WHITE32, 10);
	angle+=360/8;
	}
wait(60);
pp = pp*-1;
SetMovePosition02(GetCenterX, GetClipMinY+120, 75);
SetAction(ACT_MOVE, 75);
wait(90);
}
}

task CreateWarningLaser(x, y, angle, graphic, delay){
	
	let obj = Obj_Create(OBJ_LASER);
	let time = 0;
	ObjLaser_SetSource(obj, false);
	Obj_SetPosition(obj, x, y);
	ObjLaser_SetLength(obj, 1000);
	ObjLaser_SetWidth(obj, 25);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(obj)){
	
	if(time>=delay){
	Obj_Delete(obj);
	}

	time++;
	
	yield;
	}
	
	
	
	
	
	

}




task CreateTrickster(x, y, v, angle, graphic, delay){
	let speed = v;
	let bouncecount = 0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetAutoDelete(obj, true);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, v);
	Obj_SetAngle(obj, angle);
	ObjShot_SetBombResist(obj, true);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(obj)){
	
	if(Obj_GetX(obj)>GetClipMaxX+10 && bouncecount<=0){
	//PlaySE(phase);
	if(GetCommonDataDefault("makelasers", false)==true){
	CreateWarningLaser(GetClipMinX-8, Obj_GetY(obj), angle, BLUE60, 30);
	}
	CreateShot01(GetClipMinX-8, Obj_GetY(obj), v, angle, graphic, 0);
	
	Obj_Delete(obj);
	bouncecount++;
	}
	if(Obj_GetX(obj)<GetClipMinX-10 && bouncecount<=0){
	//PlaySE(phase);
	if(GetCommonDataDefault("makelasers", false)==true){
	CreateWarningLaser(GetClipMaxX+8, Obj_GetY(obj), angle, BLUE60, 30);
	}
	CreateShot01(GetClipMaxX+8, Obj_GetY(obj), v, angle, graphic, 0);
	
	Obj_Delete(obj);
	bouncecount++;
	}
	if(Obj_GetY(obj)>GetClipMaxY+10 && bouncecount<=0){
	//PlaySE(phase);
	if(GetCommonDataDefault("makelasers", false)==true){
	CreateWarningLaser(Obj_GetX(obj), GetClipMinY-8, angle, BLUE60, 30);
	}
	CreateShot01(Obj_GetX(obj), GetClipMinY-8, v, angle, graphic, 0);
	
	Obj_Delete(obj);
	bouncecount++;
	}
	if(Obj_GetY(obj)<GetClipMinY-10 && bouncecount<=0){
	//PlaySE(phase);
	if(GetCommonDataDefault("makelasers", false)==true){
	CreateWarningLaser(Obj_GetX(obj), GetClipMaxY+8, angle, BLUE60, 30);
	}
	CreateShot01(Obj_GetX(obj), GetClipMaxY+8, v, angle, graphic, 0);
	
	Obj_Delete(obj);
	bouncecount++;
	}
	
	
	yield;
	}
	
	
	
	
	
	

}



    @BackGround{
	 SetTexture(background);
   SetGraphicRect(0, 0, 256, 256);
   SetGraphicScale(2.5, 2.5);
   SetGraphicAngle(0, 0, y);
   DrawGraphic(GetCenterX, GetCenterY);
	if(TimeStopped!=true){
   y+=acc;
	}
	if(slowed==true){
	y-=0.75;
	}
	SetGraphicAngle(0, 0, 0);
	}





	
}

