#TouhouDanmakufu
#Title[Khayoshia's second spell -Normal-]
#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~"KhaBG2.png";
	let spark = GetCurrentScriptDirectory~"spark.wav";
	let shot7 = GetCurrentScriptDirectory~"shot7.wav";
	let t = 0;
	let v = 0.05;
	let a = 0;
	let frame2 = 0;
	let angle = 50;
	let angleAcc = 0;
	let radius = 50;
	let w = 0;
	let num = 80;
	let b = 0;
	let z = 0;
	let spin = 0;
    let frame = -60;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(900);
        SetTimer(60);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(shot7);
	LoadSE(declare);
	LoadSE(spark);
	SetScore(6000000);
	LoadSE(shot2);
	SetShotAutoDeleteClip(100, 200, 100, 100);
	shotinit;
	PlaySE(declare);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(30, 21);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 10);
        CutIn(KOUMA, "Organized Chaos "\""Fickle Danmaku"\", GetCurrentScriptDirectory~"KhayoshiaSprite2.png", 40, 10, 256, 256);
        LoadGraphic(ImgBoss);
	SetTexture(ImgBoss);
	LoadGraphic(background);
    
    }

    @MainLoop {
	SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 32);
	
	if(GetPlayerMoveState==MOVE_SLOW){
	if(frame == 60){
		ExMove;
		let a = 0;
	let num = 25;
	loop(num){
		PlaySE(shot);
		CreateShotA(1, GetClipMinX, GetClipMaxY, 30);
		SetShotDataA(1, 0, 0, GetAngleToPlayer+a, 0.1, 0.2, 1, PURPLE03);
		SetShotDataA(1, 20, 0, GetAngleToPlayer+a, 0.1, 0.2, 1, PURPLE02);
		SetShotDataA(1, 40, 0, GetAngleToPlayer+a, 0.1, 0.2, 1, PURPLE01);
		SetShotDataA(1, 60, 0, GetAngleToPlayer+a, 0.1, 0.2, 1, PURPLE58);
		CreateShotA(2, GetClipMaxX, GetClipMaxY, 30);
		SetShotDataA(2, 0, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE02);
		SetShotDataA(2, 20, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE01);
		SetShotDataA(2, 40, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE58);
		SetShotDataA(2, 60, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE03);
		CreateShotA(3, GetClipMinX, GetClipMinY, 30);
		SetShotDataA(3, 0, 0, GetAngleToPlayer+a, -0.5, 0.2, 3, PURPLE01);
		SetShotDataA(3, 20, 0, GetAngleToPlayer+a, -0.5, 0.2, 3, PURPLE58);
		SetShotDataA(3, 40, 0, GetAngleToPlayer+a, -0.5, 0.2, 3, PURPLE03);
		SetShotDataA(3, 60, 0, GetAngleToPlayer+a, -0.5, 0.2, 3, PURPLE02);
		CreateShotA(4, GetClipMaxX, GetClipMinY, 30);
		SetShotDataA(4, 0, 0, GetAngleToPlayer+a, 0.5, 0.2, 3, PURPLE58);
		SetShotDataA(4, 20, 0, GetAngleToPlayer+a, 0.5, 0.2, 3, PURPLE03);
		SetShotDataA(4, 40, 0, GetAngleToPlayer+a, 0.5, 0.2, 3, PURPLE02);
		SetShotDataA(4, 60, 0, GetAngleToPlayer+a, 0.2, 0.2, 3, PURPLE01);
		a+=360/num;

FireShot(1);
FireShot(2);
FireShot(3);
FireShot(4);
y++;
	}

}
}

if(GetPlayerMoveState==MOVE_NORMAL){
	if(frame == 60){
		let a = 0;
	let num = 25;
	loop(num){
		PlaySE(shot);
		CreateShotA(1, GetClipMinX, GetClipMaxY, 30);
		SetShotDataA(1, 0, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE03);
		SetShotDataA(1, 20, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE02);
		SetShotDataA(1, 40, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE01);
		SetShotDataA(1, 60, 0, GetAngleToPlayer+a, 0.1, 0.2, 2, PURPLE59);
		CreateShotA(2, GetClipMaxX, GetClipMaxY, 30);
		SetShotDataA(2, 0, 0, GetAngleToPlayer+a, 0.1, 0.2, 3, PURPLE02);
		SetShotDataA(2, 20, 0, GetAngleToPlayer+a, 0.1, 0.2, 3, PURPLE01);
		SetShotDataA(2, 40, 0, GetAngleToPlayer+a, 0.1, 0.2, 3, PURPLE58);
		SetShotDataA(2, 60, 0, GetAngleToPlayer+a, 0.1, 0.2, 3, PURPLE03);
		CreateShotA(3, GetClipMinX, GetClipMinY, 30);
		SetShotDataA(3, 0, 0, GetAngleToPlayer+a, -0.3, 0.2, 2, PURPLE01);
		SetShotDataA(3, 20, 0, GetAngleToPlayer+a, -0.3, 0.2, 2, PURPLE58);
		SetShotDataA(3, 40, 0, GetAngleToPlayer+a, -0.3, 0.2, 2, PURPLE03);
		SetShotDataA(3, 60, 0, GetAngleToPlayer+a, -0.1, 0.2, 2, PURPLE02);
		CreateShotA(4, GetClipMaxX, GetClipMinY, 30);
		SetShotDataA(4, 0, 0, GetAngleToPlayer+a, 0.1, 0.2, 1, PURPLE58);
		SetShotDataA(4, 20, 0, GetAngleToPlayer+a, 0.1, 0.2, 1, PURPLE03);
		SetShotDataA(4, 40, 0, GetAngleToPlayer+a, 0.1, 0.2, 1, PURPLE02);
		SetShotDataA(4, 60, 0, GetAngleToPlayer+a, 0.2, 0.2, 1, PURPLE01);
		a+=360/num;

FireShot(1);
FireShot(2);
FireShot(3);
FireShot(4);
y++;
	}

}
}

if(frame==110||frame==130||frame==150){
		y+=30
}
  frame++;
	v+=2;
	yield;

if(frame == 151){
	frame=30;
}
}
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.

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