#TouhouDanmakufu
#Title[Marisa Scrapped Boss Spell 2]
#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 charge = GetCurrentScriptDirectory~"charge.wav";
	let broomride = GetCurrentScriptDirectory~"broomride.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 = -130;
	let frame2 = 1;
	let n = 0;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(1200);
        SetTimer(60);
	LoadSE(charge);
        LoadSE(shot);
	LoadSE(broomride);
	LoadSE(bounce);
	LoadSE(declare);
	SetScore(1000000);
	LoadSE(spark);
	LoadSE(shot2);
	SetShotAutoDeleteClip(300, 300, 300, 300);
	CutIn(KOUMA, "Rapid Fire "\""Triple Laser Light Show"\", GetCurrentScriptDirectory~"marisa.png", 0, 0, 128, 256);
	shotinit;
	PlaySE(declare);
	SetEnemyMarker(true);
	SetInvincibility(120);
	SetDamageRate(50, 3);
        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(frame == 0||frame==20||frame==40||frame==60||frame == 80 || frame == 100 || frame == 120 ||frame == 140 || frame == 160 || frame == 180 || frame==200 || frame == 220 || frame == 240 || frame == 260 || frame == 280 || frame == 300) {
let c   = rand(0, 200);
        let num = 20; //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 == 100 || frame == 150 || frame == 190){


	
            
		CreateLaserA(3, GetX, GetY, 4, 120, YELLOW60, 80);
	    SetLaserDataA(3, 0, GetAngleToPlayer, 0, 8, 0, 0); 
	    SetShotKillTime(3, 290);
	    FireShot(3);
            PlaySE(laser);
      
	
	
    }


if(frame == 180 || frame == 230 || frame == 270){
	PlaySE(spark);
	}
	

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



  frame++;
	yield;

}



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.


task CreateShotReflect(x, y, v, ang, graphic, delay) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = 20; let  counter = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); Obj_SetAngle(obj_id, ang); ObjShot_SetDelay(obj_id, delay);
		while(!Obj_BeDeleted(obj_id)) {
			if(counter <= 1) {
				if(Obj_GetX(obj_id) > GetClipMaxX+border) { Obj_SetX(obj_id, 2*(GetClipMaxX+border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)); counter+=2; }
				else if(Obj_GetX(obj_id) < GetClipMinX-border) { Obj_SetX(obj_id, 2*(GetClipMinX-border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)); counter+=2; }
				else if(Obj_GetY(obj_id) < GetClipMinY-border) { Obj_SetY(obj_id, 2*(GetClipMinY-border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
				//else if(Obj_GetY(obj_id) > GetClipMaxY+border) { Obj_SetY(obj_id, 2*(GetClipMaxY+border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
			}
			yield;
		}
	}
	
  @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);
    }
}