#TouhouDanmakufu
#Title[Secant nonspell 4]
#Text[SECANTCOSINE!]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User(.\moon.png, 0, 0)]
script_enemy_main {
    let ImgBoss = GetCurrentScriptDirectory~"sprite.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let t = 0;
	let a = 0;
	let v = 1;
    let frame = -120;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(3000);
        SetTimer(40);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(shot2);
	SetShotAutoDeleteClip(100, 200, 100, 100);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(100, 40);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        SetGraphicRect(1, 1, 128, 128);
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);

if(frame == 49 || frame == 45 || frame == 41 || frame == 37 || frame == 33 || frame == 29 || frame == 25 || frame == 21 || frame == 17 || frame== 13 || frame == 9 || frame == 5 || frame ==1 || frame==53 || frame==57 || frame==61 || frame==65 || frame == 69 || frame == 73 || frame == 77 || frame == 81 || frame == 85 || frame == 89 || frame == 93 || frame == 97 || frame == 101 || frame == 105 || frame == 109 || frame == 113 || frame == 117 || frame == 121 || frame == 125 || frame == 129){
	let a   = 0;
        let num = 12; //Change this number here to specify the number of bullets in the ring.
	
	loop(num)
            {	
		PlaySE(shot2);
		CreateShotA(1, GetX, GetY, 0);
		SetShotDataA(1, 0, -1, a+90+v, 0.01, 0.3, 2.5, SP09);
		a +=360/num;
FireShot(1);
}
        }


if(frame == 55){
	
	let a   = 0;
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
		
            CreateShot01(GetX, GetY, 2, a+GetAngleToPlayer, BLUE57, 0);
	    CreateShot01(GetX, GetY, 2.5, a+GetAngleToPlayer, BLUE57, 5);
	    CreateShot01(GetX, GetY, 3, a+GetAngleToPlayer, BLUE57, 7);
	    CreateShot01(GetX, GetY, 3.5, a+GetAngleToPlayer, BLUE57, 7);
            a += 360/num;
	PlaySE(bounce);
	
		

}

}

if(frame == 109){
frame2=rand_int(1, 2);
}
if(frame == 110){
	
	ExMove;
	let a   = 0;
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
		
            CreateShot01(GetX, GetY, 2, a+GetAngleToPlayer, BLUE57, 0);
	    CreateShot01(GetX, GetY, 2.5, a+GetAngleToPlayer, BLUE57, 5);
	    CreateShot01(GetX, GetY, 3, a+GetAngleToPlayer, BLUE57, 7);
	    CreateShot01(GetX, GetY, 3.5, a+GetAngleToPlayer, BLUE57, 7);
            a += 360/num;
	PlaySE(bounce);
	frame=0;
	
		

}

}










if(frame2==1){
       v+=3;
	}
if(frame2==2){
	v+=-3;
	}
        frame++;
	t+=-0.05;
	
    }

sub ExMove { ExMove_(GetCenterY-100, 30, rand(15, 30)); }
function ExMove_(height, ud, length) {
	
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 5, 11);
		} else {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 11);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 11);
		} else {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 5, 11);
		}
	}
}
	// Movement functions for the boss to move towards the player.


    @DrawLoop {

                DrawGraphic(GetX,GetY);
    }
let v = 0;
    @Finalize {
        DeleteGraphic(ImgBoss);
    }
}
