Hey flashkit,

I'm currently building the engine for a platforming game, and am having some problems with my collision detect. It works for the most part...but when my player lands on 'HitObject' (the object I'm having him collide with), he goes all the way through the object, then back to the top, where I want him to be. Now granted, this happens very fast, so it's not that big a deal. What is, however, is that when I jump multiple times, eventually player will fall completely through the object. Is there a better way to do collision detect then what I'm already doing? (if you want to ctrl f right to the code where I do the collision detect, just search for 'f(_player.hitTestObject(_hitObject))'

And while I'm at it...I might as well ask another question I've been wondering about. Is there a way to add a display object to the display list from your library without explicitly creating a class for it? i.e I have a movieclip in my library, and I just want to bring it onto the stage.

Here's my code...if it helps.

Thanks!

Code:
package {
	
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.display.Stage;
	import Player;
	import HitObject;
	
	public class TestGame extends MovieClip {
		
		private var _hitObject:HitObject; 
		private var _player:Player;
		private var _leftArrow:Boolean;
		private var _rightArrow:Boolean;
		private var _upArrow:Boolean;
		private var _hit:Boolean;
		private var _fall:Boolean;
		private var _jump:Boolean = true;
		private var _velR:Number = 0;
		private var _velL:Number = 0;
		private var _scale:Number = .1;
		private var _jumpCount:Number = 0;
		private var _i:Number = 0;
		private var _adjustHit:Number;
		
		public function TestGame() {
			_hitObject = new HitObject();
			_player = new Player();
			addChild(_hitObject);
			addChild(_player);
			_hitObject.x = (stage.width * 0.5) + 50;
			_hitObject.y = (stage.height * 0.5) + 150;
			_player.scaleX = _scale;
			_player.scaleY = _scale;
			_player.x += 200;
			_player.y += 250;
			stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
			stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
		}
		
		private function enterFrameHandler(e:Event) {
			if(_player.hitTestObject(_hitObject)) {
				_adjustHit = _hitObject.y - _hitObject.height/2 - _player.height/2;
				_player.y = _adjustHit;
				_hit = true;
				_jump = true;
				_jumpCount = 0;
			}
			if(!_player.hitTestObject(_hitObject) && _fall) {
				_player.y += _i;
				_i++;
				if(_i < 5) {
					_i = 5;
				}
				_hit = false;
			}
			if(_upArrow && _hit && _jump) {
				_player.y -= 5;
				_jumpCount += 1;
				_fall = false;
				if(_jumpCount > 15) {
					_jump = false;
					_fall = true;
				}
			}
			if(!_upArrow) {
				_fall = true;
			}
		}
		
		private function keyDownHandler(e:KeyboardEvent):void {
			if(e.keyCode == 39) {
			_rightArrow = true;
			}
			if(e.keyCode == 37) {
			_leftArrow = true;
			}
			if(e.keyCode == 38) {
			_upArrow = true;
			_rightArrow = false;
			_leftArrow = false;
			}
		}
		private function keyUpHandler(e:KeyboardEvent):void {
			_upArrow = false;
			_rightArrow = false;
			_leftArrow = false;
		}
	}
}