#TouhouDanmakufu
#Title[TESTING]
#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 cardcall = GetCurrentScriptDirectory~"cardcall.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let background = GetCurrentScriptDirectory~"patchybackground.png";
	let t = 0;
	let a = 0;
	let v = 1;
    let frame = -120;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(600);
        SetTimer(50);
	DeleteSE("se\seUseSpellCard.wav");
        LoadSE(shot);
	LoadSE(cardcall);
	PlaySE(cardcall);
	LoadSE(bounce);
	LoadSE(shot2);
	SetShotAutoDeleteClip(200, 200, 200, 200);
	shotinit;
	SetScore(100000);
	SetEnemyMarker(true);
	LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        attack3;
	SetInvincibility(120);
	SetDamageRate(15, 40);
	LoadGraphic(background);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        CutIn(KOUMA, "Blue Sign "\""Sea of 53 Minutes"\", GetCurrentScriptDirectory~"cutin2.png", 0, 0, 240, 300);
        
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	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;

task attack1{
		loop{
			wait(60);
			attack2;
			
	}
	}

task attack2{
	v = 0;
	loop(10){
			wait(1);
			
			CreateShot01(GetX+v+cos(100), GetY, 2, GetAngleToPlayer, RED11, 20);
			CreateShot01(GetX-v+cos(100), GetY, 2, GetAngleToPlayer, RED11, 20);
			CreateShot01(GetX, GetY+v, 2, GetAngleToPlayer, RED11, 20);
			CreateShot01(GetX, GetY-v, 2, GetAngleToPlayer, RED11, 20);
			v+=20;
			}
v = 0;
}

task attack3 {
		let side = 1;
		loop {
			let r = 0;
			let a = rand(0,360);
			loop(30) {
				ascent(i in 0..4) { let a2 = a+i*360/2; ascent(j in 0..1) { ascent(k in 0..5) {
					CreateShot01(GetX+r*cos(a2*side), GetY+r*sin(a2*side/2), 9/27+j*3/8, (a2+r*7)*side+k*360/5, BLUE57, 30);
					CreateShot01(GetX+r*cos(a2*side), GetY+r*sin(a2*side), 9/27+j*3/8, (a2+r*7)*side+k*360/5, BLUE57, 30);
				} }  }
				r+=pi*5; a+=7;
			wait(3); } side*=-1;
			loop(3) {  wait(45); }
		}
	}

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


    @Finalize {
        DeleteGraphic(ImgBoss);
    }
}
