#TouhouDanmakufu
#Title[Secant Spell 3]
#Text[SECANTCOSINE!]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User(.\patchybackground.png, 0, 3)]
script_enemy_main {
    let ImgBoss = GetCurrentScriptDirectory~"sprite.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let shot4 = GetCurrentScriptDirectory~"shot4.wav";
	let radius = 200;
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let cardcall = GetCurrentScriptDirectory~"cardcall.wav";
	let angle = GetAngleToPlayer;
	
	let background = GetCurrentScriptDirectory~"patchybackground.png";
	let t = 0;
	let a = 0;
	let v = 1;
    let frame = -130;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(550);
        SetTimer(50);
        LoadSE(shot);
	LoadSE(shot4);
	LoadSE(bounce);
	LoadSE(shot2);
	PlaySE(cardcall);
	SetShotAutoDeleteClip(200, 200, 200, 200);
	shotinit;
	SetScore(100000);
	DeleteSE("se\seUseSpellCard.wav");
	SetEnemyMarker(true);
	LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        
	SetInvincibility(120);
	SetDamageRate(15, 40);
	LoadGraphic(background);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        CutIn(KOUMA, "Detection "\""Deadly Quarantine"\", GetCurrentScriptDirectory~"cutin2.png", 0, 0, 240, 300);
        
    }

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


	if(frame == 60){
	let a   = 0;
	PlaySE(shot4);
        let num = 14; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetPlayerX+radius*cos(angle), GetPlayerY+radius*sin(angle), -1, angle, SP08, 15);
            angle += 360/num;

}

}
if(frame == 120){
	ExMove;
	}
if(frame == 0 || frame == -30 || frame == 60 || frame == 90 || frame == 30){

let a   = rand(0, 100);
        let num = 17; //Change this number here to specify the number of bullets in the ring.
	PlaySE(shot);
	loop(num)
            {	
		CreateShotA(1, GetX, GetY, 0);
		SetShotDataA(1, 0, 0, a+90, 0.002, 0.35, 1.5, ORANGE57);
		a +=360/num;
FireShot(1);
}
        }




if(frame == 121){
frame=-31;
}












if(frame2==1){
       v+=1.3;
	}
if(frame2==2){
	v+=-1.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 {
		SetTexture(ImgBoss);
                SetRenderState(ALPHA);
		SetGraphicRect(1, 1, 128, 128);
                SetAlpha(255);  
                SetGraphicScale(1,1);
                SetGraphicAngle(0,0,0);
		DrawGraphic(GetEnemyX,GetEnemyY);
               
                      
 
               
    }
let y = 0;
@BackGround{
   SetTexture(background);
   SetGraphicRect(0, 0-y, 512, 512-y);
   DrawGraphic(GetCenterX, GetCenterY);
  y+=5;
}

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