//==============================================================================
//	{X AjCu
//@{XʃAjCu`ɂăCN[h
//==============================================================================
//@萔Aϐ
//==============================================================================
//@ANV萔
//@{XhbgG̊eJbg̔zuԍ
//@	1  5  9 13 17 21   25 29
//@	2  6 10 14 18 22   26 30
//@	3  7 11 15 19 23   27 31
//@	4  8 12 16 20 24   28 32
//@e萔ɂAjp^[͊eRgQƁi*͏󋵂ɉĒ\j
//------------------------------------------------------------------------------
let _ACT_STAND1		= -1;	//@iAjȂj		 1
let _ACT_STAND3		= 0;	//@{܂΂i3R}j	 1-  2-  3-c 1-  5-  6-c
let _ACT_MOVE		= 3;	//@ړiEj	
let _ACT_MOVE_L		= 4;	//@ړ					 9-*10-  9
let _ACT_MOVE_R		= 5;	//@Eړ					11-*12- 11


//------------------------------------------------------------------------------
//@Jbgʋ`W萔i̍Wj
//@e萔Jbg̓RgyуANV萔̃JbgzuԍQ
//------------------------------------------------------------------------------
let RECT_LENGTH		= 32;
let RECT_STAND0		= [ 0, 0 ];								//	 1
let RECT_STAND1		= [ 0, RECT_LENGTH ];					//	 2
let RECT_STAND2		= [ 0, 2 * RECT_LENGTH ];				//	 3
let RECT_STAND3		= [ 0, 3 * RECT_LENGTH ];				//	 4
let RECT_BLINK0		= [ RECT_LENGTH, 0 ];					//	 5
let RECT_BLINK1		= [ RECT_LENGTH, RECT_LENGTH ];			//	 6
let RECT_BLINK2		= [ RECT_LENGTH, 2 * RECT_LENGTH ];		//	 7
let RECT_MOVE_L0	= [ 2 * RECT_LENGTH, 0 ];				//	 9
let RECT_MOVE_L1	= [ 2 * RECT_LENGTH, RECT_LENGTH ];		//	10
let RECT_MOVE_R0	= [ 2 * RECT_LENGTH, 2 * RECT_LENGTH ];	//	11
let RECT_MOVE_R1	= [ 2 * RECT_LENGTH, 3 * RECT_LENGTH ];	//	12


//------------------------------------------------------------------------------
//@L萔
//------------------------------------------------------------------------------
let CHAR_ZAKO		= 27;

//------------------------------------------------------------------------------
//@̑ϐ
//------------------------------------------------------------------------------
let actionDefault = _ACT_STAND1;	//@{ANV
let action = actionDefault;			//@݂̃ANV
let actionCount = 0;				//@ANVt[JE^
let actionCountMax = 0;				//@ANVI܂ł̃t[
let stopAnime = false;				//@true̊Ԃ̓Aj~
let character = CHAR_ZAKO;		//@쒆̃LN^[

//==============================================================================
//@ANVw֘A֐
//==============================================================================
//@ANVݒ
//------------------------------------------------------------------------------
task InitializeAction(){
	loop{
		SetAction( actionDefault, 0 );
		while( actionCount < actionCountMax ){
			while( stopAnime ){ yield; }
			actionCount ++;
			yield;
		}
	}
}

//------------------------------------------------------------------------------
//@ANVw
//@wt[o߂Ɗ{ANVɈڍs
//------------------------------------------------------------------------------
function SetAction(
	let newAction,		//@ANV萔
	let frame			//@ANVI܂ł̃t[
){
	alternative( newAction )
	case( _ACT_STAND1, _ACT_STAND3 ){ frame = 216000; }
	action = newAction;
	actionCount = 0;
	actionCountMax = frame;
}

//------------------------------------------------------------------------------
//@Ajꎞ~
//@~rɂĊJꍇ0ȉ̃t[w肷
//------------------------------------------------------------------------------
task StopAnime(
	let frame		//@~t[ioߌɃAjĊJj
){
	if( frame > 0 ){
		stopAnime = true;
		loop( frame ){
			if( !stopAnime ){ break; }
			yield;
		}
		stopAnime = false;
	}
	else{ stopAnime = false; }
}

//==============================================================================
//@`֘A֐
//==============================================================================
//@{XAj`iʏj
//------------------------------------------------------------------------------
function DrawBoss(
	let imageFile		//@摜t@CpX
){
	_DrawBoss( imageFile, GetX(), GetY() );
}

//------------------------------------------------------------------------------
//@{XAj`iWwj
//------------------------------------------------------------------------------
function _DrawBoss(
	let imageFile,		//@摜t@CpX
	let x,				//	SxW
	let y				//	SyW
){
	let rect = [];
	alternative( action )
	//@3R}[vi{Hj --------------------------------
	case( _ACT_STAND3 ){
		let cutFrame = 12;
		let count = actionCount % ( cutFrame * 12 );
		let number = trunc( count / cutFrame );
		let anime = [ 0, 1, 2, 0, 1, 2, 0, 3, 4, 0, 1, 2, 2 ][ number ];
		rect = [ RECT_STAND0, RECT_STAND1, RECT_STAND2,
			RECT_BLINK0, RECT_BLINK1 ][ anime ];
	}

	//@3R}ړiEj ------------------------------------
	case( _ACT_MOVE){
		if( absolute( GetSpeed() ) < 0.1 ){ rect = RECT_STAND0; }
		else{
			let cutFrameA = 10;
			if( actionCountMax < 30 ){ cutFrameA = trunc( actionCountMax / 3 ); }
			let cutFrameB = actionCountMax - cutFrameA;
			let animePattern = [ 0, 1, 0 ];
			let framePattern = [ cutFrameA, cutFrameB, actionCountMax ];
			let anime = animePattern[ 2 ];
			ascent( let i in 0 .. 3 ){
				if( actionCount < framePattern[ i ] ){
					anime = animePattern[ i ];
					break;
				}
			}
			let moveL = cos( GetAngle() ) <= 0;
			if( moveL ){ rect = [ RECT_MOVE_L0, RECT_MOVE_L1 ][ anime ]; }
			else{ rect = [ RECT_MOVE_R0, RECT_MOVE_R1 ][ anime ]; }
		}
	}
	//@3R}ړiEwj ----------------------------------------
	case( _ACT_MOVE_L, _ACT_MOVE_R){
		let cutFrameA = 10;
		if( actionCountMax < 30 ){ cutFrameA = trunc( actionCountMax / 3 ); }
		let cutFrameB = actionCountMax - cutFrameA;
		let animePattern = [ 0, 1, 0 ];
		let framePattern = [ cutFrameA, cutFrameB, actionCountMax ];
		let anime = animePattern[ 2 ];
		ascent( let i in 0 .. 3 ){
			if( actionCount < framePattern[ i ] ){
				anime = animePattern[ i ];
				break;
			}
		}
		if( action == _ACT_MOVE_L ){
			rect = [ RECT_MOVE_L0, RECT_MOVE_L1 ][ anime ];
		}
		else{ rect = [ RECT_MOVE_R0, RECT_MOVE_R1 ][ anime ]; }
	}

	//@` ---------------------------------------------------------
	SetTexture( imageFile );
	SetGraphicRect( rect[ 0 ], rect[ 1 ], rect[ 0 ] + RECT_LENGTH, rect[ 1 ] + RECT_LENGTH );
	DrawGraphic( x, y );
}

