跳ね返り運動2 : ActionScript

Pocket

斜面での跳ね返りの覚書

幅:10px,高:10px,中心(-5,-5)の円シンボルを作成。

function Ball() {
	function Ball() {
	// 初期位置
	this._x = 10;
	this._y = 0;
	// 落下加速度
	var a = 0.98;
	// 速度
	this.vx = 0;
	this.vy = 0;
	// 反発係数
	var e = 0.5;
	/* onEnterFrame */
	this.onEnterFrame = function() {
		// 等加速度落下
		this.vy += a;
		this._x += this.vx;
		this._y += this.vy;
		var bounds = _root["line_mc"].getBounds(_root);
		if (this._x>bounds.xMin && this._x-this._height/2) {
				y2 = -this._height/2;
				vy1 *= -e;
			}
			// 回転を元に戻す
			x1 = cos*x2-sin*y2;
			y1 = sin*x2+cos*y2;
			this._x = _root["line_mc"]._x+x1;
			this._y = _root["line_mc"]._y+y1;
			// 速度の回転を戻す
			this.vx = cos*vx1-sin*vy1;
			this.vy = sin*vx1+cos*vy1;

		}
	};
}
// line
var line = _root.createEmptyMovieClip('line_mc', _root.getNextHighestDepth());
line.lineStyle(1, 0x000000, 100);
line.moveTo(0, 0);
line.lineTo(400, 0);
line._rotation = 20;
line._x = 0;
line._y = 200;
// ball
o = new Ball();
ball = _root.attachMovie('ball', 'ball_mc', _root.getNextHighestDepth(), o);

コメント

No comments yet.

コメントの投稿

改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。