#TouhouDanmakufu
#Title[Second Nonspell]
#Text[SECANTCOSINE!]
#Player[FREE]
#BGM[.\BGM.mp3]
#ScriptVersion[2]
#BackGround[User(.\BG.png, 0, 0)]


script_enemy_main {
    let ImgBoss = GetCurrentScriptDirectory~"nimono.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let time1 = GetCurrentScriptDirectory~"time1.wav";
	let time2 = GetCurrentScriptDirectory~"time2.wav";
	let timer = GetTimer;
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let explode = GetCurrentScriptDirectory~"explode.wav";
	let familiarspawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let tilt = 0;
	let alive = 1;
	let moo = 867;
	let xs = GetCommonData("secx");
	let ys = GetCommonData("secy");
	let xy = 0;
	let nyan = 1;
	let v = 1;
    let frame = -120;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
	DeleteSE("se\seEnemyExplode01.wav");
        SetLife(2000);
	SetCommonData("alive", true);
        SetTimer(40);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(shot2);
	LoadSE(time1);
	LoadSE(time2);
	LoadSE(familiarspawn);
	SetShotAutoDeleteClip(100, 200, 100, 100);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(100, 40);
        SetMovePosition02(GetCenterX+100, GetClipMinY + 120, 120);
        
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        SetGraphicRect(1, 1, 128, 128);
    }

    @MainLoop {

		

	if(GetTimer!=timer && (GetTimer < 10 && GetTimer>3)){
	PlaySE(time1);
	}

	if(GetTimer!=timer && GetTimer < 4){
	PlaySE(time2);
	}

	timer = GetTimer;


	let xs = GetCommonData("secx");
	let ys = GetCommonData("secy");


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



if(frame2==1){
CreateEnemyFromFile(GetCurrentScriptDirectory~"Secant2A.txt", xs, ys, 0, 0, 0);
}




if(GetCommonData("alive")==true){
if(frame == 110 || frame == 95 || frame == 80 || frame == 65 || frame == 50 || frame == 35 || frame == 20 || frame == 5){
	
	
	let a   = rand(-2, 2);
        let num = 1; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
		
            CreateShot01(GetX+rand(-100, 100), GetY+rand(-40, 40), 2.5, a+GetAngleToPlayer-a, YELLOW22, 20);
	    CreateShot01(GetX+rand(-100, 100), GetY+rand(-40, 40), 3, a+GetAngleToPlayer-a, YELLOW23, 20);
	    
           a+=0;
	PlaySE(shot);

	
		

}

}



if(frame == 110){
frame=-10;
}
}

if(GetCommonData("alive")==false){
frame=2;
Shoot;
}


yield;
        frame++;
	frame2+=0.5;
	

if(frame2==180){
ExMove;
frame2=10;
}
    }


task ExMove { 
wait(120);
		SetMovePosition03(GetClipMinX+20, GetClipMinY+120+rand(-15, 15), 30, 2);
		wait(320);
		SetMovePosition03(GetClipMaxX-20, GetClipMinY+120+rand(-15, 15), 30, 2);
		

}
	// Movement functions for the boss to move towards the player.
function wait(w) { loop(w) { yield; } }	

task LifeGet{ AddLife(1); }

task Shoot{

		loop(1){
		SetMovePosition02(GetCommonData("secx"), GetCommonData("secy"), 60);
		wait(60);
		CreateShot01(GetX, GetY, 2, rand(0, 360), PURPLE22, 0);
}
yield;
}

    @DrawLoop {
		if(tilt == 0){
		SetGraphicAngle(0, 0, 0);
                DrawGraphic(GetX,GetY);
		}

    }
let v = 0;
    @Finalize {
        DeleteGraphic(ImgBoss);
    }
}
