#TouhouDanmakufu#TouhouDanmakufu
#Title[Fifth Spell]
#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 timer = GetTimer;
	let initialscore = GetScore;
	let background = GetCurrentScriptDirectory~"BG2.png";
	let a = 0;
	let we = 50;
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let angle = 0;
	let beep = GetCurrentScriptDirectory~"beep.wav";
	let charge = GetCurrentScriptDirectory~"charge.wav";
	let laser2 = GetCurrentScriptDirectory~"laser2.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let explode = GetCurrentScriptDirectory~"explode.wav";
	let familiarspawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let tilt = 0;
	let frame3 = 0;
	let b = 2;
	let thrown= 0;
	let alive = 1;
	let data = 0;
	let moo = 867;
	let x = 0;
	let y = 0;
	let xs = GetCommonData("secx");
	let w = -180;
	let ys = GetCommonData("secy");
	let xy = 0;
	let nyan = 1;
	let v = 90;
	let hihi = 1;
    let frame = -120;
	let frame2 = 0;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
		PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
        SetLife(2700);
	DeleteSE("se\seUseSpellCard.wav");
	LoadGraphic(background);
	SetCommonData("attack", 0);
	SetCommonData("alive", true);
	CutIn(KOUMA, "Cooperation "\""Wildcard Danmaku"\", GetCurrentScriptDirectory~"cutin2.png", 150, 40, 450, 300);
	SetScore(200000);
        SetTimer(145);
	SetEffectForZeroLife(60, 155, 3);
	MagicCircle(false);
	LoadSE(laser2);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(beep);
	LoadSE(shot2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	
	SetShotAutoDeleteClip(30, 30, 30, 30);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(25, 0);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
      
    }

    @MainLoop {
	frame++;
	data = GetCommonData("attack");
	if(GetCommonDataDefault("toggling", false)==false){

	frame3++;

	}

	if(GetCommonDataDefault("toggling", false)==true){

	

	frame3=-60;

	}
	w+=0.5;
	let xs = GetCommonData("secx");
	let ys = GetCommonData("secy");
	
	

	if(frame == 60){
	PlaySE(bounce);
	let cx = rand(GetClipMinX, GetClipMaxX);
	we = rand(-10, 10);
	CreateShot01(cx, GetClipMinY, 2.9, 90+we, BLUE03, 30);
	CreateShot01(cx, GetClipMinY, 2.7, 90+we, BLUE03, 30);
	CreateShot01(cx, GetClipMinY, 2.5, 90+we, BLUE03, 30);
	frame=-30;
	}


	if(frame3==500){
	Toggle;
	frame3=rand_int(-200, -300);
	}

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



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



    }

task Toggle{
	SetDamageRate(0, 0);
	SetCommonData("toggling", true);
	SetMovePosition02(GetX, GetClipMinY-50, 30);
	hihi=0;
	wait(30);
	PlaySE(beep);
	wait(120);
	hihi = 1;
	SetDamageRate(25, 0);
	SetCommonData("attack", data+1);
	if(GetCommonData("attack")==6){
	SetCommonData("attack", 0);
	}

	SetMovePosition02(GetCenterX, GetClipMinY+120, 30);
		SetCommonData("toggling", false);
	
	
}



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

task LifeGet{ AddLife(1); }


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

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

    }
let v = 0;
    @Finalize {
	
	if(GetMissCountInThisSpell == 0 && GetBombCountInThisSpell == 0){ AddScore(initialscore); PlaySE(GetCurrentScriptDirectory~"capture.wav"); }
	if(Continued){FadeOutMusic(GetCurrentScriptDirectory~"BGM.mp3", 100); PlaySE(GetCurrentScriptDirectory~"failhard.wav"); }

	PlaySE(explode);
        DeleteGraphic(ImgBoss);
    }
}
