#TouhouDanmakufu
#Title[Secant ideas]
#Text[Everyone sees.]
#Player[FREE]

#BackGround[User(.\bg.png, 0, 0)]

#ScriptVersion[2]

// Difficulty levels: Easy - Normal - Extra - Hard - Another - Lunatic - Phantasm - Roadkiller - mewKyuu

script_enemy_main {
	#include_function ".\include.dnh"
	task TMain {
		SetLife(830); CreateLifebar(2, 1); dmgratemax=15; dmgrateup=1; 
		SetBossAnimation(BossMode_MOVE, 45); SetMovePosition03(GetCenterX, GetCenterY-175/4, 15, 9); waitInv(60);
		SetBossAnimation(BossMode_SPELL, 120); CutIn(KOUMA, "Forlorn Junk Heap "\""Danmaku of a Futuristic World"\", cutcut, 0, 0, 240, 300);
		SetScore(1000000); declare;
waitInv(120);
		
		attack2;
		
		attack4;
		attack5;
		
	}

task declare{
	wait(10);
	PlaySE(seCard1);
	}
	
	task attack2 {
		let a = 0; let b = 0;
		loop {  PlaySE(shot);
			
			ascent(i in 0..12) { CreateShot01(GetX, GetY, 1.9, a+i*360/11, ORANGE57, 0); }
			a-=10; a%=360; b+=pi*3/2; b%=360; wait(10);
		}
	}

	task attack5 {
		loop { PlaySE(bounce);
			let x = rand_int(GetClipMinX, GetClipMaxY); let a = 90+rand(-3, 3);
			ascent(i in 0..3) { CreateShot01(x, GetClipMinY, 3-i/5, a, GREEN03, 30); }
			wait(45);
		}
	}

	task move{
	loop{
	wait(180);
	ExMove;
	}
	}
	task attack4 {
		let ang = 2; let n = 3; let side = 1;
		loop {	PlaySE(shot2);
			ascent(j in 0..2) { ascent(i in 0..n) { let x = GetX+75*cos(-90+ang*side+i*360/n); let y = GetY+25*sin(-90+ang*side+i*360/n); CreateShotA(0, x, y, 5);
			SetShotDataA(0, 0, (((GetClipMinY-y)^2+(GetCenterX-x)^2)^0.5)/15, atan2(GetClipMinY-y,GetCenterX-x), 0, 0, 0, [WHITE50,WHITE01][i<=3&&j==0]);
			SetShotDataA(0, 15, 3, -90+ang*side+i*360/n, 2*side*cos(ang*side+i*360/n), 0, 0, SP09);
			SetShotDataA(0, 45, 3, NULL, -1/3*side*cos(ang*side+i*360/n), -1/10, 2, NULL);
			FireShot(0); } side*=-1; } ang+=18/pi; ang%=360; wait(3);
		}
	}
	}
sub ExMove { wait(120); ExMove_(GetCenterY-100, 30, rand(15, 30)); }
function ExMove_(height, ud, length) {
	
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 5, 11);
		} else {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 11);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 11);
		} else {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 5, 11);
		}
	}
}
	// Movement functions for the boss to move towards the player.