#TouhouDanmakufu
#Title[Marisa Midboss Spell]
#Text[Moo]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User(.\moon.png, 0, 0)]
#BGM[.\bgm2.mp3]
script_enemy_main {
    let ImgBoss = GetCurrentScriptDirectory~"MarisaSprites.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let declare = GetCurrentScriptDirectory~"cardcall.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let background = GetCurrentScriptDirectory~"MariBG.png";
	let spawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let t = 0;
	let blu = 1;
	let a = 0;
	let v = 1;
	let angle = 0;
	let angle2 = atan2(GetY-GetEnemyY, GetX-GetEnemyX);
	let radius = 100;
	let z = 0;
    let frame = -60;
	
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(5000);
        SetTimer(60);
	
	LoadSE(spawn);
	ExMove1;
	LoadGraphic(background);
	LoadSE(declare);
	PlaySE(declare);
        LoadSE(shot);
	LoadSE(bounce);
	CutIn(KOUMA, "Modified Ancient Relic "\""Orreries Sun"\", GetCurrentScriptDirectory~"marisa.png", 0, 0, 128, 256);
	LoadSE(shot2);
	SetScore(202020);
	SetShotAutoDeleteClip(100, 100, 100, 100);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(200);
	SetDamageRate(100, 20);
        SetMovePosition02(GetCenterX, GetCenterY, 120);
        
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        SetGraphicRect(1, 1, 64, 70);
    }

    @MainLoop {
	
        SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 16);
	
	if(frame == 60 || GetTimer==20 && blu==1 || GetEnemyLife<2500 && blu==1){
	let num = 8;
	PlaySE(spawn);
loop(num){
CreateEnemyFromFile(GetCurrentScriptDirectory~"marifam2.txt", GetX+radius*cos(angle), GetY+radius*sin(angle), 0.01, 0.1, NULL);

angle+=360/num;
	}
        }

	if(GetTimer==20 || GetEnemyLife<2500){
	blu=0;
	}
	yield;

        frame++;
	v+=2;
	if(blu==0){
	SetDamageRate(150, 2);
	}
	
    }

function Wait(w){loop(w){yield;}}
task ExMove1 {
loop{	Wait(120);
	ExMove;
}
}


sub ExMove { 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), 2, 1);
		} else {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 2, 1);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 2, 1);
		} else {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 2, 1);
		}
	}
}
	// Movement functions for the boss to move towards the player.
 @DrawLoop {
		SetTexture(ImgBoss);
                SetRenderState(ALPHA);
		SetGraphicRect(1, 1, 60, 70);
                SetAlpha(255);  
                SetGraphicScale(1,1);
                SetGraphicAngle(0,0,0);
		DrawGraphic(GetEnemyX,GetEnemyY);
               
                      
 
               
    }
let y = 0;
@BackGround{
   SetTexture(background);
	
   SetGraphicRect(0, 0+y, 512, 512+y);
   DrawGraphic(GetCenterX, GetCenterY);
  y+=4;
}
    @Finalize {
        DeleteGraphic(ImgBoss);
    }
}

