Показать сообщение отдельно
Старый 19.04.2011, 22:10
Ransy92 вне форума Посмотреть профиль Отправить личное сообщение для Ransy92 Найти все сообщения от Ransy92
  № 7  
Ответить с цитированием
Ransy92

Регистрация: Apr 2011
Сообщений: 19
Код AS3:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
 
	public class JumperGame extends MovieClip
	{
		public const GRAVITY:Number = 2;
		public const BOUNCE_FACTOR:Number = 0.8;
		public const HIT_FORCE:Number = 20;
 
		public var _hero:Hero;
		private var _vx:Number;		
		private var _vy:Number;
		public var speed:Number = 1;
 
		var left:Boolean = false;
		var up:Boolean = false;
		var right:Boolean = false;
		var down:Boolean = false;
 
		public function JumperGame():void
		{
			addEventListener(Event.ADDED_TO_STAGE, startApplication);
		}
		private function startApplication (e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, startApplication);
			_vx = 0;
			_vy = 0;
 
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);  //движение
			stage.addEventListener(KeyboardEvent.KEY_UP, key_up);    ///
		}
 
 
 
		private function key_down(e:KeyboardEvent):void
		{
			if (e.keyCode == 37)
			{
				left = true;
			}
			if (e.keyCode == 38)
			{
				up = true;
			}
			if (e.keyCode == 39)
			{
				right = true;
			}
 
		}
 
		private function key_up (e:KeyboardEvent):void
		{
			if (e.keyCode == 37)
			{
				left = false;
			}
			if (e.keyCode == 38)
			{
				up = false;
			}
			if (e.keyCode == 39)
			{
				right = false;
			}
 
		}
 
 
		public function enterFrameHandler (e:Event):void
		{
			_vy += GRAVITY; //гравитация
 
			_hero.x += _vx;  //Движение героя
			_hero.y += _vy;  //
 
			if (left)
			{_hero.x -= speed}
			if (right)
			{_hero.x += speed}
			if (up)
			{_hero.y -= speed}
 
			checkBoundaryCollision(); //столкновение
		}
 
 
		private function checkBoundaryCollision():void
		{
			var left:Number;
			var right:Number;
			var top:Number;
			var bottom:Number;
 
			left = _hero.x - (_hero.width / 2);
			right = _hero.x + (_hero.width / 2);
			top = _hero.y + (_hero.height / 2);
			bottom = _hero.y - (_hero.height / 2);
 
			if (left < 0 && _vx < 0)
			{
				_hero.x = _hero.width / 2;
				_vx *= -1;
			}
			else if (right > stage.stageWidth && _vx > 0)
			{
				_hero.x = stage.stageWidth - (_hero.width / 2);
				_vx *= -1;
			}
 
			if (top < 0 && _vy < 0)
			{
				_hero.y = _hero.height / 2;
				_vy *= -1;
			}
 
			else if (bottom > stage.stageHeight && _vy > 0)
			{
				_hero.y = stage.stageHeight - (_hero.height / 2);
				_vy *= -BOUNCE_FACTOR;
				_vx *= -BOUNCE_FACTOR;
			}
		}
 
		private function hit (hitX:Number, hitY:Number):void
		{
			_vy -= HIT_FORCE;
 
			if (_vy > 0)
			{
			_vy *= -BOUNCE_FACTOR / 2;	
			}
			if (_vx * hitX > 0)
			{
			_vx *= -BOUNCE_FACTOR;	
			}
 
			_vx -= (2 * hitX / _hero.width) * HIT_FORCE;
		}
	}
}
Добавлено через 49 секунд
проблема здесь

Код AS3:
public function enterFrameHandler (e:Event):void
		{
			_vy += GRAVITY; //гравитация
 
			_hero.x += _vx;  //Движение героя
			_hero.y += _vy;  //
 
			if (left)
			{_hero.x -= speed}
			if (right)
			{_hero.x += speed}
			if (up)
			{_hero.y -= speed}
 
			checkBoundaryCollision(); //столкновение
		}
Добавлено через 7 минут
Попробовал варианты, которые предложили мне, но все равно не получилось.
Может, нужно переписать весь код?