Commits

Jake Albano committed d3429a2

Fixed collision problems by adding a collision hull sprite to mobs;
Fixed bug where pressing certain keys would crash the program;
Added flag to projectiles to disable physics;

Comments (0)

Files changed (8)

 		
 		private function addWall(x:Number, y:Number, vertical:Boolean):void
 		{
-			Platforms.push(	addChild(new Platform(x, y, vertical) ) );
+			Platforms.push(	stage.addChild(new Platform(x, y, vertical) ) );
 		}
 		
 		private function addEnemy(x:Number, y:Number):void

src/com/jacobalbano/Input.as

 		{
 			_keyStates = new Vector.<Boolean>;
 			
-			for (var i:uint = 0; i < 127; i++)
+			for (var i:uint = 0; i < 255; i++)
 			{
 				_keyStates.push(false);
 			}

src/ifrit/Enemy.as

 		
 		public function Enemy(x:Number, y:Number) 
 		{
-			super(x, y, Library.IMG("enemy.png"), 13, 23 );
+			super(x, y, Library.IMG("enemy.png"), 13, 23, 13, 23 );
 			this.lastPosition = new Point(x, y);
 			this.heading = true;
 			this.fleeMode = false;

src/ifrit/Fireball.as

 			super(Library.IMG("fireballShot.png"), 25, 10, direction, x, y, friendly);
 			this.animation.add("fly", [0, 1], 7, true);
 			this.animation.play("fly");
+			//this.hasPhysics = true;
 		}
 		
 	}
 		public var velocity:Point = new Point(0, 0);
 		protected var speedLimit:Point;
 		
-		public var collisionHull:Rectangle;
+		public var collisionHull:Sprite;
 		protected var halfSize:Point;
 		
 		public var friendly:Boolean;
 		public var hitpoints:int;
 		public var maxHealth:uint;
 		
-		public function Mob(x:Number, y:Number, bitmap:Bitmap, frameWidth:Number, frameHeight:Number) 
+		public function Mob(x:Number, y:Number, bitmap:Bitmap, frameWidth:Number, frameHeight:Number, collisionWidth:Number, collisionHeight:Number) 
 		{			
 			this.container = new Sprite;
 			addChild(container);
 			this.x = x;
 			this.y = y;
 			
-			this.halfSize = new Point(frameWidth / 2, frameHeight/ 2);
+			this.collisionHull = new Sprite;
+			this.collisionHull.addChild(new Bitmap(new BitmapData(collisionWidth, collisionHeight, false, 0x000000)));
+			this.collisionHull.x = -collisionWidth / 2;
+			this.collisionHull.y = -collisionHeight / 2;
+			
+			this.halfSize = new Point(this.collisionHull.width / 2, this.collisionHull.height / 2);
 			
 			speedLimit = new Point(7, 20);
 			
 			}
 			
 			gravUp = true;
+			
+			this.collisionHull.x = this.x - this.halfSize.x;
+			this.collisionHull.y = this.y - this.halfSize.y;
 		}
 		
 	}

src/ifrit/Platform.as

 		}
 		
 		public function collide(obj:DisplayObject):Boolean 
+		{			
+			var resolve:Function = (obj is Mob) ? resolveAsMob : resolveAsObject;
+			return resolve(obj);
+		}
+		
+		private function resolveAsMob(obj:DisplayObject):Boolean
 		{
 			var dx:Number = this.x - obj.x; // Distance between objects (X)
 			var dy:Number = obj.y - this.y; // Distance between objects (Y)
 			
-			var ox:Number = ( (this.width / 2) + (obj.height / 2) ) - Math.abs(dx); // Overlap on X axis
-			var oy:Number = ( (this.height / 2) + (obj.height / 2) ) - Math.abs(dy); // Overlap on Y axis
-
-			if (this.hitTestObject(obj))
+			var ox:Number = ( (this.width / 2) + ((obj as Mob).collisionHull.height / 2) ) - Math.abs(dx); // Overlap on X axis
+			var oy:Number = ( (this.height / 2) + ((obj as Mob).collisionHull.height / 2) ) - Math.abs(dy); // Overlap on Y axis
+			
+			if (this.hitTestObject((obj as Mob).collisionHull))
 			{
 				if (this.rotation == 0)
 				{
 					if (obj.y <= this.y) // top
 					{
 						obj.y -= oy;
-						
-						if (obj is Mob)
-						{
-							(obj as Mob).gravUp = false;
-							(obj as Mob).jumpTimer.reset();
-						}
+						(obj as Mob).gravUp = false;
+						(obj as Mob).jumpTimer.reset();
+
 						
 					}
 					else if (obj.y >= this.y) // bottom
 					{
 						obj.y += oy;
-						if (obj is Mob)	(obj as Mob).jumpReset();
+						(obj as Mob).jumpReset();
 					}
 					else if (obj.x <= this.x) obj.x -= ox; // left
 					else if (obj.x >= this.x) obj.x += ox; // right
 					else if (obj.y < this.y) // top
 					{
 						obj.y -= oy;
-						if (obj is Mob)
-						{
-							(obj as Mob).gravUp = false;
-							(obj as Mob).jumpTimer.reset();
-						}
+						(obj as Mob).gravUp = false;
+						(obj as Mob).jumpTimer.reset();
 					}
 					else if (obj.y >= this.y) // bottom
 					{
 						obj.y += oy;
-						if (obj is Mob)	(obj as Mob).jumpReset();
+						(obj as Mob).jumpReset();
 					}
 				}
 				
-				
+				return true;
+			}
+			
+			return false;
+		
+		}
+		
+		private function resolveAsObject(obj:DisplayObject):Boolean
+		{
+			var dx:Number = this.x - obj.x; // Distance between objects (X)
+			var dy:Number = obj.y - this.y; // Distance between objects (Y)
+			
+			var ox:Number = ( (this.width / 2) + (obj.height / 2) ) - Math.abs(dx); // Overlap on X axis
+			var oy:Number = ( (this.height / 2) + (obj.height / 2) ) - Math.abs(dy); // Overlap on Y axis
+			
+			if (this.hitTestObject(obj))
+			{
+				if (this.rotation == 0)
+				{
+					if (obj.y <= this.y) // top
+					{
+						obj.y -= oy;						
+					}
+					else if (obj.y >= this.y) // bottom
+					{
+						obj.y += oy;
+					}
+					else if (obj.x <= this.x) obj.x -= ox; // left
+					else if (obj.x >= this.x) obj.x += ox; // right
+				}
+				else 
+				{
+					if (obj.x < this.x) obj.x -= ox; // left
+					else if (obj.x > this.x) obj.x += ox; // right
+					else if (obj.y < this.y) // top
+					{
+						obj.y -= oy;
+					}
+					else if (obj.y >= this.y) // bottom
+					{
+						obj.y += oy;
+					}
+				}
 				
 				return true;
 			}

src/ifrit/Player.as

 	{		
 		public function Player(x:Number, y:Number) 
 		{
-			super( x, y, Library.IMG("mageAtkWalk.png"), 18, 25 );
+			super( x, y, Library.IMG("fighterAtkWalk.png"), 38, 33, 15, 33);
 			this.friendly = true;
 		}
 		

src/ifrit/Projectile.as

 	 */
 	public class Projectile extends Sprite
 	{
-		
+		public var hasPhysics:Boolean;
 		public var animation:Animation;
 		protected var container:Sprite = new Sprite();
 		
 		
 		private function enterFrame(e:Event):void 
 		{
-			this.vy += 0.02;
-			this.y += this.vy;
+			this.update();
+			
+			this.x += dx;
 			
 			/**
 			 * Debugging information; displays trajectory
 			//bmp.y = this.y;
 			//Game.stage.addChild(bmp);
 			
-			this.x += dx;
+			if (!this.hasPhysics) return;
 			
-			this.update();
+			this.vy += 0.02;
+			this.y += this.vy;
 		}
 		
 	}