#東方弾幕風
#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(250);
        SetTimer(99);
        SetInvincibility(wIni*2);
        SetDamageRate(6, 1.5);
	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; }
	    	    let a=270;
	    	    let a2=180;
	    loop(3){
water(rand(44,84),0,10,a,0.12,1,254,81,80);
                PlaySE(shot);
		a-=5;
	        loop(7){ yield; }
	    }
	    loop(3){
water(rand(44,84),0,10,a,0.12,1,254,81,70);
water(rand(109,149),0,10,0,0.12,1,254,43,70);
                PlaySE(shot);
		a-=5;
	        loop(7){ yield; }
	    }
	    loop(3){
water(rand(44,84),0,10,a,0.12,1,254,81,70);
water(rand(109,149),0,10,0,0.12,1,254,43,70);
water(rand(174,214),0,10,0,0.12,1,254,44,70);
                PlaySE(shot);
		a-=5;
	        loop(7){ yield; }
	    }
			move01;
        		SetAction(ACT_MOVE,60);
	    loop(3){
water(rand(44,84),0,10,a,0.12,1,254,81,70);
water(rand(109,149),0,10,0,0.12,1,254,43,70);
water(rand(174,214),0,10,0,0.12,1,254,44,70);
water(rand(239,279),0,10,0,0.12,1,254,45,70);
                PlaySE(shot);
		a-=5;
	        loop(7){ yield; }
	    }
	    loop(3){
water(rand(44,84),0,10,a,0.12,1,254,81,70);
water(rand(109,149),0,10,0,0.12,1,254,43,70);
water(rand(174,214),0,10,0,0.12,1,254,44,70);
water(rand(239,279),0,10,0,0.12,1,254,45,70);
water(rand(294,334),0,10,0,0.12,1,254,46,70);
                PlaySE(shot);
		a-=5;
	        loop(7){ yield; }
	    }
	    loop{
	    loop(12){
water(rand(44,84),0,10,a,0.12,1,254,81,70);
water(rand(109,149),0,10,0,0.12,1,254,43,70);
water(rand(174,214),0,10,0,0.12,1,254,44,70);
water(rand(239,279),0,10,0,0.12,1,254,45,70);
water(rand(294,334),0,10,0,0.12,1,254,46,70);
water(rand(359,399),0,10,a2,0.12,1,254,87,70);
                PlaySE(shot);
		a-=5;
		a2+=5;
	        loop(7){ yield; }
		}
			move01;
        		SetAction(ACT_MOVE,60);
	    }
			}
task  water(let X,let Y,let speed,let angle,let mspeed,let lspeed,let color1,let color2,let delay){
        let obj = Obj_Create(OBJ_SHOT);
        Obj_SetPosition(obj, X, Y);
        Obj_SetSpeed(obj, speed);
        Obj_SetAngle(obj, 90);
        ObjShot_SetGraphic(obj, color1);
        ObjShot_SetDelay(obj, 10);
	loop(delay){
if(speed>lspeed){
speed-=mspeed;
		}
if(speed<lspeed){
speed=lspeed;
		}
Obj_SetSpeed(obj, speed);yield; }
        while(!Obj_BeDeleted(obj)) {
		if(angle==0){
                PlaySE(shot2);
		CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),10);
		SetShotDataA(1,0,1.75,atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj)),0,0,0,color2);
		FireShot(1);
			}
		else{
                PlaySE(shot2);
		CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),10);
		SetShotDataA(1,0,rand(0.75,1.25),angle,0,0,0,color2);
		FireShot(1);
		CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),10);
		SetShotDataA(1,0,rand(0.75,1.25),angle,0,0,0,color2);
		FireShot(1);
		}
Obj_Delete(obj);
		 yield; 
		}
	}
			sub move01 {
	    if(GetX()>=234)
	    {
	        SetMovePosition02(GetX()-rand(25,50),rand(130,170),60);
	    }
	    else if(GetX()<=204)
	    {
	        SetMovePosition02(GetX()+rand(25,50),rand(130,170),60);
	    }
	    else if(GetX()<=GetPlayerX())
	    {
	        SetMovePosition02(GetX()+rand(25,50),rand(130,170),60);
	    }
	    else if(GetX()>=GetPlayerX())
	    {
	        SetMovePosition02(GetX()-rand(25,50),rand(130,170),60);
	    }
	}
	@DrawLoop{
	  DrawBoss(imgBoss);
		DrawGraphic(GetX(),GetY());
	}
        

}
