#TouhouDanmakufu
#Title[Sakuya's 5th Nonspell -Normal-]
#Text[PAD- *knifed*!]
#Player[FREE]
#BGM[.\spellbg.mp3]
#ScriptVersion[2]
#BackGround[User(.\stgbg.png, 0, 0)]


script_enemy_main {
	let argument = 0;
	let randnum = 0;
	let one = 1;
	let frame = 0;
	let frame2 = 0;
	let frame3 = 0;
	let angle = 0;
	let angle2 = 0;
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let shot3 = GetCurrentScriptDirectory~"shot3.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let explode = GetCurrentScriptDirectory~"explode.wav";
	let familiarspawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let time1 = GetCurrentScriptDirectory~"time1.wav";
	let time2 = GetCurrentScriptDirectory~"time2.wav";
	let frame = -120;
	let timer = GetTimer;
	let Custom = GetCurrentScriptDirectory~"sup\supershot.txt";
#include_function ".\sakuyaanimationyay.txt"
    @Initialize {
	Spell;
	SpellDos;
	DeleteSE("se\seEnemyExplode01.wav");
	DeleteSE("se\seUseSpellCard.wav");
        SetLife(6000);
	LoadUserShotData(Custom);
        SetTimer(48);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(time1);
	LoadSE(time2);
	LoadSE(shot2);
	LoadSE(shot3);
	LoadSE(familiarspawn);
	SetShotAutoDeleteClip(10, 10, 10, 10);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(190, 100);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        
       
    }

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

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

function wait(w){ loop(w){yield;}}
 task CreateShotReflect(x, y, v, ang, graphic, delay) {
		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), 218, 30); CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 3.5, 180-Obj_GetAngle(obj_id), 218, 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), 218, 30); CreateShot01(Obj_GetX(obj_id), Obj_GetY(obj_id), 3.5, 180-Obj_GetAngle(obj_id), 218, 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;
			}
			
		}
	

sub ExMove { ExMove_(GetCenterY-120, 20, rand(30, 60)); }
function ExMove_(height, ud, length) {
	
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length, rand(height+20 - ud, height + ud), 5, 1);
		} else {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 1);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 1);
		} else {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 5, 1);
		}
	}
}
    @MainLoop {

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);





frame++;
yield;
}    



    @DrawLoop {
		animm;
    }




    @Finalize {
	

    }
}
script_enemy familiar {
	let graphic = 220;
	let ang = rand(0, 360);
	let www = 0;
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	#include_function ".\familiaranim.txt";
	let Custom = GetCurrentScriptDirectory~"sup\supershot.txt";
	let frame=0;
	let angle=0;
	let frame2 = 0;
	@Initialize{
	Attack;
	if(GetArgument==0){
	graphic = 71;
	}
	if(GetArgument==1){
	graphic = 74;
	}
	LoadUserShotData(Custom);
	SetDamageRate(100, 100);
	SetLife(500);
	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);
		}
		VanishEnemy;
}
	@MainLoop{

	

	
	yield;
	
	
	 
}
	@DrawLoop
	{
	anim2;
}

	function wait(w){ loop(w){ yield;}}
	@Finalize{


	}
	}

}

