#e
#Title[uRbgX^[Ov]
#Text[]
#BGM[.\..\bgm\bgm.wav]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
	
	@Initialize{
		imgBoss = imgBoss_Marisa;
		InitializeData();
		InitializeAction();
		
		SetLife(1000);
		SetX( CenterX );
		SetY( CenterY );
		SetDamageRate(22,15);
		SetCollisionEx(32,16,false,360);
		SetEnemyMarker(true);
		LastSpell();
		
		SetEffectForZeroLife(2,0,0);
		
		TMain();
	}
	
	@MainLoop{
		yield;
	}
	
	@DrawLoop{
		DrawBoss(imgBoss);
	}
	
	@Finalize{
		FinalizeData();
	}
	
	task TMain(){
		FWait(60);
		
		DeclareSpell();
		
		Atack();
	}
	
	function DeclareSpell(){
		SetScore(2600000);
		SetTimer(63);
		CutIn(KOUMA,"uRbgX^[Ov",NULL,0,0,0,0);
		SetAction(ACT_SPELL,180);
		FWait(180);
	}
	
	task Atack(){
		let color = 0;
		let aspeed = 0.6;
		
		SetAction(ACT_SHOT_A,21600);
		
		loop{
			Ring(color % 7, (color % 2) * 2 - 1,aspeed);
			
			color += 1;
			if(aspeed < 1.2){
				aspeed += 0.05;
			}
			
			FWait(60);
		}
	}
	
	task Ring(color,turn,aspeed){
		let R = [ 255, 255, 255,   0,   0,   0, 255];
		let G = [   0, 128, 255, 255, 255,   0,   0];
		let B = [   0,   0,   0,   0, 255, 255, 255];
		
		let Mrx = 0.6 * turn;
		let Mry = 0.41;
		let Mrz = 0.8;
		
		let imgSize = 512;
		
		let Way = 14;
		
		let loopflag = true;
		let nrad = 0;
		let rangle = rand(0,360);
		let rx = -90;
		let ry =   0;
		let rz =   0;
		
		RingControl();
		RingEffect();
		
		ascent(i in 0..Way){
			RingShot(rangle + i * 360 / Way);
		}
		
		////////////////////////////////////////////////////////
		// 狓                                       //
		////////////////////////////////////////////////////////
		
		task RingControl(){
			loop(30){
				nrad += 2.6;
				rx += Mrx * (120 / nrad);
				ry += Mry * (120 / nrad);
				rz += Mrz * (120 / nrad);
				yield;
			}
			
			loop(330){
				nrad += 0.9;
				rx += Mrx * (120 / nrad);
				ry += Mry * (120 / nrad);
				rz += Mrz * (120 / nrad);
				yield;
			}
			
			loopflag = false;
		}
		
		task RingShot(angle){
			let x = cos(angle);
			let y = sin(angle);
			let z = 0;
			
			let xyz = [0,0,0];
			let px = 0;
			let py = 0;
			let graph = 233 + 4;
			let graphd = 153 + color;
			
			let obj = CreateObjShot(x,y,0,0,graph,0);
			Obj_SetAutoDelete(obj,false);
			
			while( !Obj_BeDeleted(obj) && loopflag ){
				xyz = Conv3Dto2DLite(x,y,z,rx,ry,rz);
				
				px = xyz[0] * nrad;
				py = xyz[1] * nrad;
				
				GrowEffect(GetX() + px,GetY() + py,graphd,22,1);
				
				Obj_SetPosition(obj,GetX() + px,GetY() + py);
				
				angle += aspeed;
				x = cos(angle);
				y = sin(angle);
				
				yield;
			}
			
			if( !Obj_BeDeleted(obj) ){
				Obj_Delete(obj);
			}
		}
		
		task RingEffect(){
			let obj = CreateObjEffect(imgEffect_Ring,GetX(),GetY(),0,0,imgSize,imgSize,1,255,R[color],G[color],B[color]);
			
			while( !Obj_BeDeleted(obj) && GetLife() > 0 && loopflag ){
				ObjEffect_SetAngle(obj,rx,ry,rz);
				ObjEffect_SetScale(obj,nrad * 2 / imgSize,nrad * 2 / imgSize);
				
				yield;
			}
			
			if( !Obj_BeDeleted(obj) ){
				Obj_Delete(obj);
			}
		}
	}
	
	function Conv3Dto2DLite(x,y,z,a,b,c){
		let xx = ( ( x * sin(c) + y * cos(c) ) * sin(a) ) * sin(b) + ( x * cos(c) - y * sin(c) ) * cos(b);
		let yy = ( x * sin(c) + y * cos(c) ) * cos(a);
		//let zz = ( ( x * sin(c) + y * cos(c) ) * sin(a) ) * cos(b) - ( x * cos(c) - y * sin(c) ) * sin(b);
		let zz = 0;
		
		return [xx,yy,zz];
	}
	
	#include_function ".\initialize.txt"
	#include_function ".\..\lib\lib_anime_marisa.txt"
	
	#include_function ".\..\lib\lib_obj.txt"
	#include_function ".\..\lib\lib_value.txt"
	#include_function ".\..\lib\lib_effect.txt"
}