#TouhouDanmakufu
#Title[Khayoshia's last nonspell -Hard-]
#Text[Moo]
#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~"KhayoshiaSprite.png";
	let spark = GetCurrentScriptDirectory~"spark.wav";
	let t = 0;
	let v = 0.05;
	let a = 0;
	let w = 0;
	let num = 80;
	let b = 0;
	let z = 0;
	let spin = 0;
    let frame = 180;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(3000);
        SetTimer(60);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(declare);
	LoadSE(spark);
	
	LoadSE(shot2);
	SetShotAutoDeleteClip(100, 200, 100, 100);
	shotinit;
	PlaySE(declare);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(100, 75);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 10);
        
        LoadGraphic(ImgBoss);
	SetTexture(ImgBoss);
	LoadGraphic(background);
    
    }

    @MainLoop {
	SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 32);
	Shot;
	v = rand_int(1, 5);
	Shot;

	if(OnPlayerMissed){
	frame=240;
	}

if(frame == 281){
ExMove;
let a = rand(1, 2);
let num = 50;
	loop(num){
	PlaySE(shot);
		CreateShotA(1, GetX, GetY+a, 60);
		SetShotDataA(1, 0, -1, GetAngleToPlayer+a*2, 0, 0.2, -1, GREEN32);
		SetShotDataA(1, 30, -1, GetAngleToPlayer+a*2, 0, 0.2, -1, ORANGE01);

		CreateShotA(2, GetX, GetY-a, 60);
		SetShotDataA(2, 0, -2, GetAngleToPlayer+a*2, 0, 0.2, -2, GREEN32);
		SetShotDataA(2, 30, -1, GetAngleToPlayer+a*2, 0, 0.2, -1, ORANGE01);
		a+=5;
		

FireShot(2);
FireShot(1);
}
}

if(frame == 281){
let a = 0;
let num = 50;
	loop(num){
	PlaySE(shot);
		CreateShotA(1, GetX+a, GetY, 20);
		SetShotDataA(1, 0, -2, GetAngleToPlayer+a*2, 0, 0.2, -2, GREEN32);
		SetShotDataA(1, 30, -2, GetAngleToPlayer+a*2, 0, 0.2, -2, RED02);
		SetShotDataA(1, 60, -2, GetAngleToPlayer+a*2, 0, 0.2, -2, YELLOW01);
		CreateShotA(2, GetX-a, GetY, 20);
		SetShotDataA(2, 0, -2, GetAngleToPlayer+a*2, 0, 0.2, -2, GREEN32);
		SetShotDataA(2, 30, -2, GetAngleToPlayer+a*2, 0, 0.2, -2, RED02);
		SetShotDataA(2, 60, -2, GetAngleToPlayer+a*2, 0, 0.2, -2, YELLOW01);
		a+=5;
		

FireShot(2);
FireShot(1);
}
}
if(frame == 282){
	frame=-0;
}

if(frame == 121 || frame == 140 || frame == 160 || frame == 180 || frame == 200){
if(v == 1){
v = -1
}

if(v == -1){
v=1;
}

}

  frame++;
	v+=2;
}
function Wait(w){loop(w){yield;}}


task Shot{

	w+=10;

	CreateShot01(rand(GetClipMaxX, GetClipMinX), GetClipMinY-10, rand(1.5, 2), w*10, WHITE12, 20);
		CreateShot01(rand(GetClipMaxX, GetClipMinX), GetClipMinY-10, rand(1.5, 2), w*10, YELLOW12, 20);
	
}





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.

  @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, 1024, 1024);
	SetGraphicScale(1, 1);
   DrawGraphic(GetCenterX, GetCenterY);
	SetGraphicAngle(0, 0, b);
  y+=5;
}
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);
    }
}
