#TouhouDanmakufu
#Title[Secant Spell 5]
#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 frame3 = -120;
	let background = GetCurrentScriptDirectory~"patchybackground.png";
	let t = 0;
	let a = 0;
	let m = 0;
	let v = 1;
    let frame = -130;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(875);
        SetTimer(60);
        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, "Forlorn Junk Heap"\""Danmaku from a Futuristic World"\", GetCurrentScriptDirectory~"cutin2.png", 0, 0, 240, 300);
        
    }

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

	if(frame==60 || frame==120){
	let a   = 0;
        let num = 40; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
		PlaySE(bounce);
            CreateShot01(GetX, GetY, 2, a+GetAngleToPlayer, ORANGE57, 0);
		CreateShot01(GetX, GetY, 2.5, a+GetAngleToPlayer, ORANGE57, 3);
		CreateShot01(GetX, GetY, 3, a+GetAngleToPlayer, ORANGE57, 6);
            a += 360/num;
	
		

}

}
	
	if(frame == 60 || frame == 120){
	let a   = rand_int(20, 0);
        let num = 55; //Change this number here to specify the number of bullets in the ring.
	
	loop(num)
            {	
		PlaySE(shot);
		CreateShotA(1, GetX, GetY, 0);
		SetShotDataA(1, 0, -3.1, a+GetAngleToPlayer, 0.3, 0.04, 2.2, SP10);
		a +=360/num;
FireShot(1);
}
        }

	
if(frame == 50 || frame==53 || frame==56 || frame==59 || frame==62 || frame == 65 || frame == 68 || frame == 71 || frame == 74 || frame == 77 || frame == 80 || frame == 83 || frame == 86 || frame == 89 || frame == 92 || frame == 95 || frame == 98 || frame == 101 || frame == 104 || frame == 107 || frame == 110){
	let a   = 0;
        let num = 15; //Change this number here to specify the number of bullets in the ring.
	PlaySE(shot2);
	loop(num)
            {	
		CreateShotA(1, GetX, GetY, 0);
		SetShotDataA(1, 0, 7, a+90+v, -0.07, -0.9, 2.25, GREEN56);
		a +=360/num;
FireShot(1);
}
        }
	
if(frame==121){
SetMovePosition02(GetPlayerX, GetY, 20);
frame=0;
}
if(frame>40){
       v+=2;
	}
if(frame<40){
	v+=-2;
	}
        frame++;
	frame3++;
	t+=-0.05;
	yield;
	
    }

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

task CreateShotReflect(x, y, v, ang, graphic, delay) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = 25; let  counter = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); Obj_SetAngle(obj_id, ang); ObjShot_SetDelay(obj_id, delay);
		ObjShot_SetBombResist(obj_id, false);
		while(!Obj_BeDeleted(obj_id)) {
			if(counter <= 1) {
				
				
				if(Obj_GetY(obj_id) < GetClipMinY-border) { Obj_SetY(obj_id, 2*(GetClipMinY-border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
				//else if(Obj_GetY(obj_id) > GetClipMaxY+border) { Obj_SetY(obj_id, 2*(GetClipMaxY+border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
			}
			yield;
		}
	}


   @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);
    }
}
