#e
#Title[ړeXg]
#Text[test]
#PlayLevel[Test]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\lib_anime_Mokou.dnh"
	
	let bossImg = GetCurrentScriptDirectory ~ "img\dot_mokou.png";
	
	let cx = GetCenterX;
	let cy = GetCenterY;
	let xIni = cx;
	let yIni = cy;
	
	@Initialize {
		SetTimer(120);
		SetScore(10000);
		SetLife(10);
		SetDamageRate(0, 0);
		
		LoadGraphic(bossImg);
		InitializeAction;
		TMain;
	}

	@MainLoop {
		yield;
	}

	@DrawLoop {
		DrawBoss(bossImg);
	}

	@Finalize {
		DeleteGraphic(bossImg);
	}

	task TMain {
		getReady(120);
		
		let x = 128;
		let i = 1;
		loop {
			move(180, cx + x * i, cy);
			i = -i;
			
			loop(210) {
				yield;
			}
		}
	}
	
	// _frame:ړɗv鎞(F) ̔猸n߂
	// _x, _y:ړ̍W
	task move(_frame, _x, _y) {
		let fromX = GetX;	// ړO̍W@Ɗpx̎Zoɗp
		let fromY = GetY;	// 
		let toX = _x;		// ړ̍W
		let toY = _y;		// 
		SetAction(ACT_MOVE, _frame + 10);	// ړAj[V点@ړĂ鎞Ԃ኱߂Ɏ
		yield;
		
		let d = ((toX - fromX)^2 + (toY - fromY)^2)^(1/2);	// 
		let t = _frame;										// 
		
		let v0 = (4*d) / (3*t);		// v0  = (4/3)v = 4d/3t
		let a = (-8*d) / (3*t^2);	// xa = -(8/3t)v = -8d/3t^2
		
		CreateShot01(toX, toY, 0, 0, WHITE01, 0);	// ړ̖ڈƂĔeݒuĂ
		
		let angle = atan2(toY - fromY, toX - fromX);	// ړւ̊px
		SetAngle(angle);
		
		SetSpeed(v0);
		loop(t / 2) {	// ͓^𑱂
			yield;
		}
		
		let v = v0 + a;
		loop(t / 2) {	// 瓙x^@łGetSpeedg킸ɕϐvpĐ䂷
			SetSpeed(v);
			v += a;
			yield;
		}
		SetSpeed(0);	// ꉞ0
	}
	
	function getReady(wIni) {	// ʒuɈړ邾̊֐ł
		SetMovePosition02(xIni, yIni, wIni);
		loop(wIni) {
			yield;
		}
	}
}
