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


script_enemy_main {
	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 {
	GenericNonspell;
	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(100, 200, 100, 100);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(180, 100);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        
       
    }




task GenericNonspell {
	wait(180);
	
	loop{
	let PlayerLeft = GetAngleToPlayer-90;
	let PlayerRight = GetAngleToPlayer+90;
		 randnum = rand(GetAngleToPlayer+20, GetAngleToPlayer-20);
	loop(60){
		PlaySE(shot2);
		CreateShotReflect(GetX, GetY, 3.5, PlayerLeft+angle, 220, 0);
		CreateShotReflect(GetX, GetY, 3.5, PlayerRight-angle, 220, 0);
		angle+=9;
		wait(2);	
		}
	wait(60);
	ExMove;
	wait(30);
	PlaySE(shot);
	loop(30){
		
		
		CreateShotReflect(GetX, GetY, 4, PlayerRight-angle, 220, 0);
		CreateShotReflect(GetX, GetY, 3, PlayerRight-angle, 220, 0);
		CreateShotReflect(GetX, GetY, 2, PlayerLeft-angle, 220, 0);
		angle+=360/30;
		wait(0);	
		}
	wait(60);
	}
		
}
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 {
	

    }
}
