#TouhouDanmakufu
#Title[SakuyaS3_H]
#Text[SakuyaS3_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 a = 0;
	let playx = 0;
	let playy = 0;
	let bulletx = 0;
	let bullety = 0;
	let color = 0;
	let acc = 1;
	let anim3 = 0;
	let color = 0;
	let angle2 = 0;
	let x = 0;
let rotationconstant = 2;
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(phase);
	LoadSE(shot2);
	LoadSE(charge2);
	LoadSE(die);
	LoadGraphic(background);
	SetTimer(199);
	SetEnemyMarker(true);
	SetInvincibility(270);
	SetDamageRate(57, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(90, 90, 90, 20);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shadowstep);
	LoadSE(shot4);
	LoadSE(dream);
	LoadSE(die);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	SetCommonData("lastattack", false);
	}

task DelayedStart {
let radius = 30;
SetCommonData("spells", GetCommonDataDefault("spells", 0)+1);
wait(70);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Subtlety "\""Shadowstep"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
Spell;
SetTimer(49);
}


task Spell{
wait(120);
loop{
Concentration01(60);
PlaySE(charge2);
wait(75);
SetX(GetPlayerX-70*cos(GetAngleToPlayer+rand(-5, 5)));
SetY(GetPlayerY-70*sin(GetAngleToPlayer+rand(-5, 5)));
PlaySE(shadowstep);
TimeStop(70, 1, 1, 0); 
TimeStopped=true;
wait(20);
SetAction(ACT_SHOT_A, 50);
ascent(i in -3..4){
	bulletx = GetX-60*cos(GetAngleToPlayer+i*30);
	bullety = GetY-60*sin(GetAngleToPlayer+i*30);
	CreateShot01(bulletx, bullety, 2, atan2(GetPlayerY-bullety, GetPlayerX-bulletx), RED32, 0);
	CreateShot01(bulletx, bullety, 3, atan2(GetPlayerY-bullety, GetPlayerX-bulletx), RED32, 0);
	wait(2);
	}
wait(35-14);
TimeStopped=false;
wait(15);
PlaySE(shadowstep);
SetX(GetCenterX+rand(-20, 20));
SetY(GetClipMinY+120+rand(-10, 15));
rotationconstant = rand(1.8, 2.4);
spd = rand(-2, 2);
angle = GetAngleToPlayer+(360/32);
ascent(w in 0..13){
	spd = 0;
	
	loop(16){
	CreateShotA(1, GetX, GetY, 30);
	SetShotDataA(1, 0, 0.15+(w/3.75), angle+spd, 0, 0, 0, BLUE32);
	SetShotDataA(1, 138, 0, NULL, 0.75+(rotationconstant-(w/10)), 0, 3, NULL);
	SetShotDataA(1, 163, NULL, NULL, 0, 0.01, 3, WHITE32);
	SetShotDataA(1, 163+10, NULL, NULL, 0, 0.01, 3, GREEN32);
	FireShot(1);
	CreateShotA(1, GetX, GetY, 30);
	SetShotDataA(1, 0, 0.15+(w/3.75), angle+spd, 0, 0, 0, BLUE32);
	SetShotDataA(1, 138, 0, NULL, -0.75-(rotationconstant-(w/10)), 0, 3, NULL);
	SetShotDataA(1, 163, NULL, NULL, 0, 0.01, 3, WHITE32);
	SetShotDataA(1, 163+10, NULL, NULL, 0, 0.01, 3, GREEN32);
	FireShot(1);
	angle+=360/16;
	}
	}
wait(120);

}
}


task CreateTrickster(x, y, v, angle, graphic, delay){
	let speed = v;
	let bouncecount = 0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetAutoDelete(obj, true);
	LoadSE(phase);
	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);
	CreateShot01(GetClipMinX-8, Obj_GetY(obj), v, angle, graphic, 0);

	Obj_Delete(obj);
	bouncecount++;
	}
	if(Obj_GetX(obj)<GetClipMinX-10 && bouncecount<=0){
	PlaySE(phase);
	CreateShot01(GetClipMaxX+8, Obj_GetY(obj), v, angle, graphic, 0);
	
	Obj_Delete(obj);
	bouncecount++;
	}
	if(Obj_GetY(obj)>GetClipMaxY+10 && bouncecount<=0){
	CreateShot01(Obj_GetX(obj), GetClipMinY-8, v, angle, graphic, 0);
	PlaySE(phase);
	Obj_Delete(obj);
	bouncecount++;
	}
	if(Obj_GetY(obj)<GetClipMinY-10 && bouncecount<=0){
	CreateShot01(Obj_GetX(obj), GetClipMaxY+8, v, angle, graphic, 0);
	PlaySE(phase);
	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);
	}





	
}
script_enemy clock {


	let clocka = GetCurrentScriptDirectory ~ "sprites\clocka.png";
	let clockb = GetCurrentScriptDirectory ~ "sprites\clockb.png";
	let clockc = GetCurrentScriptDirectory ~ "sprites\clockc.png";
	let angle = 0;

	@Initialize {
	DeleteSE("se\seExplode01.wav");
	SetLife(1);
	LoadGraphic(clocka);
	LoadGraphic(clockb);
	LoadGraphic(clockc);
	}

	@MainLoop {
	angle+=0.12;
	if(GetDistance(GetPlayerX, GetPlayerY, GetX, GetY)<58 && GetTimeOfPlayerInvincibility<=0){
		TimeStop(1, 1, 0, 0);
	}
	if(GetX<=GetClipMinX-58 || GetX>=GetClipMaxX+58 || GetY<=GetClipMinY-58 || GetY>=GetClipMaxY+58){
		VanishEnemy;
		}
	yield;
	}

	@DrawLoop {
	SetTexture(clockb);
	SetRenderState(ALPHA);
	SetAlpha(190);
	SetGraphicRect(0, 0, 232, 232);
	SetGraphicAngle(0, 0, angle*2);
	SetGraphicScale(0.6, 0.6);
	DrawGraphic(GetX, GetY);
	
	SetTexture(clocka);
	SetRenderState(ADD);
	SetGraphicRect(0, 0, 256, 256);
	SetGraphicAngle(0, 0, angle*-4);
	SetGraphicScale(0.6, 0.6);
	DrawGraphic(GetX, GetY);
	
	SetTexture(clockc);
	SetRenderState(ADD);
	SetGraphicRect(0, 0, 32, 113);
	SetGraphicAngle(0, 0, angle*37);
	SetGraphicScale(0.6, 0.6);
	DrawGraphic(GetX + 25*cos((angle*37)-90), GetY+ 25*sin((angle*37)-90));
	
	
	SetTexture(clockc);
	SetRenderState(ADD);
	SetGraphicRect(32, 0, 64, 113);
	SetGraphicAngle(0, 0, angle*5);
	SetGraphicScale(0.6, 0.6);
	DrawGraphic(GetX + 25*cos((angle*5)-90), GetY + 25*sin((angle*5)-90));
	}

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