#東方弾幕風
#Title[贄符「御射山御狩神事」]
#Text[完成度低
雰囲気だけお楽しみください]
#BackGround[Default]
#ScriptVersion[2]

script_enemy_main{

	#include_function ".\lib\lib_anime_Sanae.txt"
	let imgBoss = GetCurrentScriptDirectory() ~ "img\dot_sanae.png";
	let shot  =GetCurrentScriptDirectory~"SE\arrow01.wav";
	let shot2  =GetCurrentScriptDirectory~"SE\kira01_r.wav";
	let shot3  =GetCurrentScriptDirectory~"SE\shoot13.wav";
	let Concentration  =GetCurrentScriptDirectory~"SE\eco00_r.wav";
	let Back=GetCurrentScriptDirectory~"img\kikuBack.png";
	let sippou=GetCurrentScriptDirectory~"img\sippou.png";
	let r  =105;
	let g  =105;
	let b  =105;
	let wIni = 120;

	@Initialize{
	LoadGraphic(imgBoss);
	LoadGraphic(Back);
	LoadGraphic(sippou);
	LoadUserShotData(GetCurrentScriptDirectory ~ "img\shot_All.txt");
        SetMovePosition02(GetCenterX(), 150, wIni/2);
        SetAction(ACT_MOVE, wIni/2);
        SetLife(200);
        SetTimer(70);
        SetInvincibility(wIni*2);
        SetDamageRate(1, 1);
	LoadGraphic(GetCurrentScriptDirectory~"img\back06_01.png");	
	InitializeAction();
	    
	GMain;
	TMain;
	}
		
	@MainLoop{
		SetCollisionA(GetX(), GetY(), 32);
		SetCollisionB(GetX(), GetY(), 24);
	    yield;
	}
	
let BGx=0;
let BGy=0;
@BackGround{
		SetTexture(Back);
		SetGraphicRect(0,0,500,500);
		SetGraphicAngle(0, 0, 0);
		SetAlpha(155);
		SetColor(200,200,200);
		SetGraphicExpansion(1,1);
		DrawGraphic(224, 240); 

		SetTexture(sippou);
		SetGraphicRect(BGx,BGy,BGx+450,BGy+50000);
		SetRenderState(ADD);
		SetGraphicAngle(0, 0, 0);
		SetAlpha(100);
		SetColor(r,g,b);
		SetGraphicExpansion(1,1);
		DrawGraphic(224, 240);
		BGy-=1;
	}	  		
	@Finalize{
	DeleteGraphic(imgBoss);
	}
		task GMain{
		loop{
		loop(50){
		r+=2;
		b-=2;
	    loop(4){ yield; }
			}
		loop(50){
		g+=2;
		r-=2;
	    loop(4){ yield; }
			}
		loop(50){
		b+=2;
		g-=2;
	    loop(4){ yield; }
			}
			}
			}	
	
	task TMain{
	    SetAction(ACT_MOVE, wIni/2);	    
	    yield;
	    loop(wIni/2){ yield; }
        CutIn(YOUMU, "贄符「御射山御狩神事」", "", 0, 0, 0, 0);
          SetAction(ACT_SHOT_B,12000);
        SetScore(14000000/3);
	    loop(wIni/2){ yield; }
	    
	    loop{
	    		let a=-GetAngleToPlayer;
	    loop(1){
 CreateObjShot(GetX, GetY, 3.5,a,30, 0, 0, 4,-1,1,130,-1,8/2);
 CreateObjShot(GetX, GetY, 3.5,a+72,30, 0, 0, 4,-1,1,0,-1,20/2);
 CreateObjShot(GetX, GetY, 3.5,a+72*2,30, 0, 0, 4,-1,1,15,-1,16/2);
 CreateObjShot(GetX, GetY, 3.5,a+72*3,30, 0, 0, 4,-1,1,45,-1,16/2);
 CreateObjShot(GetX, GetY, 3.5,a+72*4,30, 0, 0, 4,-1,1,90,-1,8/2);
		}
	        loop(130){ yield; }
                PlaySE(Concentration);
	        loop(100){ yield; }
                PlaySE(shot3);
	        loop(100){ yield; }
        SetDamageRate(10, 1.5);
	    loop(1){
 CreateObjShot(GetX, GetY, 3.5,a,30, 0, 0, 4,1,-1,-130,1,8/2);
 CreateObjShot(GetX, GetY, 3.5,a+72,30, 0, 0, 4,1,-1,0,1,20/2);
 CreateObjShot(GetX, GetY, 3.5,a+72*2,30, 0, 0, 4,1,-1,-15,1,16/2);
 CreateObjShot(GetX, GetY, 3.5,a+72*3,30, 0, 0, 4,1,-1,-45,1,16/2);
 CreateObjShot(GetX, GetY, 3.5,a+72*4,30, 0, 0, 4,1,-1,-90,1,8/2);
		}
	        loop(130){ yield; }
                PlaySE(Concentration);
	        loop(100){ yield; }
                PlaySE(shot3);
	        loop(100){ yield; }
	    }
			}
	
	
	task CreateObjShot(let x, let y, let speed,
             let angle, let graphic, let delay, let angle2, let cangle, let l, let l2, let angle3, let l3,let W) {
    
        let obj = Obj_Create(OBJ_SHOT);
        Obj_SetPosition(obj, x, y);
        Obj_SetSpeed(obj, speed);
        Obj_SetAngle(obj, angle);
	Obj_SetAlpha(obj, 0);
	ObjShot_SetBombResist(obj, true);
        ObjShot_SetGraphic(obj, graphic);
        ObjShot_SetDelay(obj, delay);
        
        loop(delay){ yield; }
        let a=rand(70,110)*l+angle3;
	let k=0+a;
	let c=l3;
	let w=24;
	let W2=W*2;
        let t=30;
        let t2=320;
	loop(2){
	loop(W){
	loop(4){
		if(cangle>2.1){
	cangle-=0.028;
		}
	angle+=cangle*l2;
        Obj_SetAngle(obj, angle);
            yield;
		}
                PlaySE(shot);
		suzu(10);
		CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),10);
		SetShotDataA(1,0,0,0,0,0,0,30);
		SetShotDataA(1,t,0,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+k,0,0.02,2,30);
		FireShot(1);
	CreateObjShot3(Obj_GetX(obj),Obj_GetY(obj), 0, 18-angle2, 145, 10, t2);
		k-=c*180/(40-1)*2;
		angle2+=6/w;
		t2-=6;
		w-=0.4;
	loop(4){
		if(cangle>2.1){
	cangle-=0.028;
		}
	angle+=cangle*l2;
        Obj_SetAngle(obj, angle);
            yield;
		}
                PlaySE(shot);
		suzu(10);
		CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),10);
		SetShotDataA(1,0,0,0,0,0,0,30);
		SetShotDataA(1,t,0,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+k,0,0.02,2,30);
		FireShot(1);
	CreateObjShot3(Obj_GetX(obj),Obj_GetY(obj), 0, -18+angle2, 145, 10, t2);
		k-=c*180/(40-1)*2;
		angle2+=6/w;
		t2-=6;
		w-=0.4;
		}
        let a=rand(80,100)*l;
	W2=W*2;
	W=20-W2/2;
	k=0+a;
	if(W==16){
	W=8;
	}
		}
	if(W==12){
	loop(8){
	loop(4){
		if(cangle>2.1){
	cangle-=0.028;
		}
	angle+=cangle*l2;
        Obj_SetAngle(obj, angle);
            yield;
		}
                PlaySE(shot);
		suzu(10);
		CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),10);
		SetShotDataA(1,0,0,0,0,0,0,30);
		SetShotDataA(1,t,0,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+k,0,0.02,2,30);
		FireShot(1);
	CreateObjShot3(Obj_GetX(obj),Obj_GetY(obj), 0, 18-angle2, 145, 10, t2);
		k-=c*180/(40-1)*2;
		angle2+=6/w;
		t2-=6;
		w-=0.4;
	loop(4){
		if(cangle>2.1){
	cangle-=0.028;
		}
	angle+=cangle*l2;
        Obj_SetAngle(obj, angle);
            yield;
		}
                PlaySE(shot);
		suzu(10);
		CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),10);
		SetShotDataA(1,0,0,0,0,0,0,256);
		SetShotDataA(1,t,0,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+k,0,0.02,2,30);
		FireShot(1);
	CreateObjShot3(Obj_GetX(obj),Obj_GetY(obj), 0, -18+angle2, 145, 10, t2);
		k-=c*180/(40-1)*2;
		angle2+=6/w;
		t2-=6;
		w-=0.4;
		}
		}
        Obj_Delete(obj);
    }
	task CreateObjShot3(let x, let y, let speed,
             let angle, let graphic, let delay, let delay2) {
        let obj = Obj_Create(OBJ_SHOT);
        Obj_SetPosition(obj, x, y);
        Obj_SetSpeed(obj, 0);
        Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+angle);
        ObjShot_SetGraphic(obj, graphic);
        ObjShot_SetDelay(obj, delay);
        loop(delay2){Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+angle); yield; }
	                     PlaySE(shot2);
        loop(50){speed+=0.1;Obj_SetSpeed(obj,speed); yield; }
    }
		task suzu(t){
	        loop(t){ yield; }
                    PlaySE(shot2);
				}
	@DrawLoop{
	  DrawBoss(imgBoss);
		DrawGraphic(GetX(),GetY());
	}
        

}
