#TouhouDanmakufu
#Title[Khayoshia's fourth spell -Hard-]
#Text[Who is stalking who?]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User(.\KhaBG.png, 0, 0)]
#BGM[.\BGM.mp3]
script_enemy_main {
    let ImgBoss = GetCurrentScriptDirectory~"KhayoshiaSprite.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let laser = GetCurrentScriptDirectory~"laser.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let declare = GetCurrentScriptDirectory~"cardcall.wav";
	let background = GetCurrentScriptDirectory~"KhaBG2.png";
	let spark = GetCurrentScriptDirectory~"spark.wav";
	let shot7 = GetCurrentScriptDirectory~"shot7.wav";
	let t = 0;
	let v = 255;
	let a = 0;
	let frame2 = 0;
	let angle = GetAngleToPlayer;
	let angleAcc = 0;
	let nu = 0;
	let pie = 1;
	let radius = 0;
	let w = -2;
	let num = 20;
	let b = 0;
	let blu = 1;
	let z = 0;
	let spin = 0;
    let frame = -60;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
Hitbox;
        SetLife(1500);
        SetTimer(58);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(shot7);
	LoadSE(declare);
	LoadSE(spark);
	SetScore(6000000);
	LoadSE(shot2);
	SetShotAutoDeleteClip(150, 200, 150, 150);
	shotinit;
	PlaySE(declare);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(50, 10);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 10);
        CutIn(KOUMA, "Desperado"\""Night Stalker"\", GetCurrentScriptDirectory~"KhayoshiaSprite2.png", 40, 10, 256, 256);
        LoadGraphic(ImgBoss);
	SetTexture(ImgBoss);
	LoadGraphic(background);
    	

    }

	@MainLoop{
	if(GetTimer>57){


		
}

		SetCollisionA(GetX, GetY, 32);
		SetCollisionA(GetCenterX, GetCenterY, 32);
		SetCollisionB(GetX, GetY, 30);
		frame++;
		yield;
		y--;

	if(GetTimer<57){
		CreateShot01(GetX, GetY, 3, rand(0, 5)+atan2(GetCenterY-GetY,GetCenterX-GetX), RED12, 0);
		}



if(GetTimer==40 && blu==1 || GetEnemyLife<1000 && blu==1){
		pie = 0;
}



if(GetEnemyLife<750 || GetTimer<30 && frame == 120){
SetDamageRate(20, 5);
let a = 0;
let num = 20;
loop(num){
CreateShot01(GetClipMinX, GetClipMinY, 1, GetAngleToPlayer+a, PURPLE12, 20);
CreateShot01(GetClipMinX, GetClipMaxY, 1, GetAngleToPlayer+a, PURPLE12, 20);
CreateShot01(GetClipMaxX, GetClipMinY, 1, GetAngleToPlayer+a, PURPLE12, 20);
CreateShot01(GetClipMaxX, GetClipMaxY, 1, GetAngleToPlayer+a, PURPLE12, 20);
a+=360/num;
}
}


if(pie==0){
	if(frame == 120 || frame == 360 || frame == 240 || frame == 480){
			let num = 20;
			let a = 0;
			loop(num){
			CreateShot01(GetCenterX, GetCenterY, 2, GetAngleToPlayer+a, PURPLE12, 20);
			a+=360/num;
		}
		}
		}

if(frame == 120){
		let num = 30;
		loop(num){
			CreateShot01(GetX, GetY, 2.5, GetAngleToPlayer+a, RED57, 0);
			a+=360/num;
			}

		SetMovePosition02(GetClipMinX+40, GetClipMinY+40, 60);
	PlaySE(shot);

}

if(frame == 240){
		loop(num){
			CreateShot01(GetX, GetY, 2.5, GetAngleToPlayer+a, RED57, 0);
			a+=360/num;
			}
		SetMovePosition02(GetClipMaxX-40, GetClipMinY+40,60);
		
PlaySE(shot);
}

if(frame == 360){
		loop(num){
			CreateShot01(GetX, GetY, 2.5, GetAngleToPlayer+a, RED57, 0);
			a+=360/num;
			}
		SetMovePosition02(GetClipMaxX-40, GetClipMaxY-40, 60);
	PlaySE(shot);

}

if(frame == 480){
		loop(num){
			CreateShot01(GetX, GetY, 2.5, GetAngleToPlayer+a, RED57, 0);
			a+=360/num;
			}
		SetMovePosition02(GetClipMinX+40, GetClipMaxY-40, 60);
	PlaySE(shot);
}

if(frame == 600){
frame=119;
}
}


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



sub ExMove { ExMove_(GetCenterY-100, 30, rand(15, 30)); }
function ExMove_(height, ud, length) {
	
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length, GetY, 5, 11);
		} else {
			SetMovePosition03(GetX - length, GetY, 5, 11);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length, GetY, 5, 11);
		} else {
			SetMovePosition03(GetX + length, GetY, 5, 11);
		}
	}
}
	// Movement functions for the boss to move towards the player.


task Hitbox{
		let obj_id = Obj_Create(OBJ_SHOT); 
		Obj_SetPosition(obj_id, GetCenterX, GetCenterY);
		ObjShot_SetGraphic(obj_id, PURPLE03);
		Obj_SetSpeed(obj_id, 0); Obj_SetAngle(obj_id, 0); ObjShot_SetDelay(obj_id, 600000);
		ObjShot_SetBombResist(obj_id, true);
}

  @DrawLoop {
		
		SetTexture(ImgBoss);
                SetRenderState(ALPHA);
		SetGraphicRect(1, 1, 512, 512);
                SetAlpha(255);  
                SetGraphicScale(0.2,0.2);
                SetGraphicAngle(0,0,0);
		DrawGraphic(GetEnemyX,GetEnemyY);
               	
                      
 
               
    }
let y = 0;
@BackGround{
   SetTexture(background);
	
   SetGraphicRect(0, 0, 1066, 1031);
	SetGraphicScale(1, 1);
	SetGraphicAngle(0, 0, y);
   DrawGraphic(GetCenterX, GetCenterY);
	
  
}
let v = 0;
    @Finalize {
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
	CreateItem(ITEM_SCORE,GetX + rand(-20,20),GetY + rand(-20,20));
        DeleteGraphic(ImgBoss);
    }
}
