#TouhouDanmakufu[Player]
#ScriptVersion[3]
#ID["DDC Reimu B"]
#Title["DDC Reimu B"]
#Text["Replicates DDC's Reimu B[r]Spell: Spirit Sign \"Fantasy Seal\"[r]By: Ultima/InfiniteWave"]
#Image["./Reimu.png"]
#ReplayName["DDC Reimu B"]

let objPlayer = GetPlayerObjectID();
let current = GetCurrentScriptDirectory();
let spshot = current~"./se/shot.wav";
let spsound = current~"./se/se_gun00.wav";
let spsound2 = current~"./se/se_cat00.wav";
let pshot = current~"./se/se_plst00.wav";
let pldead = current~"./se/se_pldead00.wav";
let pldead2 = current~"./se/se_pldead01.wav";
let graze = current~"./se/se_graze.wav";
let anisp = 5;
let aniwait = 0;
@Initialize{
SetPlayerSpeed(3.5,2);
let path = current ~ "ShotData.dnh";
LoadPlayerShotData(path);
LoadSound(spshot);
LoadSound(spsound);
LoadSound(spsound2);
LoadSound(pshot);
LoadSound(pldead);
LoadSound(pldead2);
LoadSound(graze);
SetPlayerAutoItemCollectLine(100);
ObjPlayer_AddIntersectionCircleA1(objPlayer, 0, 0, 1, 20);
TImage();
Focus;
NormalShot;
SetPlayerClip(13,15,GetStgFrameWidth-13,GetStgFrameHeight-15);
Orbs(ObjMove_GetX(objPlayer),ObjMove_GetY(objPlayer));

}

@MainLoop{yield;}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_SPELL)
	{

		let spell = GetPlayerSpell();
		if(spell >= 1)
		{
			SetScriptResult(true);
			SetPlayerSpell(spell-1);
			TSpell();
		}
		else
		{
			SetScriptResult(false);
		}
	}
	case(EV_HIT)
	{
        PlaySE(pldead);
        DestructionA1(objPlayer,GetPlayerX,GetPlayerY,60);

	}
	case(EV_GRAZE)
	{
        PlaySE(graze);

	}
	case(EV_PLAYER_REBIRTH)
	{
 aniwait = 50;
         Respawn;
	}
	case(EV_PLAYER_SHOOTDOWN)
	{
	PlayerDie;
	SetPlayerSpell(3);

	}
	case(EV_GET_ITEM)
	{

		let itemType = GetEventArgument(0);
		alternative(itemType)
		case(ITEM_SPELL)
		{
			//WriteLog("ITEM_SPELL");
		}
		case(ITEM_SPELL_S)
		{
			//WriteLog("ITEM_SPELL_S");
		}
		case(ITEM_POWER)
		{
			//WriteLog("ITEM_POWER");
		}
		case(ITEM_POWER_S)
		{
			//WriteLog("ITEM_POWER_S");
		}
	}

}
task Respawn{
SetPlayerClip(13,15,GetStgFrameWidth-13,GetStgFrameHeight+30);
ObjMove_SetY(objPlayer,GetStgFrameHeight+30);
ObjRender_SetDestAtFrame(objPlayer,GetPlayerX,GetPlayerY-63,50);
SetPlayerInvincibilityFrame(180);
Blink;
loop(50){yield;}
SetPlayerClip(13,15,GetStgFrameWidth-13,GetStgFrameHeight-15);
}
task Focus{
let obj = [ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D)];
let timer = 0;
let z = 0;
let alpha = 0;

let Target = current~"./etama2.png";

      let scale = 3;
        ascent(i in 0..length(obj)){
	Obj_SetRenderPriorityI(obj[i], 51);
	ObjPrim_SetTexture(obj[i], Target);
	ObjRender_SetBlendType(obj[i], BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj[i], 0, 18, 63, 78);

        ObjSprite2D_SetDestCenter(obj[i]);
        ObjRender_SetScaleXYZ(obj[i], 1, 1, 1);

        ObjRender_SetPosition(obj[i],GetPlayerX,GetPlayerY,0);
        }
        while(!Obj_IsDeleted(objPlayer)){

        if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD && GetPlayerState==STATE_NORMAL){
        alpha+=12;
        scale-=0.05;
        }else{
        alpha-=36;
        scale +=0.1;
        }
        if(scale < 1){
        scale = 1;
        z+=2;
        }
        if(scale > 1){
        z+=6;

        }
        if(scale > 2){
        scale = 2;
        }
        if(alpha > 255){
        alpha = 255;
        }
        if(alpha < 0){
        alpha = 0;
        }
        ascent(i in 0..length(obj)){
        ObjRender_SetAlpha(obj[i],alpha);
        ObjRender_SetAngleZ(obj[0],z);
        ObjRender_SetAngleZ(obj[1],-z);
        ObjRender_SetScaleXYZ(obj[i], scale, scale, scale);
        ObjRender_SetPosition(obj[i],GetPlayerX,GetPlayerY,0);
        }
        yield;
        }
        }
task Blink{
let frameInv = GetPlayerInvincibilityFrame();

while(frameInv >  0){
frameInv = GetPlayerInvincibilityFrame();
ascent(i in 0..2){
ObjRender_SetColor(objPlayer,255*i,255*i,255);
loop(2){yield;}
}
loop(1){yield;}
}
}
task TImage
{

	let path = GetCurrentScriptDirectory() ~ "pl00.png";
	ObjPrim_SetTexture(objPlayer, path);

	let frame = 0;
	let frame2 = 0;
	let movestop = 0;
	let idlestop = 0;
	loop
	{

        aniwait--;

        if(aniwait < 0){
        aniwait = 0;
        }
	if(movestop==0){
	frame++;
	}
	if(idlestop==0){
	frame2++;
	}
	if(movestop==1){
	frame = anisp*4;
	}
	if(idlestop==1){
	frame2 = 0;
	}
if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_LEFT) == KEY_HOLD&&GetPlayerState==STATE_NORMAL&&aniwait <= 0)
{
idlestop = 1;
movestop = 0;
if(frame==anisp){
ObjSprite2D_SetSourceRect(objPlayer, 32*0, 49, 32*1, 98);
}
if(frame==anisp*2){
ObjSprite2D_SetSourceRect(objPlayer, 32*1, 49, 32*2, 98);
}
if(frame==anisp*3){
ObjSprite2D_SetSourceRect(objPlayer, 32*2, 49, 32*3, 98);
}
if(frame==anisp*4){
ObjSprite2D_SetSourceRect(objPlayer, 32*3, 49, 32*4, 98);
}
if(frame==anisp*5){
ObjSprite2D_SetSourceRect(objPlayer, 32*4, 49, 32*5, 98);
}
if(frame==anisp*6){
ObjSprite2D_SetSourceRect(objPlayer, 32*5, 49, 32*6, 98);
}
if(frame==anisp*7){
ObjSprite2D_SetSourceRect(objPlayer, 32*6, 49, 32*7, 98);
}
if(frame==anisp*8){
ObjSprite2D_SetSourceRect(objPlayer, 32*7, 49, 32*8, 98);
frame = anisp*8/2;
}

}
else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_RIGHT) == KEY_HOLD&&GetPlayerState==STATE_NORMAL&&aniwait <= 0)
{
idlestop = 1;
movestop = 0;
if(frame==anisp){
ObjSprite2D_SetSourceRect(objPlayer, 32*0, 98, 32*1, 145);
}
if(frame==anisp*2){
ObjSprite2D_SetSourceRect(objPlayer, 32*1, 98, 32*2, 145);
}
if(frame==anisp*3){
ObjSprite2D_SetSourceRect(objPlayer, 32*2, 98, 32*3, 145);
}
if(frame==anisp*4){
ObjSprite2D_SetSourceRect(objPlayer, 32*3, 98, 32*4, 145);
}
if(frame==anisp*5){
ObjSprite2D_SetSourceRect(objPlayer, 32*4, 98, 32*5, 145);
}
if(frame==anisp*6){
ObjSprite2D_SetSourceRect(objPlayer, 32*5, 98, 32*6, 145);
}
if(frame==anisp*7){
ObjSprite2D_SetSourceRect(objPlayer, 32*6, 98, 32*7, 145);
}
if(frame==anisp*8){
ObjSprite2D_SetSourceRect(objPlayer, 32*7, 98, 32*8, 145);
frame = anisp*8/2;
}





}
		else
		{
idlestop = 0;
movestop = 1;

if(frame2==anisp){
ObjSprite2D_SetSourceRect(objPlayer, 32*0, 0, 32*1, 50);
}
if(frame2==anisp*2){
ObjSprite2D_SetSourceRect(objPlayer, 32*1, 0, 32*2, 50);
}
if(frame2==anisp*3){
ObjSprite2D_SetSourceRect(objPlayer, 32*2, 0, 32*3, 50);
}
if(frame2==anisp*4){
ObjSprite2D_SetSourceRect(objPlayer, 32*3, 0, 32*4, 50);
}
if(frame2==anisp*5){
ObjSprite2D_SetSourceRect(objPlayer, 32*4, 0, 32*5, 50);
}
if(frame2==anisp*6){
ObjSprite2D_SetSourceRect(objPlayer, 32*5, 0, 32*6, 50);
}
if(frame2==anisp*7){
ObjSprite2D_SetSourceRect(objPlayer, 32*6, 0, 32*7, 50);
}
if(frame2==anisp*8){
ObjSprite2D_SetSourceRect(objPlayer, 32*7, 0, 32*8, 50);
frame2 = 0;
}


  }
		ObjSprite2D_SetDestCenter(objPlayer);
		yield;
 }

}

task NormalShot{
loop{
if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD && GetPlayerState==STATE_NORMAL ){
if(IsPermitPlayerShot){
NormShot(9);
NormShot(-11);
PlaySE(pshot);
}
}

loop(4){yield;}
}
}
task NormShot(x){
let obj = CreatePlayerShotA1(GetPlayerX()+x, GetPlayerY()-16, 10, 270, 1.5, 1, 1);
let LastX = ObjMove_GetX(obj);
let LastY = ObjMove_GetY(obj);
while(!Obj_IsDeleted(obj)){
LastX = ObjMove_GetX(obj);
LastY = ObjMove_GetY(obj);
yield;
}
CreateParticle2(LastX,LastY,270);
}



task Orbs(x,y){
Orbs2(x,y);
let csd = GetCurrentScriptDirectory;
let Target = csd~"./shot.png";
let obj = [ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D)];
let timer = 0;
let s = 0;
let mx = ObjMove_GetX(objPlayer);
let my = ObjMove_GetY(objPlayer);

        ascent(i in 0..length(obj)){
	Obj_SetRenderPriorityI(obj[i], 49);
	ObjPrim_SetTexture(obj[i], Target);
	ObjRender_SetBlendType(obj[i], BLEND_ALPHA);
	ObjSprite2D_SetSourceRect(obj[i], 0, 154, 16, 170);

        ObjSprite2D_SetDestRect(obj[i],-16,-16,16,16);
        ObjRender_SetScaleXYZ(obj[i], 0.5, 0.5, 0);

        ObjRender_SetPosition(obj[i],x,y,125);
         }
         optionpos(obj);
         homingshot(obj);
        while(!Obj_IsDeleted(GetPlayerObjectID)){
        timer+=6;
        mx = ObjMove_GetX(objPlayer);
        my = ObjMove_GetY(objPlayer);
        ascent(i in 0..length(obj)){
             ObjRender_SetAngleZ(obj[i],timer);
              if(GetPlayerState==STATE_NORMAL){

              ObjRender_SetAlpha(obj[i],255);
              }else{
              ObjRender_SetPosition(obj[i],GetPlayerX,GetPlayerY,125);
              ObjRender_SetAlpha(obj[i],0);
              }
               }

yield;
}
}
task Orbs2(x,y){
let csd = GetCurrentScriptDirectory;
let Target = csd~"./shot.png";
let obj = [ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D)];
let timer = 0;
let s = 0;
let mx = ObjMove_GetX(objPlayer);
let my = ObjMove_GetY(objPlayer);

        ascent(i in 0..length(obj)){
	Obj_SetRenderPriorityI(obj[i], 48);
	ObjPrim_SetTexture(obj[i], Target);
	ObjRender_SetBlendType(obj[i], BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj[i], 0, 154, 16, 170);
        ObjSprite2D_SetDestRect(obj[i],-16,-16,16,16);
        ObjRender_SetScaleXYZ(obj[i], 0.7, 0.7, 0);

        ObjRender_SetPosition(obj[i],x,y,125);
         }
         optionpos(obj);

        while(!Obj_IsDeleted(GetPlayerObjectID)){
        timer-=6;
        mx = ObjMove_GetX(objPlayer);
        my = ObjMove_GetY(objPlayer);
        ascent(i in 0..length(obj)){
             ObjRender_SetAngleZ(obj[i],timer);
              if(GetPlayerState==STATE_NORMAL){

              ObjRender_SetAlpha(obj[i],255);
              }else{
              ObjRender_SetPosition(obj[i],GetPlayerX,GetPlayerY,125);
              ObjRender_SetAlpha(obj[i],0);
              }
               }

yield;
}
}
task optionpos(obj){
let f = 6;
loop{

if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD){
         ObjRender_SetDestAtFrame(obj[0], GetPlayerX-20, GetPlayerY-20, f);
         ObjRender_SetDestAtFrame(obj[1], GetPlayerX+20, GetPlayerY-20, f);
         ObjRender_SetDestAtFrame(obj[2], GetPlayerX-8, GetPlayerY-30, f);
         ObjRender_SetDestAtFrame(obj[3], GetPlayerX+8, GetPlayerY-30, f);
}else{
         ObjRender_SetDestAtFrame(obj[0], GetPlayerX-50, GetPlayerY+10, f);
         ObjRender_SetDestAtFrame(obj[1], GetPlayerX+50, GetPlayerY+10, f);
         ObjRender_SetDestAtFrame(obj[2], GetPlayerX-20, GetPlayerY+30, f);
         ObjRender_SetDestAtFrame(obj[3], GetPlayerX+20, GetPlayerY+30, f);

}

loop(1){yield;}
}
}

task homingshot(obj){
loop{
if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD && GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD && GetPlayerState==STATE_NORMAL ){
Needle(ObjRender_GetX(obj[0])+2, ObjRender_GetY(obj[0])-10, 10, 270, 3.5, 2);
Needle(ObjRender_GetX(obj[1])+2, ObjRender_GetY(obj[1])-10, 10, 270, 3.5, 2);
Needle(ObjRender_GetX(obj[2])+2, ObjRender_GetY(obj[2])-10, 10, 270, 3.5, 2);
Needle(ObjRender_GetX(obj[3])+2, ObjRender_GetY(obj[3])-10, 10, 270, 3.5, 2);

}
if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD && GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE && GetPlayerState==STATE_NORMAL ){

if(IsPermitPlayerShot){
HomingAmulet(ObjRender_GetX(obj[0]), ObjRender_GetY(obj[0]), 10, 270-25, 2.2, 3);
HomingAmulet(ObjRender_GetX(obj[1]), ObjRender_GetY(obj[1]), 10, 270+25, 2.2, 3);
HomingAmulet(ObjRender_GetX(obj[2]), ObjRender_GetY(obj[2]), 10, 270-15, 2.2, 3);
HomingAmulet(ObjRender_GetX(obj[3]), ObjRender_GetY(obj[3]), 10, 270+15, 2.2, 3);

}
}
loop(4){yield;}
}
}
task Needle(x,y,s,a,d,g){
let obj = CreatePlayerShotA1(x, y, s, a, d, 1, g);
let LastX = ObjMove_GetX(obj);
let LastY = ObjMove_GetY(obj);

while(!Obj_IsDeleted(obj)){
       LastX = ObjMove_GetX(obj);
       LastY = ObjMove_GetY(obj);
yield;
}
CreateParticle(LastX,LastY,[255,0,0]);
CreateParticle(LastX,LastY,[255,0,0]);
CreateParticle3(LastX,LastY);
}
task ObjRender_SetDestAtFrame(obj, x, y, frames){
    let ox = ObjRender_GetX(obj);
    let oy = ObjRender_GetY(obj);
    let xc = (x-ox)/frames;
    let yc = (y-oy)/frames;
    loop(frames){
        ox += xc;
        oy += yc;
        ObjRender_SetX(obj, ox);
        ObjRender_SetY(obj, oy);
        yield;
    }
}


task PlayerDie
{
let dtime = 60;
ExCircle(GetPlayerX,GetPlayerY,0.05,dtime);
ExCircle(GetPlayerX-30,GetPlayerY,0.05,dtime);
ExCircle(GetPlayerX+30,GetPlayerY,0.05,dtime);
ExCircle(GetPlayerX,GetPlayerY-30,0.05,dtime);
ExCircle(GetPlayerX,GetPlayerY+30,0.05,dtime);
PlaySE(pldead2);
loop(10){yield;}
ExCircle(GetPlayerX,GetPlayerY,0.05,dtime-10);

}

task ExCircle(x,y,sc,dtime){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
let timer = 0;
let s = 0;


let Target = current~"./Effect03.png";
let mx = ObjRender_GetX(obj);
let my = ObjRender_GetY(obj);


	Obj_SetRenderPriorityI(obj, 79);
	ObjPrim_SetTexture(obj, Target);

	ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);

	ObjSprite2D_SetSourceRect(obj, 0, 0, 512, 512);

        ObjSprite2D_SetDestCenter(obj);
        ObjRender_SetScaleXYZ(obj, s, s, s);
ObjRender_SetPosition(obj,x,y,0);
loop{
timer++;
        s+=sc;
        ObjRender_SetScaleXYZ(obj, s, s, s);

        if(timer == dtime){
        Obj_Delete(obj);
        break;
        }
        yield;
        }

        }








task TSpell
{
	let current = GetCurrentScriptDirectory();
	let simage = current ~ "pl00b.png";
        SetPlayerInvincibilityFrame(300);
        Blink;
        let ln = 0;
        let t = 0;
        let c = 1;
        let orb_count = 18;
	let objManage = GetSpellManageObject();
	PlaySE(spsound);
        PlaySE(spsound2);
        loop(9){

        FantasySeal(ln,t,c);
        FantasySeal(ln,t,-1);
        ln+=360/9;
        t+=10;
        c++;
        }
        loop{
        if(orb_count==0){
        Obj_Delete(objManage);
        }
        yield;
        }
        task FantasySeal(a,waittime,c){
       	let sobj = ObjSpell_Create;
	let rotate = 0;
	let timer = 0;
	let dir = 0+a;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
        ObjSpell_Regist(sobj);
        if(c==0){
        ObjRender_SetColor(obj,255,0,0);
        }
                if(c==1){
        ObjRender_SetColor(obj,255,0,0);
        }
                if(c==2){
        ObjRender_SetColor(obj,0,255,0);
        }
                if(c==3){
        ObjRender_SetColor(obj,0,0,255);
        }
                if(c==4){
        ObjRender_SetColor(obj,255,0,0);
        }
                if(c==5){
        ObjRender_SetColor(obj,0,255,0);
        }
                if(c==6){
        ObjRender_SetColor(obj,0,0,255);
        }
                if(c==7){
        ObjRender_SetColor(obj,255,0,0);
        }
                if(c==8){
        ObjRender_SetColor(obj,0,255,0);
        }
                if(c==9){
        ObjRender_SetColor(obj,0,0,255);
        }
         let timer2 = 0;
        ObjPrim_SetTexture(obj,simage);
	Obj_SetRenderPriorityI(obj, 49);
        ObjSpell_SetDamage(sobj,1);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);

        ObjSprite2D_SetDestCenter(obj);
        if(c == -1){
        ObjRender_SetScaleXYZ(obj, 0.5, 0.5, 1);
        }else{
        ObjRender_SetScaleXYZ(obj, 1, 1, 1);
        }
        let r = 0;
        ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
        while(!Obj_IsDeleted(sobj)){
        let eid = GetClosestEnemyID(ObjRender_GetX(obj), ObjRender_GetY(obj));
        rotate+=20;
        timer++;
        timer2++;
        dir+=10;
        if(r<=100){
        r+=1;
        }
        if(timer2<=160+waittime){
        ObjRender_SetPosition(obj,GetPlayerX+r*cos(dir),GetPlayerY+r*sin(dir),0);

        }
        if(timer2==160+waittime){
        	let alleid = GetAllEnemyID;
	if(length(alleid)<= 0){timer2 = 0;}else{
        ObjRender_SetDestAtFrame(obj,ObjMove_GetX(eid),ObjMove_GetY(eid),30);
        }
        }
        if(timer==190+waittime){
        ObjSpell_SetDamage(sobj,5);
        blowup(obj,sobj,objManage);
        }

        ObjSpell_SetIntersectionCircle(sobj,ObjRender_GetX(obj),ObjRender_GetY(obj),30);
        ObjRender_SetAngleZ(obj,rotate);
        ObjMove_SetX(sobj,125);
        ObjMove_SetY(sobj,125);
        yield;
        }
        }

           task blowup(obj,sobj,objManage){
   let s = 1;
   let alpha = 255;
    PlaySE(spshot);
    SShake(12,10);
   loop{
   s+=1;
   alpha-=26;
   ObjRender_SetScaleXYZ(obj,s,s,s);
   ObjRender_SetAlpha(obj,alpha);
   if(alpha<=0){
           Obj_Delete(obj);
        Obj_Delete(sobj);
        orb_count--;
        break;

        }
   yield;
   }
   }
}






function GetDistance(x1,y1,x2,y2){
	return(((x2-x1)^2+(y2-y1)^2)^(1/2))
}


function GetClosestEnemyID(x1, y1){
	let earray = GetAllEnemyID;
	if(GetEnemyBossSceneObjectID != ID_INVALID){earray = GetIntersectionRegistedEnemyID;}
	let objid = ID_INVALID;
	let dist = max(GetStgFrameWidth, GetStgFrameHeight)*1.25;
	let size = max(-1, length(earray));
	if(size>=0){
		ascent(b in 0..size){
			let eID = earray[b];
			let edist = GetDistance(x1,y1,ObjRender_GetX(eID),ObjRender_GetY(eID));
			if(edist<dist){
				dist = edist;
				objid = eID
			}
		}
	}
	return objid;
}
task SShake(dist,time){
let cenx = GetStgFrameWidth/2;
let ceny = GetStgFrameHeight/2;

loop(time){

Set2DCameraFocusX(cenx+rand(-dist,dist));
Set2DCameraFocusY(ceny+rand(-dist,dist));
yield;
}

Reset2DCamera;
}

    task DestructionA1(objEnemy,x,y,r){
        let angle = 0;
        loop(1){
        angle+=5;
        loop(r){
        Cherry(x,y,angle);
              angle+=360/r;
                 }
        yield;
        }
        }
        task Cherry(x,y,a){
        let path2 = current ~ "etama2.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

        let angle = a;
        let speed = rand(1.5,3);
        let sa = round(rand(0,359));
        let xm = speed*cos(angle);
        let ym = speed*sin(angle);
        let al = rand(1.5,2);
        let alpha = 0;
        let ora = 255;
        ObjRender_SetColor(obj,255,0,0);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj, 62);
	ObjPrim_SetTexture(obj, path2);
	ObjSprite2D_SetSourceRect(obj, 192, 224, 229,256);
        let s = rand(0.5,1);
        ObjSprite2D_SetDestCenter(obj);
        ObjRender_SetScaleXYZ(obj,s,s,s);
        ObjRender_SetAlpha(obj, ora);
        ObjRender_SetPosition(obj,x,y,0);

        loop{
        alpha+=3;
        ora -=al;
        if(ora<=0){
        Obj_Delete(obj);
        }

        ObjRender_SetAlpha(obj, ora);
        ObjRender_SetPosition(obj,ObjRender_GetX(obj)+xm,ObjRender_GetY(obj)+ym,0);
        ObjRender_SetAngleXYZ(obj,sa+alpha,sa-alpha,sa+alpha);
        yield;
        }

        }


        task HomingAmulet(x, y, s, angle, Shotdmg, Shotgraphic){
	let san = 0;
	let ShotObj = CreatePlayerShotA1(x, y, s, san, Shotdmg, 1, Shotgraphic);
        let alleid = GetClosestEnemyID(ObjMove_GetX(ShotObj), ObjMove_GetY(ShotObj));
         if(length(alleid)==ID_INVALID){san = angle;}else{san = GetAngleToBoss(ShotObj);}
       let LastX = ObjMove_GetX(ShotObj);
       let LastY = ObjMove_GetY(ShotObj);
        let wa = 25;
	let sa = 15;
	let A = 95;
	let S = 0;
	let fAngle = san+A;
	let mod = 2;
        if(angle==270+wa){
        A = 75;
        if(ObjMove_GetY(alleid) > ObjMove_GetY(ShotObj)){
        A = -75;
        }
        }
        if(angle==270+sa){
        A = 45;
        if(ObjMove_GetY(alleid) > ObjMove_GetY(ShotObj)){
        A = -45;
        }
        }
        if(angle==270-wa){
        A = -75;
        if(ObjMove_GetY(alleid) > ObjMove_GetY(ShotObj)){
        A = 75;
        }
        }
        if(angle==270-sa){
        A = -45;
        if(ObjMove_GetY(alleid) > ObjMove_GetY(ShotObj)){
        A = 45;
        }
        }

	while(!Obj_IsDeleted(ShotObj)){
       LastX = ObjMove_GetX(ShotObj);
       LastY = ObjMove_GetY(ShotObj);
	fAngle = san+A;
 if(angle==270+wa||angle==270+sa){
 if(ObjMove_GetY(alleid) > ObjMove_GetY(ShotObj)){
        A+=20;
        if(A > 0){
        A = 0;
        }
 }else{
         A-=18;
        if(A < 0){
        A = 0;
        }
 }
 }

 if(angle==270-wa||angle==270-sa){
 if(ObjMove_GetY(alleid) > ObjMove_GetY(ShotObj)){
        A-=20;
        if(A < 0){
        A = 0;
        }
 }else{
         A+=18;
        if(A > 0){
        A = 0;
        }
 }

 }
                                if(alleid==ID_INVALID){

                                ObjMove_SetAngle(ShotObj, angle);

                                }else{
                                ObjMove_SetAngle(ShotObj, fAngle);
                                }



				yield;
			}
			 CreateParticle2(LastX,LastY,fAngle);

	}

function GetAngleToBoss(obj){
let eid = GetClosestEnemyID(ObjMove_GetX(obj), ObjMove_GetY(obj));
return atan2(ObjMove_GetY(eid)-ObjMove_GetY(obj),ObjMove_GetX(eid)-ObjMove_GetX(obj))
}


task CreateParticle(x,y,color){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj,current~"./Effect04.png");
Obj_SetRenderPriorityI(obj,49);
ObjRender_SetScaleXYZ(obj,1,1,1);
let speed = 3;
let count = 0;
let angle = round(rand(45,180-45));
let mx = speed*cos(angle);
let my = speed*sin(angle);
ObjSprite2D_SetSourceRect(obj,0,0,5,5);
ObjSprite2D_SetDestCenter(obj);
ObjRender_SetColor(obj,color[0],color[1],color[2]);
ObjRender_SetX(obj,x);
ObjRender_SetY(obj,y);
ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
while(!Obj_IsDeleted(obj)){
count++;
ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);
if(count==15){
Obj_Delete(obj);
}
yield;
}
}
task CreateParticle2(x,y,a){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj,current~"./shot.png");
Obj_SetRenderPriorityI(obj,49);
ObjRender_SetScaleXYZ(obj,1,1,1);
let speed = 3;
let count = 0;
let angle = a;
let mx = speed*cos(angle);
let my = speed*sin(angle);
animatePar(obj);
ObjRender_SetAlpha(obj,210);
//ObjSprite2D_SetSourceRect(obj,1,1,4,4);
ObjSprite2D_SetDestCenter(obj);

ObjRender_SetX(obj,x);
ObjRender_SetY(obj,y);
ObjRender_SetBlendType(obj,BLEND_ALPHA);

while(!Obj_IsDeleted(obj)){
count++;
ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);
ObjRender_SetAngleZ(obj,a+90);
yield;
}
}

task animatePar(obj){
let ny = 0;
ObjSprite2D_SetSourceRect(obj,17,235-ny,31,250-ny);
ObjSprite2D_SetDestCenter(obj);
ny += 15;
loop(8){yield;}
ObjSprite2D_SetSourceRect(obj,17,235-ny,31,250-ny);
ObjSprite2D_SetDestCenter(obj);
ny += 15;
loop(8){yield;}
Obj_Delete(obj);
}

task CreateParticle3(x,y){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj,current~"./shot.png");
Obj_SetRenderPriorityI(obj,49);
ObjRender_SetScaleXYZ(obj,1,1,1);
let speed = 3;
let count = 0;
let angle = GetAngleToBoss(obj)+90;
let mx = speed*cos(angle);
let my = speed*sin(angle);

ObjRender_SetAlpha(obj,100);
ObjSprite2D_SetSourceRect(obj,34,130,50,200);
ObjSprite2D_SetDestCenter(obj);
//ObjRender_SetAngleZ(obj,round(rand(-15,15)));
ObjRender_SetX(obj,x);
ObjRender_SetY(obj,y);
ObjRender_SetBlendType(obj,BLEND_ALPHA);

while(!Obj_IsDeleted(obj)){
count++;
if(count == 10){
Obj_Delete(obj);
}
yield;
}
}