#TouhouDanmakufu
#Title[Marisa Boss Spell 3]
#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 laser = GetCurrentScriptDirectory~"laser.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let charge = GetCurrentScriptDirectory~"charge.wav";
	let broomride = GetCurrentScriptDirectory~"broomride.wav";
	let declare = GetCurrentScriptDirectory~"cardcall.wav";
	let background = GetCurrentScriptDirectory~"MariBG2.png";
	let spark = GetCurrentScriptDirectory~"spark.wav";
	let t = 0;
	let a = 0;
	let v = 1;
	let d = 24;
	let angle = 0;
	let z = 0;
	let spin = 0;
    let frame = -130;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(900);
        SetTimer(60);
	LoadSE(charge);
        LoadSE(shot);
	LoadSE(broomride);
	LoadSE(bounce);
	LoadSE(declare);
	SetScore(1000000);
	LoadSE(spark);
	LoadSE(shot2);
	SetShotAutoDeleteClip(100, 100, 100, 100);
	CutIn(KOUMA, "Borrowed Magic "\""Elemental Hurricane"\", GetCurrentScriptDirectory~"marisa.png", 0, 0, 128, 256);
	shotinit;
	PlaySE(declare);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(30, 30);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 30);
        
        LoadGraphic(ImgBoss);
	SetTexture(ImgBoss);
	LoadGraphic(background);
        SetGraphicRect(1, 1, 64, 70);
    }

    @MainLoop {
	 SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	if(GetPlayerX>GetCenterX){
	d = 24
	}
	if(GetPlayerX<GetCenterX){
	d = 24
	}

	if(frame == 40 || frame==80){
	PlaySE(shot);
	let a   = 0;
        let num = 12; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		
		CreateShotA(1, GetX, GetY, 0);
		CreateShotA(2, GetX, GetY, 5);
		CreateShotA(3, GetX, GetY, 10);
		CreateShotA(4, GetX, GetY, 15);
		CreateShotA(5, GetX, GetY, 20);
		CreateShotA(6, GetX, GetY, 25);
		SetShotDataA(1, 0, 1, v+90+a, 0.01, 0.05, 4, RED21);
		SetShotDataA(1, 60, 2, NULL, 0.01, 0.09, 2, RED21);
		SetShotDataA(2, 0, 1, v+90+a, 0.01, 0.05, 4, RED21);
		SetShotDataA(2, 60, 2, NULL, 0.01, 0.09, 2, RED21);
		SetShotDataA(3, 0, 1, v+90+a, 0.01, 0.05, 4, RED21);
		SetShotDataA(3, 60, 2, NULL, 0.01, 0.09, 2, RED21);
		SetShotDataA(4, 0, 1, v+90+a, 0.01, 0.05, 4, RED21);
		SetShotDataA(4, 60, 2, NULL, 0.01, 0.09, 2, RED21);
		SetShotDataA(5, 0, 1, v+90+a, 0.01, 0.05, 4, RED21);
		SetShotDataA(5, 60, 2, NULL, 0.01, 0.09, 2, RED21);
		SetShotDataA(6, 0, 1, v+90+a, 0.01, 0.05, 4, RED21);
		SetShotDataA(6, 60, 2, NULL, 0.01, 0.09, 2, RED21);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);
FireShot(2);
FireShot(3);
FireShot(4);
FireShot(5);
FireShot(5);


}
}        

if(frame == 60 || frame==100){
	
	let a   = 0;
        let num = 20; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		PlaySE(bounce);
		CreateShotA(1, GetX+70, GetY, 20);
		SetShotDataA(1, 0, 1, v+90+a, 0.01, 0.05, 3, YELLOW04);
		SetShotDataA(1, 60, 1, NULL, 0.2, 0.1, 2, YELLOW04);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        

if(frame == 30 || frame==90){
	
	let a   = 0;
        let num = 32; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		PlaySE(shot);
		CreateShotA(1, GetX, GetY-40, 30);
		SetShotDataA(1, 0, 1, v+90+a, 0.01, 0.05, 1, GREEN12);
		SetShotDataA(1, 60, 0, v+90+a, -0.3, -0.1, -2, GREEN54);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        

if(frame == 60 || frame== 120){
	
	let a   = 0;
        let num = 32; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		PlaySE(shot);
		CreateShotA(1, GetX, GetY-40, 30);
		SetShotDataA(1, 0, 1, v+90+a, 0.01, 0.05, 1, GREEN12);
		SetShotDataA(1, 60, 0, v+90+a, 0.3, -0.1, -2, GREEN54);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        

if(frame == 60 || frame==100){
	
	let a   = 0;
        let num = 20; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		
		CreateShotA(1, GetX-70, GetY, 20);
		SetShotDataA(1, 0, 1, v+90+a, 0.01, 0.05, 3, YELLOW04);
		SetShotDataA(1, 60, 1, NULL, 0.2, -0.1, 2, YELLOW04);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        

if(frame == 55 || frame==110){
	
	let a   = 0;
        let num = 20; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		PlaySE(bounce);
		CreateShotA(1, GetX-130, GetY+50, 20);
		SetShotDataA(1, 0, 1, v+90+a, 0.01, 0.05, 3, WHITE32);
		SetShotDataA(1, 60, 1, NULL, 0.2, 0.2, 1, WHITE32);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        

if(frame == 55 || frame==110){
	
	let a   = 0;
        let num = 20; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		PlaySE(shot);
		CreateShotA(1, GetX+130, GetY+50, 20);
		SetShotDataA(1, 0, 1, v+90+a, 0.01, 0.05, 3, WHITE32);
		SetShotDataA(1, 60, 1, NULL, 0, 0.2, 1, WHITE32);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        

if(frame==0 ||frame == 40 ||  frame == 80 || frame == 120){
	
	let a   = 0;
        let num = 20; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		PlaySE(shot2);
		CreateShotA(1, GetX, GetY, 0);
		SetShotDataA(1, 0, 1, 180, 0.01, 0.05, 3, BLUE02);
		SetShotDataA(1, 60, 2, GetAngleToPlayer-d, 0.01, 0.09, 2.5, BLUE02);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        

if(frame==0 ||frame == 40 ||  frame == 80 || frame == 120){
	
	let a   = 0;
        let num = 20; //Change this number here to specify the number of bullets in the ring.

	loop(num)
            {	
		
		CreateShotA(1, GetX, GetY, 0);
		SetShotDataA(1, 0, 1, 360, 0.01, 0.05, 3, BLUE02);
		SetShotDataA(1, 60, 2, GetAngleToPlayer+d, 0.01, 0.05, 2.5, BLUE02);
		
		v+=0.16;
		
		a +=360/num;
FireShot(1);


}
}        


	if(frame == 120){
	frame=0;
	}


  frame++;

}



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 {
        DeleteGraphic(ImgBoss);
    }
}
