#TouhouDanmakufu
#Title[Marisa scrapped midboss spell!]
#Text[Moo]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User(.\moon.png, 0, 0)]
script_enemy_main {
    let ImgBoss = GetCurrentScriptDirectory~"MarisaSprites.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~"MariBG.png";
	let spark = GetCurrentScriptDirectory~"spark.wav";
	let t = 0;
	let a = 0;
	let v = 1;
	let angle = 0;
	let z = 0;
	let spin = 0;
    let frame = -120;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(300);
        SetTimer(60);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(declare);
	SetScore(1000000);
	LoadSE(spark);
	LoadSE(shot2);
	SetShotAutoDeleteClip(100, 200, 100, 100);
	CutIn(KOUMA, "Love Sign "\""Master Spark -Sweeping-"\", GetCurrentScriptDirectory~"marisa.png", 0, 0, 128, 256);
	shotinit;
	PlaySE(declare);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(10, 10);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        
        LoadGraphic(ImgBoss);
	SetTexture(ImgBoss);
	LoadGraphic(background);
        SetGraphicRect(1, 1, 64, 70);
    }

    @MainLoop {
	if(GetPlayerX>GetCenterX){
	angle = 50;
	spin = 0.17;
	}
	if(GetPlayerX<GetCenterX){
	angle = -50;
	spin = -0.17;
	}
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);

	


if(frame == 20){

	let c   = rand(0, 200);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}


if(frame == 40){

	let c   = rand(0, 200);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 60){

	let c   = rand(0, 40);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 80){

	let c   = rand(0, 600);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 100){

	let c   = rand(0, 80);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 120){

	let c   = rand(0, 100);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 140){

	let c   = rand(0, 120);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 160){

	let c   = rand(0, 140);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 180){

	let c   = rand(0, 160);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 200){

	let c   = rand(0, -200);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 220){

	let c   = rand(0, -400);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 240){

	let c   = rand(0, -600);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 260){

	let c   = rand(0, -80);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 280){

	let c   = rand(0, -120);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 300){

	let c   = rand(0, -140);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 320){

	let c   = rand(0, -160);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 340){

	let c   = rand(0, -180);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 360){

	let c   = rand(0, -200);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 380){

	let c   = rand(0, -100);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, RED59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 400){

	let c   = rand(0, -1000);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, BLUE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}

if(frame == 420){

	let c   = rand(0, -1000);
        let num = 30; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShot01(GetX, GetY, 1, c+90, PURPLE59, 5);
            c += 360/num;
	PlaySE(shot);
}

}
        if(frame == 421) {

	frame=-1;
	}

if(frame == 120){


	
            CreateLaserA(1, GetX, GetY, 4, 90, YELLOW60, 60);
	    SetLaserDataA(1, 0, -angle+GetAngleToPlayer, spin, 8, 0, 0); 
	    SetShotKillTime(1, 320);
	    FireShot(1);
            PlaySE(laser);
      
	
	
    }
if(frame == 180){
	PlaySE(spark);
	}

  frame++;
	v+=2;
}
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, rand(height - 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.

  @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+=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));
	CreateItem(ITEM_1UP,GetX + rand(-20,20),GetY + rand(-20,20));
        DeleteGraphic(ImgBoss);
    }
}
