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


script_enemy_main secant {
	let reset = 0;
    let ImgBoss = GetCurrentScriptDirectory~"secant.png";
	let background = GetCurrentScriptDirectory~"BG2.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let charge = GetCurrentScriptDirectory~"charge.wav";
	let familiarspawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let a = 0;
	let bb = 0;
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let bn = 0;
	let explode = GetCurrentScriptDirectory~"explode.wav";
	let tilt = 0;
	let radius = 100;
	let angle = GetAngleToPlayer;
	let i = 0;
	let alive = 1;
	let waffle = 1;
	let moo = 867;
	let xy = 0;
	let frame3=60;
	let nyan = 1;
	let v = 1;
    let frame = -90;
	let frame2 = 0;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
     @Initialize {
        SetLife(700);
	LoadGraphic(background);
	SetCommonData("alive", true);
	CutIn(KOUMA, "Role Reversal "\""Wolf-Eating Sheep"\", GetCurrentScriptDirectory~"cutin2.png", 150, 40, 450, 300);
	SetScore(200000);
        SetTimer(60);
	MagicCircle(false);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(shot2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	SetShotAutoDeleteClip(20, 20, 10, 10);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(50, 20);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
      
    }

    @MainLoop {
	bb++;

	if(frame2==1){
CreateEnemyFromFile(GetCurrentScriptDirectory~"Nimono3B.txt", GetCommonData("secx"), GetCommonData("secy"), 0, 0, 0);
}

	

	




	
	SetCollisionA(GetX, GetY, 16);
	SetCollisionB(GetX, GetY, 16);
	v = rand(-0.11, 0.11);

	SetCommonData("secy", GetY);
	SetCommonData("secx", GetX);
	if(frame == 40){
	let a = 0;
	PlaySE(shot2);
	let num = 8;
	loop(num){
	ascent(i in 0.22..80){
	

		CreateShotA(1, GetX, GetY, 0);
		

		SetShotDataA(1, 0, 3, 90+a, 0, 0, 3, ORANGE03);
		CreateShotA(2, 0, 0, 10);
		SetShotDataA(2, 0, 1, bb, 0, 0, 1, ORANGE57);
		AddShot(i*30, 1, 2, 0);
		
		


}
FireShot(1);
a+=360/num;
}
frame=0;
reset++;

}
	
if(reset==10){
	
	frame=-100;
	reset=0;
	SetMovePosition02(GetPlayerX, GetY, 70);
	}
	yield;
	frame3++;

	frame2++;
        frame++;
	
	
    }


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

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

task LifeGet{ AddLife(1); }

task dead{	

loop(1){
		PlaySE(explode);
		Explosion01(GetX, GetY, 50, 1, 60);
		SetDamageRate(0, 0);
		tilt=1;
		xy = 1;
		wait(360);
		alive=1;
		SetDamageRate(25, 40);
		AddLife(GetLife);
		
		Explosion01(GetX, GetY, 50, 1, 60);
		xy=0;
		tilt=0;
		frame3=-10;
		SetCommonData("alive", true);
		yield;
		
}
}

task fiyah{
	wait(20);
	PlaySE(shot2);
	loop(1){
	let a = 0;
	let num = 15;
	loop(num){
		CreateShot01(GetX, GetY, 2.5, a+GetAngleToPlayer, SP01, 10);
		a+=360/num;
		
	}
	}
}
	

   
	@BackGround{
   SetTexture(background);
	
   SetGraphicRect(0, 0, 512, 512);
	SetGraphicScale(1.2, 1.2);
   DrawGraphic(GetCenterX, GetCenterY);
	
  
}

    @DrawLoop {
		SetTexture(ImgBoss);
		if(tilt == 0){
		SetTexture(ImgBoss);
		SetGraphicAngle(0, 0, 0);
		SetGraphicRect(1, 1, 128, 128);
                DrawGraphic(GetX,GetY);
		}

		if(tilt == 1){
		SetTexture(ImgBoss);
		SetGraphicAngle(0, 0, 90);
		SetGraphicRect(1, 1, 128, 128);
                DrawGraphic(GetX,GetY);
		}

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