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

script_enemy_main {
	let familiar = GetCurrentScriptDirectory~"sprites\familiar.png";
	let variable = 0;
	let xvelocity = 0;
	let xpos = 0;
	let ypos = 0;
	let undulate = 0;
	let color = 0;
	#include_function ".\Yukainclude.txt";
	let i = 0;
	let one = 1;
	let anim3 = 0;
	let plax = 0;
	let blah = 0;
	@Initialize{
	shotinit;
	LoadSE(capture);
	LoadSE(time1);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(ping);
	LoadGraphic(familiar);
	LoadSE(shot);
	DelayedStart;
	LoadSE(shot2);
	LoadSE(die);
	SetTimer(199);
	SetEnemyMarker(true);
	SetInvincibility(420);
	SetDamageRate(25.5, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(50, 50, 50, 50);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(die);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	MagicCircle(false);
	}



task CreateShotAngular(x, y, v, angle, graphic, delay, angvel) {
		let obj = Obj_Create(OBJ_SHOT);
		let angle2 = 0;
		let time = 0;
		let radius = 0;
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, 0);
		Obj_SetCollisionToObject(obj, true);
		ObjShot_SetDelay(obj, delay);
		ObjShot_SetGraphic(obj, graphic);
		while(!Obj_BeDeleted(obj)){
		Obj_SetPosition(obj, x+radius*cos(angle+angle2), y+radius*sin(angle+angle2));
		radius+=v;
		angle2+=angvel;
		yield;
		}	
}		
	


task CreateTargetCircle(x, y, duration, arg){
		let obj = Obj_Create(OBJ_EFFECT);
		let anglee = 0;
  		ObjEffect_SetTexture(obj, familiar);
  		ObjEffect_SetLayer(obj, 5);
		Obj_SetAlpha(obj, 15);
  		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
  		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_InitializeRect(familiar, 5);
		ObjEffect_SetXYRect(obj, -64, -64, 64, 64); 
		ObjEffect_SetUVRect(obj, 0, 64, 64, 128);
		ObjEffect_SetRenderState(obj, ALPHA);
		Obj_SetPosition(obj, x, y);
		
		while(!Obj_BeDeleted(obj)) {
			if(arg==1){
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
			}
		ObjEffect_SetAngle(obj,0,0,anglee*2);
		ObjEffect_SetScale(obj,2-(anglee/45),2-(anglee/45));
		anglee+=1;
		if(anglee>=duration || 2-(anglee/45)<=0) { Obj_Delete(obj); }
		yield;
		}

}

task DelayedStart {
wait(60);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Living Prison "\""Carnivorous Heliotrope"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
attack1;
attack2;
SpellBG;
SetTimer(63);
}

	let backRED = 255;
	let backGREEN = 255;
	let backBLUE = 255;

task attack2{
wait(240);
loop{

ascent(i in 0..30){
		loop(6){
	CreateShot01(GetX, GetY, 1.5+(i/27), (angle*one)+rand(-1, 1), [YELLOW12, ORANGE12][color%2], 10);
	CreateShot01(GetX, GetY, 1.8+(i/27), -(angle*one)+rand(-1, 1), [ORANGE12, YELLOW12][color%2], 10);
		angle+=360/6;
		}
	angle+=8.89587246;
	wait(10);
	}
wait(60);

loop(60){
		ascent(i in -2..2){
	CreateShot12(GetX, GetY, 1.2*sin(xvelocity*1.2)+(i/75), -2+i/7, 0, 0.025, 20, 2.65, RED11, 10);
		}
	wait(1);
	xvelocity+=12;
	}
	
wait(180);

	loop(8){
loop(14){	
	CreateShotAngular(GetX, GetY, 1.75, angle, [BLUE02, RED02][color%2], 10, 0.65*one);	
	angle+=360/14;
	}
color++;
one*=-1;
wait(20);
}
wait(90);

}
}


task attack1{
wait(120);
PlaySE(charge);
Concentration01(60);
SetAction(ACT_SHOT_A, 60);
wait(60);
loop(12){
	CreateEnemyFromScript("pitcher", GetPlayerX, GetPlayerY, 0, 0, angle);
	angle+=360/12;
	}
CreateTargetCircle(GetPlayerX, GetPlayerY, 180, 1);
wait(180);
CreateTargetCircle(GetCenterX, GetCenterY+90, 180, 0);
PlaySE(charge);
wait(60);
SetCommonData("XPosition", GetCenterX);
SetCommonData("YPosition", GetCenterY+90);
wait(240);
loop{
xpos = GetClipMinX+80+rand(-35, 35);
ypos = GetCenterY+90+rand(-15, 15);
CreateTargetCircle(xpos, ypos, 180, 0);
PlaySE(charge);
wait(60);
SetMovePosition03(xpos+rand(-10, 10), GetClipMinY+120+rand(-10, 10), 11, 1.25);
SetAction(ACT_MOVE, 120);
SetCommonData("XPosition", xpos);
SetCommonData("YPosition", ypos);
wait(240);
xpos = GetCenterX+rand(-15, 35);
ypos = GetCenterY+120+rand(-20, 20);
CreateTargetCircle(xpos, ypos, 180, 0);
PlaySE(charge);
wait(60);

SetMovePosition03(xpos+rand(-10, 10), GetClipMinY+120+rand(-10, 10), 11, 1.25);
SetAction(ACT_MOVE, 120);
SetCommonData("XPosition", xpos);
SetCommonData("YPosition", ypos);
wait(240);
xpos = GetClipMaxX-80+rand(-35, 35);
ypos = GetCenterY+70+rand(-20, 20);
CreateTargetCircle(xpos, ypos, 180, 0);
PlaySE(charge);
wait(60);

SetMovePosition03(xpos+rand(-10, 10), GetClipMinY+120+rand(-10, 10), 11, 1.25);
SetAction(ACT_MOVE, 120);
SetCommonData("XPosition", xpos);
SetCommonData("YPosition", ypos);
wait(240);
xpos = GetCenterX+rand(-35, 15);
ypos = GetCenterY+120+rand(-20, 20);
CreateTargetCircle(xpos, ypos, 180, 0);
PlaySE(charge);
wait(60);

SetMovePosition03(xpos+rand(-10, 10), GetClipMinY+120+rand(-10, 10), 11, 1.25);
SetAction(ACT_MOVE, 120);
SetCommonData("XPosition", xpos);
SetCommonData("YPosition", ypos);

wait(180);
}
}


	task SpellBG {
		let w = 60;
		wait(w);
		loop(w){
			backGREEN-=255/w;
			backBLUE-=255/w;
			wait(1);
		}
		loop{
			loop(w){
				backGREEN+=128/w;
				wait(1);
			}
			loop(w){
				backGREEN+=127/w;
				wait(1);
			}
			loop(w){
				backRED-=255/w;
				wait(1);
			}
			loop(w){
				backBLUE+=255/w;
				wait(1);
			}
			loop(w){
				backGREEN-=255/w;
				wait(1);
			}
			loop(w){
				backRED+=255/w;
				wait(1);
			}
			loop(w){
				backBLUE-=255/w;
				wait(1);
			}
		}
	}




@BackGround{
SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetGraphicScale(1, 1);
SetColor(backRED/3, backGREEN/3, backBLUE/3);
SetGraphicRect(19, 0+(anim2*5), 474, 455+(anim2*5));
SetAlpha(255);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetColor(255, 255, 255);
SetGraphicScale(1, 1);
SetGraphicRect(0, 0-(anim2*4), 512, 512-(anim2*4));
SetAlpha(60);
DrawGraphic(GetCenterX, GetCenterY);
SetColor(255, 255, 255);
i+=1; i%=360;
anim2 += 0.75;
acc1 = 6;
}	
}


script_enemy pitcher{
	 
	
	
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	#include_function ".\cutin.dnh"
	
	


let f = true;
let variation = 1;
let graphic = GetArgument/30;
let variable = 1;
let frame = -60;
let shooting = false;
let frame2 = -60;
let boom = GetCurrentScriptDirectory~"sfx\boom.wav";
let frame3 = -60;
let border = GetCurrentScriptDirectory~"sfx\border.wav";
let orb = GetCurrentScriptDirectory~"sfx\orb.wav";
let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
let charge = GetCurrentScriptDirectory~"sfx\Charge.wav";
let laser2 = GetCurrentScriptDirectory~"sfx\laser2.wav";
let wtf = GetCurrentScriptDirectory~"sfx\kira00.wav";
let b = 0;
let timer = GetTimer;
let time1 = GetCurrentScriptDirectory~"sfx\time1.wav";
let time2 = GetCurrentScriptDirectory~"sfx\time2.wav";
let warp = GetCurrentScriptDirectory~"sfx\warp.wav";
let caution = GetCurrentScriptDirectory~"sfx\caution.wav";
let acc1 = 0;
let acc2 = 0;
let c = 0;
let acc3 = 0;
let acc5 = 0;
let EnX = GetEnemyX;
let EnY = GetEnemyY;
let ang = 0;
let anim1 = 0;
let c = 0;
let angle = GetArgument;
let anim2 = 0;
let anim3 = 0;
let radius = 0;
let something = 10;
let time = 0;
let angle = 0;
let CBG1 = GetCurrentScriptDirectory~"sprites\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"sprites\CBG2.png";
let ang = 0;
let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
let objbullets = [];
let pointx = GetX;
let var = 0;
let locx = GetPlayerX;
let locy = GetPlayerY;
let pointy = GetY;
let objgrowers = [];
let part1stop = false;
let variation = 0;
let autodelete = false;
let radiusdecel = 10;
let x = 20000;
let y = 20000;
let imglifebar = GetCurrentScriptDirectory~"lifebar_thWW.png";
let familiarspawn = GetCurrentScriptDirectory~"sfx\Shadow.wav";
let familiar = GetCurrentScriptDirectory~"sprites\familiar.png";
let bgm = GetCurrentScriptDirectory~"mu\bgm.mp3";
let SP = GetCurrentScriptDirectory~"sprites\futo.png";
let laser = GetCurrentScriptDirectory~"sfx\laser.wav";
let MC = GetCurrentScriptDirectory~"sprites\NMC.png";
let angle2 = 0;
	@Initialize {
	DeleteSE("se\seEnemyExplode01.wav");
	DeleteSE("se\seUseSpellCard.wav");
	LoadSE(shot);
	firing;
	LoadSE(boom);
	LoadSE(laser2);
	LoadSE(shot2);
	LoadGraphic(familiar);
	LoadSE(shot3);
	
	SetLife(750000000);
	SetDamageRateEx(100, 100, 80, 40);
	existance;
	movement;
	angle = GetArgument;
	}


function WithinPlayingField {
if(GetX>GetClipMinX-10 && GetX<GetClipMaxX+10 && GetY>GetClipMinY-50 && GetY<GetClipMaxY+10){ return true; }
else { return false;  }
}


	function GetDistance(x1,y1,x2,y2){
return(((x2-x1)^2+(y2-y1)^2)^(1/2))
} 
	

	task existance {
	radius = 750;
	loop{
	
	if(part1stop==false){
	radius=300+210*cos(var);
	var+=1;
	}
	if(radius<=90){
	part1stop = true;
	}
	wait(1);
	

}
}
	task movement {
		loop{
			if(time<240){
			SetX(locx+radius*cos(angle));
			SetY(locy+radius*sin(angle));
			}
			if(time>240){
			radius = 110;
			SetMovePosition02(locx+radius*cos(angle), locy+radius*sin(angle), 75);
			}
			angle+=1;
			
			wait(1);
			
		}
}

	
	@MainLoop{
	locx = GetCommonDataDefault("XPosition", GetPlayerX);
	locy = GetCommonDataDefault("YPosition", GetPlayerY);
	
	//DeleteEnemyShotImmediatelyInCircle(CHILD, GetPlayerX, GetPlayerY, 1);
	SetCollisionB(GetX, GetY, 6);
	yield;
	time++;
	if(autodelete == true){
		if(WithinPlayingField == false){
			VanishEnemy;
			}
		}
	
	}
task firing{
	wait(10);
		loop{
			x = GetX;
			y = GetY;
			if(WithinPlayingField==true){
			
			CreateShot01(GetX, GetY, 4, angle+45, GREEN23, 0);	
			CreateShot01(GetX, GetY, 4, angle-45, GREEN23, 0);
			
			}

			wait(5);
			}
		}
function wait(w){ loop(w){ yield;} }


 @DrawLoop {
SetTexture(familiar);
SetGraphicRect(0, 0, 64, 64);
SetGraphicScale(0.35, 0.35);
SetAlpha(255);
SetGraphicAngle(0, 0, frame*4);
DrawGraphic(GetX, GetY);
	SetGraphicScale(1, 1);
	SetGraphicAngle(0, 0, 0);
frame++;
}


@Finalize {

if(!BeVanished){
DeleteEnemyShotToItem(CHILD);
PlaySE(boom);       
}


}

}

