

script_enemy_main {
    let ImgBoss = GetCurrentScriptDirectory~"nimono.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let background = GetCurrentScriptDirectory~"BG2.png";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let angle = 0;
	let time1 = GetCurrentScriptDirectory~"time1.wav";
	let initialscore = GetScore;
	let time2 = GetCurrentScriptDirectory~"time2.wav";
	let timer = 0;
	let charge = GetCurrentScriptDirectory~"charge.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let explode = GetCurrentScriptDirectory~"explode.wav";
	let familiarspawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let tilt = 0;
	let alive = 1;
	let blargh = 0;
	let moo = 867;
	let xs = GetCommonData("secx");
	let ys = GetCommonData("secy");
	let xy = 0;
	let nyan = 1;
	let v = 90;
    let frame = -120;
	let frame2 = 0;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
	SetCommonData("nimono", true);
        SetLife(700);
		PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
	DeleteSE("se\seUseSpellCard.wav");
	SetCommonData("nimono", true);
	CutIn(KOUMA, "Role Reversal "\""Wolf-Eating Sheep"\", GetCurrentScriptDirectory~"cutin2.png", 150, 40, 450, 300);
	SetScore(200000);
	LoadGraphic(background);
        SetTimer(60);
	MagicCircle(false);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(time1);
	LoadSE(time2);
	LoadSE(shot2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	SetShotAutoDeleteClip(100, 200, 100, 100);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(25, 40);
        SetMovePosition02(GetCenterX, GetClipMinY + 140, 120);
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
      
    }

    @MainLoop {
	frame++;

	

	if(GetTimer!=timer && (GetTimer < 10 && GetTimer>3)){
	PlaySE(time1);
	}

	if(GetTimer!=timer && GetTimer < 4){
	PlaySE(time2);
	}

	timer = GetTimer;

	if(GetCommonData("nimono")==false){
	SetCollisionA(GetX, GetY, 0);
	SetCollisionB(GetX, GetY, 0);
	}

	SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	if(GetLife<250){
	SetCommonData("nimono", false);
		blargh=1;
		Explode;
	}

if(GetLife>251){
	SetCommonData("nimono", true);
		
	}

if(frame>70){
frame=-10;
}

if(blargh==0){

	if(frame == 60){
	ExMove;
	let a = -1;
	let num = 15;
	loop(num){
		PlaySE(shot);
		CreateShot01(GetX, GetY, 3-a, GetAngleToPlayer, GREEN21, 0);
		
		a+=1/8;
		angle+=360/num;
frame=-60;
}
}

}

	frame2++;
	yield;
	
	
        
	






    }

sub ExMove { ExMove_(GetCenterY-75, 30, rand(15, 30)); }
function ExMove_(height, ud, length) {
	
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length, rand(height+20 - 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.


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



task Explode{	
SetCommonData("nimono", false);
loop(1){	SetCollisionA(GetX, GetY, 0);
		SetCollisionB(GetX, GetY, 0);
		AddLife(500);
		SetMovePosition02(GetClipMinX, GetY, 1000);
		PlaySE(explode);
		Explosion01(GetX, GetY, 50, 1, 60);
		SetDamageRate(0, 0);
		tilt=1;
		xy = 1;
		yield;
		
}
}
   
	@BackGround{
   SetTexture(background);
	
   SetGraphicRect(0, 0, 512, 512);
	SetGraphicScale(1.2, 1.2);
   DrawGraphic(GetCenterX, GetCenterY);
	
  
}

    @DrawLoop {
		SetTexture(ImgBoss);
		if(tilt == 0){
		SetGraphicAngle(0, 0, 0);
		SetGraphicRect(1, 1, 128, 128);
                DrawGraphic(GetX,GetY);
		}

    }
let v = 0;
    @Finalize {
	if(GetMissCountInThisSpell == 0 && GetBombCountInThisSpell == 0){ AddScore(initialscore); PlaySE(GetCurrentScriptDirectory~"capture.wav"); }
	if(GetMissCountInThisSpell >0 || GetBombCountInThisSpell > 0){ PlaySE(GetCurrentScriptDirectory~"fail.wav"); }

        DeleteGraphic(ImgBoss);
    }
}
