#TouhouDanmakufu
#Title[Aya ShaMEEMaru ns4 easy]
#Text [Original way of using circle shots, but easy T_T]
#Player[FREE]
#ScriptVersion[2]			

script_enemy_main{
#include_function ".\1Config.txt"         
	let CSD	= GetCurrentScriptDirectory;
let angul = 180;
let angull = 180;
    let MinX	  = GetClipMinX;
    let MaxX	  = GetClipMaxX;
    let CenX	  = GetCenterX;
    let MinY	  = GetClipMinY;
    let MaxY	  = GetClipMaxY;
    let CenY	  = GetCenterY;
let powerl    = GetCurrentScriptDirectory~".\enm4se\power_logo.wav";
 	let imgBoss = CSD ~ "system\Aya_Main.png";
	let cut = CSD ~ "system\GusanoCirnoCut.png";
	let bg = CSD ~ "system\lake.png";
        let bgm = CSD ~ "bgm\bgm.mp3";
#include_function ".\newsfx.txt";
#include_function ".\Obj_hpb.txt"
#include_function ".\Cutin_Eff.txt"
#include_function ".\system\Aura_Effects.dnh"
#include_function ".\lib_anime_Aya.txt"
	@Initialize{
SetShotAutoDeleteClip(10,10,10,10);
                LoadUserShotData(CSD ~ "kshotData.txt");
		SetLife(2000);
		SetTimer(45);
SetDamageRate(120, 30);
if(lifebar_activate ==1){
hpb(0,1,0);
}
if(Cutin_Activate ==1){
Timer(2,0);
}
                SetInvincibility(180);
		SetMovePosition01(GetCenterX,GetCenterY,5);
		LoadGraphic(imgBoss);
		LoadGraphic(cut);
		LoadGraphic(bg);
InitializeAction;
	if(Aura_Activate==1){
	Aura5;
}
		mainTask;
	}

	@MainLoop{
		SetCollisionA(GetX,GetY,32);
		SetCollisionB(GetX,GetY,16);
		yield;
	}

	@DrawLoop{
DrawText("Aya Shameimaru", 40, 35, 12, 255);
	if(GetSpeedX()>0){SetAction(ACT_MOVE,0)}
	if(GetSpeedX()<0){SetAction(ACT_MOVE,0)}		
	DrawBoss(imgBoss);
	}

	@BackGround{
		SetTexture(bg);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicRect(0,0,63,73);
		SetGraphicScale(2,2);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY);
	}

	@Finalize{
		DeleteGraphic(imgBoss);
		DeleteGraphic(cut);
		DeleteGraphic(bg);
	}

	// main task, activates stuff.
	task mainTask{
		yield;
		fire;
		movement;
	}

	task movement{
		loop{
			SetMovePositionRandom01(50,50,9,GetCenterX-80,GetCenterY-120,GetCenterX+80,GetCenterY-100);
			wait(240);
			yield;
		}
	}
	task fire{
//StartMapleConcentrate;
SetColor(255,0,0);
Concentration01(60);
SetColor(255,255,255);
PlaySE(charge);
wait(60);
Tshot;
	}
 task Tshot {
        let x;
        let y;
        let angle;
        let speed;

        let way = 20;
        let interval = 60;

        let dir;

        loop {
            angle = rand(0, 360);
            dir = rand(0, 360);
PlaySE(shot4);
            loop(way) {
                shotC(GetX, GetY, 0.9, angle, dir, 61, 1);
                angle += 360 / way;
            }
            wait(interval);
        }
    }


    task shotC(x, y, speed, angle, DIR, color1, color2) {
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetDelay(obj, 10);
        ObjShot_SetGraphic(obj, color1);
        Obj_SetSpeed(obj, speed);
        Obj_SetAngle(obj, angle);
        Obj_SetPosition(obj, x, y);

        wait(100);

        let X;
        let Y;
        let dir = DIR;

        let way = 10;
        let interval = 20;

        while(Obj_BeDeleted(obj) == false) {
            shotA(obj, speed, angle, dir, color2);
            dir += 360 / way;

            yield;

            X = Obj_GetX(obj);
            Y = Obj_GetY(obj);
            Obj_Delete(obj);
            obj = Obj_Create(OBJ_SHOT);
            ObjShot_SetGraphic(obj, color1);
            Obj_SetSpeed(obj, speed);
            Obj_SetAngle(obj, angle);
            Obj_SetPosition(obj, X, Y);

            wait(interval - 1);
        }
    }

    task shotA(obj, speed, angle, dir, color) {
        let obj2 = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj2, color);
        Obj_SetCollisionToPlayer(obj2, false);
        Obj_SetSpeed(obj2, speed);
        Obj_SetAngle(obj2, angle);
        Obj_SetPosition(obj2, Obj_GetX(obj) + 18 * cos(dir),
                              Obj_GetY(obj) + 18 * sin(dir));

        let alpha = 0;

        loop(20) {
            Obj_SetAlpha(obj2, alpha);
            alpha += 12;
            yield;
        }
        Obj_SetAlpha(obj2, 255);
        Obj_SetCollisionToPlayer(obj2, true);

        wait(80);

        Obj_SetCollisionToPlayer(obj2, false);
        alpha = 255;

        loop(20) {
            Obj_SetAlpha(obj2, alpha);
            alpha -= 12;
            yield;
        }

        Obj_Delete(obj2);
    }


	// wait function
	function wait(w){
		loop(w){yield;}
	}


}