#Title[gʏ8]
#Text[]
#ScriptVersion[2]
#BackGround[User()]
#Player[FREE]

script_enemy_main {
	#include_function".\lib.txt"
	#include_function".\lib_usershot.txt"
	#include_function".\lib_anime_Mokou.txt"
	
	let img = [	csd~"dot_mokou.png",
				];
	let IMG_BOSS=img[0];
	let count=0;
	
	@Initialize {
		SetX(GetCenterX);
		SetY(144);
		SetLife(10000);
		ascent(i in 0..length(img)){LoadGraphic(img[i]);}
		InitializeAction;
		LoadUserShotData(csd~"data_usershot.txt");
		Main;
	}
	
	@MainLoop {
		SetCollisionA(GetX,GetY,48);
		count+=4.5;
		yield;
	}
	
	@DrawLoop {
		_DrawBoss(IMG_BOSS,GetX,GetY+3*sin(count));
	}
	
	@Finalize {
		ascent(i in 0..length(img)){DeleteGraphic(img[i]);}
	}

	task Main {
		yield;
		loop(180){yield;}
		SetAction(ACT_MOVE,600000);
		Shot;
		Move;
	}
	
	task Shot{
		let distance=64;
		let a;
		let ang=-96;
		let dang=16;
		
		loop{
			a=rand(0,360);
			CircleShot(GetX+distance*cos(a),GetY+distance*sin(a),ang);
			ang+=dang;
			loop(10){yield;}
		}
		
		function CircleShot(x,y,ang){
			loop(48){
				CreateShot02(x,y,1.5,ang,0.025,100,US_BILL_PURPLE,10);
				ang+=7.5;
			}
		}
	}
	
	task Move{
		let ang;
		let v=2;	//ړ(60)(ړt[(60)2)
		let a=-2/60;	//xړt[
		let posx;
		let posy;
		let hflg=true;	//EtO false: true:E
		let vflg=true;	//㉺tO false: true:
		let minx=GetCenterX-64;
		let maxx=GetCenterX+64;
		let miny=GetClipMinY+40;
		let maxy=GetClipMinY+72;
		
		/*
		ascent(i in 0..100){
			CreateShot01(GetClipMinX+4*i,miny,0,0,RED05,0);
			CreateShot01(GetClipMinX+4*i,maxy,0,0,RED05,0);
			CreateShot01(GetClipMinX+4*i,GetClipMinY+107,0,0,RED05,0);
		}
		ascent(i in 0..6){
			CreateShot01(minx,miny+4*i,0,0,RED05,0);
			CreateShot01(maxx,miny+4*i,0,0,RED05,0);
		}
		*/
		
		loop{
			loop(180){yield;}
			hflg=(GetPlayerX>GetX);
			if(GetX<minx){hflg=true;}
			if(GetX>maxx){hflg=false;}
			vflg=[true,false][rand_int(0,1)];
			if(GetY>maxy){vflg=false;}
			
			if(hflg){	//E
				if(vflg){	//
					ang=rand(0,60);
				}else{		//
					ang=rand(-60,0);
				}
			}else{		//
				if(vflg){	//
					ang=rand(120,180);
				}else{		//
					ang=rand(180,240);
				}
			}
			
			v=2;
			loop(60){
				v+=a;
				posx=GetX+v*cos(ang);
				posy=GetY+v*sin(ang);
				if(posy<miny){posy=miny;}
				SetX(posx);
				SetY(posy);
				yield;
			}
		}
	}
}
