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


script_enemy_main {
let secx=0;
let secy=0;
	let attacking = 0;
	let a = 0;
    let ImgBoss = GetCurrentScriptDirectory~"nimono.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let angle = 0;
	let initialscore = GetScore;
	let timer = GetTimer;
	let time1 = GetCurrentScriptDirectory~"time1.wav";
	let time2 = GetCurrentScriptDirectory~"time2.wav";
	let charge = GetCurrentScriptDirectory~"charge.wav";
	let background = GetCurrentScriptDirectory~"BG2.png";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let explode = GetCurrentScriptDirectory~"explode.wav";
	let familiarspawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let tilt = 0;
	let yyy = 0;
	let alive = 1;
	let moo = 867;
	let xs = GetCommonData("secx");
	let ys = GetCommonData("secy");
	let xy = 0;
	let nyan = 1;
	let v = 90;
    let frame = -120;
	let frame2 = 0;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
	attack3;
	PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
        SetLife(2000);
	DeleteSE("se\seUseSpellCard.wav");
	SetCommonData("alive", true);
	CutIn(KOUMA, "Dynamic Duo "\""Danmaku Hail"\", GetCurrentScriptDirectory~"cutin2.png", 150, 40, 450, 300);
	SetScore(200000);
        SetTimer(60);
	MagicCircle(false);
        LoadSE(shot);

	LoadSE(time1);
	LoadSE(time2);
	LoadSE(bounce);
	LoadSE(shot2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	SetShotAutoDeleteClip(100, 200, 100, 100);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(25, 40);
        SetMovePosition02(GetPlayerX, GetClipMinY + 180, 120);
   
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
	LoadGraphic(background);
    
    }

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

task bullet(v, ang) {
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, GetX, GetY);
		ObjShot_SetGraphic(obj, rand(25, 33));
		Obj_SetAngle(obj, ang);
		ObjShot_SetDelay(obj, 10); wait(10);
		descent(i in 0..45) { Obj_SetSpeed(obj, v*i/45); wait(1); } wait(30);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		ascent(i in 0..45) { Obj_SetSpeed(obj, 1*i/(45-(i/10))); wait(1); }
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(1);
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		wait(20);
		
		
		Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
		ascent(i in 0..45) { PlaySE(shot2);Obj_SetSpeed(obj, 5*i/(45-(i/10))); wait(1); }
		
	}

task attack3 {	wait(20);
		let a = 0;
		loop {	
			wait(210); let t = 0;
			Concentration01(60);
	PlaySE(charge); wait(60); let attacking = 1; loop(40){ PlaySE(shot); ascent(i in 0..3) { bullet(1+i*5/4+t/20, a); } a+=20;  t++; wait(3); }
		let attacking = 0;
		}
	
	}
    @MainLoop {

	secx=GetCommonDataDefault("secx", 0);
	secy=GetCommonDataDefault("secy", 0);

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

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

	timer = GetTimer;

	if(frame == 180){
	
	}

	if(frame == 240){
	let t = 0;
	let w = 0;
	
frame=120;
}

	frame2++;
	if(frame2>120){	
	SetMovePosition03(GetPlayerX, GetClipMinY+120, 20, 0.5);
	}
	yield;
	
	
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	



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



    }







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



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

		if(attacking == 1){
		SetGraphicAngle(0, 0, 0);
		SetGraphicRect(300, 130, 600, 250);
                DrawGraphic(GetX,GetY);
		}


    }
let v = 0;
    @Finalize {
	if(GetMissCountInThisSpell == 0 && GetBombCountInThisSpell == 0){ AddScore(initialscore); PlaySE(GetCurrentScriptDirectory~"capture.wav"); }
	if(GetMissCountInThisSpell >0 || GetBombCountInThisSpell > 0){ PlaySE(GetCurrentScriptDirectory~"fail.wav"); }

        DeleteGraphic(ImgBoss);
    }
}
