Commits

Jake Albano committed 8d64588

Fixed bug where AI would get stuck on obstacles;
Abandoned collision hulls for mobs;

Comments (0)

Files changed (5)

obj/IfritConfig.xml

     </define>
     <define append="true">
       <name>CONFIG::timeStamp</name>
-      <value>'11/6/2011'</value>
+      <value>'11/7/2011'</value>
     </define>
     <verbose-stacktraces>true</verbose-stacktraces>
     <source-path append="true">

src/ifrit/Enemy.as

 		override public function think():void 
 		{
 			super.think();
-			this.rotationY = this.heading ? 0 : 180;
 			
+			this.findPlatform();
+			
+			this.beginFlee();
+			
+			this.endFlee();
+			
+			this.adjustHeading();
+			
+			this.move();
+		}
+		
+		/**
+		 * AI synapse
+		 * Search the platform list and decide which platform, if any, to restrict movement to
+		 */
+		private function findPlatform():void
+		{
 			var found:Boolean = false;
 			for (var i:int = 0; i < Game.Platforms.length; i++) 
 			{
 				this.leftBound = 0;
 				this.rightBound = stage.stageWidth;
 			}
-			
+		}
+		
+		/**
+		 * AI synapse
+		 * Test if hitpoints are at the panic level and begin the flee procedure
+		 */
+		private function beginFlee():void
+		{
 			if ( this.hitpoints <= this.maxHealth / 2 && !fleeMode)
 			{
 				fleeMode = true;
 				if (this.x <= Game.man.x) heading = false;	else heading = true;
 				this.fleeCooldown.start();
 			}
-			
+		}
+		
+		/**
+		 * AI synapse
+		 * Regenerate hitpoints if enough time has gone by and end the flee procedure
+		 */
+		private function endFlee():void
+		{
 			if (this.fleeCooldown.currentCount >= 4)
 			{
 				this.fleeMode = false;
 				this.fleeCooldown.reset();
 				this.hitpoints = this.maxHealth;
 			}
+		}
+		
+		/**
+		 * AI synapse
+		 * Turn around if the edge of a platform is reached or an obstacle is struck
+		 */
+		private function adjustHeading():void
+		{
+			if (heading)	{	if (this.x <= this.lastPosition.x) heading = !heading;	}
+			else			{ 	if (this.x >= this.lastPosition.x) heading = !heading;	}
 			
-			if (this.x == this.lastPosition.x) heading = !heading;
 			if (!fleeMode)
 			{
 				if (this.x >= this.rightBound) heading = false;
 				else if (this.x <= this.leftBound) heading = true;
 			}
+		}
+		
+		/**
+		 * AI synapse
+		 * Update movement
+		 */
+		private function move():void
+		{
+			this.lastPosition.x = this.x;
 			
-			this.lastPosition.x = this.x;
+			this.rotationY = this.heading ? 0 : 180;
 			
 			if (fleeMode)
 			{
 			}
 			else
 			{
-				if (heading) this.x += 1;  else x -= 1;
+				if (heading) this.x += 1 + this.speed;  else x -= 1 + speed;
 			}
 		}
 		
+		
 	}
 
 }
 		public var velocity:Point = new Point(0, 0);
 		protected var speedLimit:Point;
 		
-		public var collisionHull:Bitmap;
+		public var collisionHull:Rectangle;
 		protected var halfSize:Point;
 		
 		public var friendly:Boolean;
 			container.y = -frameHeight / 2;
 			container.addChild(graphic);
 			
-			var bounds:BitmapData = new BitmapData(frameWidth, frameHeight, true, 0);
-			bounds.draw(this.container);
-			
-			var rect:Rectangle = bounds.getColorBoundsRect(0xFFFFFF, 0x00000000, false);
-			this.collisionHull = new Bitmap(new BitmapData(rect.width, rect.height, true, 0) );
 			
 			this.x = x;
 			this.y = y;

src/ifrit/Platform.as

 			
 			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)
 			
 			return false;
 		}
-		
 	}
 }
 

src/ifrit/Player.as

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