Показать сообщение отдельно
Старый 18.06.2006, 00:31
Nidl вне форума Посмотреть профиль Отправить личное сообщение для Nidl Найти все сообщения от Nidl
  № 2  
Ответить с цитированием
Nidl

Регистрация: Mar 2006
Сообщений: 353
Код:
onClipEvent (load) {
	thrust = 2;
	maxSpeed = 4;
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.RIGHT)) {
		this._rotation += 3;
			}
	if (Key.isDown(Key.LEFT)) {
		this._rotation -= 3;
		}
	if (Key.isDown(Key.UP)) {
		xSpeed += thrust*Math.sin(_rotation*(Math.PI/180));
		ySpeed += thrust*Math.cos(_rotation*(Math.PI/180));
	
	} else {
		xSpeed *= decay;
		ySpeed *= decay;		
	}
	if (Key.isDown(Key.DOWN)) {
		xSpeed -= thrust*Math.sin(_rotation*(Math.PI/180));
		ySpeed -= thrust*Math.cos(_rotation*(Math.PI/180));
	
	}
	speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
	if (speed>maxSpeed) {
		xSpeed *= maxSpeed/speed;
		ySpeed *= maxSpeed/speed;
	}
	_y -= ySpeed;
	_x += xSpeed;
	
}
или если с физикой то вот еще пример :

Код:
onClipEvent (load) {
	this.dam = 0;
	this.br = 0.06;
	var MAXspeed = 5;
	var frontMAXspeed = -1;
	this.a = 0.01;
	this.b = 0.02;
	var aksel_koeff = a+b;
	var BreakPathKoeff = 0.005;
	var Akseleration = 0;
	this.nosz._alpha = 0;
	this._rotation = 90;
	this.fuel = 80;
	this.x0 = 100;
	this.nos = 0;
	this.ch = 0;
}
onClipEvent (enterFrame) {
	if (this.Akseleration>0) {
		if (Key.isDown(Key.RIGHT)) {
			if (this.lw._rotation<35) {
				this.lw._rotation++;
				this.rw._rotation++;
			}
			if (Akseleration>0) {
				this._rotation += afront;
			} else if (Akseleration<0) {
				this.arear = math.atan((Akseleration-1)*-Akseleration*2.4);
				this._rotation += arear;
			}
		} else if (Key.isDown(Key.LEFT)) {
			if (this.lw._rotation>-35) {
				this.lw._rotation--;
				this.rw._rotation--;
			}
			if (Akseleration>0) {
				this._rotation -= afront;
			} else if (Akseleration<0) {
				this.arear = math.atan((Akseleration-1)*-Akseleration*2.4);
				this._rotation -= arear;
			}
		} else if (!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT)) {
			this.lw._rotation = 0;
			this.rw._rotation = 0;
		}
		var brake_koeff = br;
	} else if (Akseleration<0) {
		var brake_koeff = -br*2;
	}
	this._x = this.vx+this.x0;
	this._y = this.vy+this.x0;
	if (Key.isDown(Key.ENTER)) {
		if (this.Akseleration<3) {
			this.dl.play();
			this.ch = 1;
			point = new Object();
			point.x = mc3._x;
			point.y = mc3._y;
			localToGlobal(point);
			_root.man._x = point.x;
			_root.man._y = point.y;
			_root.mcc._x = point.x;
			_root.mcc._y = point.y;
		}
	}
	if (this.hitTest(_root.w)) {
		_root.ma._alpha = 100;
		_root.ma._x = _x;
		_root.ma._y = _y;
		_root.ma._rotation = _rotation;
	} else if (this.hitTest(_root.p)) {
		_root.ma._alpha = 100;
		_root.ma._x = _x;
		_root.ma._y = _y;
		_root.ma._rotation = _rotation;
	} else {
		if (_root.ma._alpha>0) {
			_root.ma._alpha -= 5;
		}
	}
	this.vx += akseleration*math.sin(this._rotation*(math.pi/180));
	this.vy -= akseleration*math.cos(this._rotation*(math.pi/180));
	this.afront = math.atan((akseleration+1)*akseleration*2.4);
	if (Key.isDown(Key.UP)) {
		if (this.key.isdown(Key.SHIFT) && this.nos>0) {
			this.nosz._alpha = 100;
			this.nos -= 1;
			if (this.Akseleration<this.maxspeed) {
				this.Aksel_koeff = a+b*1.5;
			}
		} else {
			this.Aksel_koeff = a+b;
			this.nosz._alpha = 0;
		}
		if (this.Akseleration<this.MAXSpeed) {
			this.Akseleration += aksel_koeff;
		}
	} else if (Key.isDown(Key.DOWN)) {
		this.Akseleration -= brake_koeff;
	}
	if (!Key.isDown(Key.UP) && !Key.isDown(Key.DOWN)) {
		if (this.Akseleration>0) {
			this.Akseleration -= BreakPathKoeff;
			if (this.Akseleration<0) {
				this.Akseleration = 0;
			}
		} else if (this.Akseleration<0) {
			this.Akseleration += BreakPathKoeff;
			if (this.Akseleration>0.5) {
				this.Akseleration = 0;
			}
		}
		if (Key.isDown(Key.SPACE)) {
			this.Akseleration /= 1.06;
		}
	}
}

Этот код повесь на машинку .
расход топлива это временной счетчик если клавиша нажата то счетчик обратно считает .
__________________
Вильгельм Тель...........