#TouhouDanmakufu
#Title[Reimu Non Spellcard 3- easy]
#Text [Changed due to being impossible on normal 
stills using the Leave-style bullets]
#Player[FREE]
#ScriptVersion[2]			

script_enemy_main{         
	let CSD	= GetCurrentScriptDirectory;
let angul = 180;
let angull = 180;
 	let imgBoss = CSD ~ "system\raymoosprite.png";
	let cut = CSD ~ "system\GusanoCirnoCut.png";
	let bg = CSD ~ "system\lake.png";
        let bgm = CSD ~ "bgm\bgm.mp3";
                  #include_function ".\function_cutin.txt"
#include_function ".\blossom.txt"
#include_function ".\newsfx.txt";
#include_function ".\Obj_hpb.txt"
#include_function ".\let.txt"
	@Initialize{
                LoadUserShotData(CSD ~ "kshotData.txt");
		SetLife(4000);
		SetTimer(45);
SetDamageRate(100, 30);
hpb(0,1,0);
//Timer(2,0);
                SetInvincibility(180);
		SetMovePosition01(GetCenterX,GetCenterY,5);
		LoadGraphic(imgBoss);
		LoadGraphic(cut);
		LoadGraphic(bg);
                PlayMusic(bgm);
		SetCommonData("BGM", "BGM : A Tiny, Tiny, Clever Commander");
		SetCommonData("frame",0);
		SetCommonData("length",460);
	
		mainTask;
	}

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

	@DrawLoop{
DrawText("Reimu Hakurei", 40, 35, 12, 255);
		SetTexture(imgBoss);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicRect(0,0,63,73);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetX,GetY);
	}

	@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;
loop(180){yield;}
poot;
	}

	task movement{
		loop{
			SetMovePositionRandom01(50,50,9,GetCenterX-80,GetCenterY-120,GetCenterX+80,GetCenterY-100);
			loop(240){yield;}
			yield;
		}
	}

task poot{
loop{
SetColor(255,255,255);
ascent(i in 0..30){
CreateObjShot(GetX, GetY,3, 0+i*12, 95, 0);
                       }
PlaySE(shot5);
loop(60){yield;}
yield;
             }
function CreateObjShot(let fPosX, let fPosY, let fSpeed, let fAngle, let nGraphic, let nDelay) {
	let objID = Obj_Create(OBJ_SHOT);
	Obj_SetPosition   (objID, fPosX, fPosY);
	Obj_SetSpeed      (objID, fSpeed);
	Obj_SetAngle      (objID, fAngle);
	ObjShot_SetGraphic(objID, nGraphic);
	ObjShot_SetDelay  (objID, nDelay);
backfire(objID,1,10,0);
	return objID;
       }
task backfire( obj, kind, late, gap )
{
while ( Obj_BeDeleted( obj ) == false )
  {
  CreateShotA( 0, Obj_GetX( obj ), Obj_GetY( obj ), late ) ;
  SetShotDataA( 0, 0, 0, 0, 0, 0, NULL, kind ) ;
  SetShotKillTime( 0, 0 ) ;
  FireShot( 0 ) ;
  loop( gap ){yield;}
yield;
  }
}
  }
	task fire{
SetColor(255,0,0);
Concentration01(60);
SetColor(255,255,255);
PlaySE(charge);
loop(60){yield;}
sound;
let x1;
        let x2;
        let angle;

        let interval = 200;

        loop {
            x1 = rand(GetClipMinX - 25, GetCenterX + 25);
            x2 = rand(GetCenterX - 75, GetClipMaxX + 75);
            angle = atan2(GetClipMaxY - GetClipMinY, x2 - x1);
            shotL(x1, GetClipMinY - 30, angle);
            loop(interval){yield;}

            x1 = rand(GetCenterX - 25, GetClipMaxX + 25);
            x2 = rand(GetClipMinX - 75, GetCenterX + 75);
            angle = atan2(GetClipMaxY - GetClipMinY, x2 - x1);
            shotL(x1, GetClipMinY - 30, angle);
            loop(interval){yield;}
        }
    }
task sound{
loop{
PlaySE(bulletwave);
loop(200){yield;}
yield;
 }
}
    //Š‘’e‚ð•À‚×‚é’e–‹‚P—ñ•ª
    task shotL(X, Y, angle) {
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, 1);
        ObjShot_SetBombResist(obj, true);
        Obj_SetAlpha(obj, 0);
        Obj_SetSpeed(obj, 4);
        Obj_SetAngle(obj, angle);
        Obj_SetPosition(obj, X, Y);

        let x;
        let y;
        let dir;
        let radius;

        let interval = 1;

        while(Obj_BeDeleted(obj) == false) {
            dir = rand(0, 360);
            radius = rand(15, 60);
            x = Obj_GetX(obj) + radius * cos(dir) + rand(-10, 10);
            y = Obj_GetY(obj) + radius * sin(dir) + rand(-10, 10);
            shotM(x, y);
            loop(interval){yield;}
        }
    }

    //Š‘’e
    task shotM(x, y) {
        let speed = [0.3, 0.3, 0.4, 0.4, 0.6];
        let angle = rand(0, 360);
        let R = rand(0, 200);
        let shift = [-90, 90, -50, 50, 0];

        SetShotColor(255, 255 - R, 255 - R);
        ascent(i in 0..5) {
            CreateShotA(0, x, y, 15);
            SetShotDataA(0, 0, speed[i], angle + shift[i], 0, 0, 0, 51);
            SetShotDataA(0, 10, 0, NULL, 0, 0, 0, 51);
            SetShotDataA(0, 140, -speed[i], NULL, 0, 0, 0, 51);
            SetShotKillTime(0, 150);
            FireShot(0);
        }
    }
            
			loop(120){yield;}
			yield;
		}
task lol{
loop(20){yield;}
let x;
        let y;
        let speed = [0.3, 0.3, 0.4, 0.4, 0.6];
        let angle;
        let R;

        let shift = [-90, 90, -50, 50, 0];
        let quantity = 10;
        let interval = 0;

        loop {
            loop(quantity) {
                x = rand(GetClipMinX - 5, GetClipMaxX + 5);
                y = rand(GetClipMinY - 5, GetCenterY + 70);
                angle = rand(0, 360);
                R = rand(0, 200);
                SetShotColor(255, 255 - R, 255 - R);
                ascent(i in 0..5) {
                    CreateShotA(0, x, y, 0);
                    SetShotDataA(0, 0, speed[i], angle + shift[i], 0, 0, 0, 51);
                    SetShotDataA(0, 10, 0, NULL, 0, 0, 0, 51);
                    SetShotDataA(0, 110, 2, NULL, 0, 0, 0, 51);
                    SetShotKillTime(0, 120);
                    FireShot(0);
                }
            }
           loop(interval){yield;}
        
}

}

}
	}

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

}