Commits

Jake Albano committed 17dbaf1

Various name changes for clarity and consistancy;
Added projectile classes to repository;

Comments (0)

Files changed (6)

 package ifrit 
 {
 	import flash.display.Bitmap;
+	import flash.display.BitmapData;
 	import flash.display.Sprite;
 	import flash.events.Event;
 	import flash.geom.Point;
+	import flash.geom.Rectangle;
 	import flash.utils.Timer;
 	
 	import com.jacobalbano.Animation;
 		public var velocity:Point = new Point(0, 0);
 		protected var speedLimit:Point;
 		
+		public var collisionHull:Bitmap;
 		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

 	
 	public class Platform extends Sprite
 	{		
-		public var hWall:Bitmap = Library.IMG("horizontal.png");
-		public var hWallC:Sprite = new Sprite();
+		public var bitmap:Bitmap = Library.IMG("horizontal.png");
+		public var container:Sprite = new Sprite();
 		
 		public function Platform(x:Number, y:Number, vertical:Boolean) 
 		{
-			addChild(hWallC);
+			addChild(container);
 			
-			hWallC.x = hWall.x - (hWall.width / 2);
-			hWallC.y = hWall.y - (hWall.height / 2);
+			container.x = bitmap.x - (bitmap.width / 2);
+			container.y = bitmap.y - (bitmap.height / 2);
 			
 			this.x = x;
 			this.y = y;
 			if (vertical) this.rotation = 90;
 			else this.rotation = 0;
 			
-			hWallC.addChild(hWall);
+			container.addChild(bitmap);
 		}
 		
 		public function collide(obj:DisplayObject):Boolean 
 		{
-			var objHalfW:Number = obj.width / 2;
-			var objHalfH:Number = obj.height / 2;
-			var thisHalfW:Number = this.width / 2;
-			var thisHalfH:Number = this.height / 2;
-			
 			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 = (thisHalfW + objHalfW) - Math.abs(dx); // Overlap on X axis
-			var oy:Number = (thisHalfH + objHalfH) - Math.abs(dy); // Overlap on Y axis
+			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))
 			{
 			
 			return false;
 		}
+		
 	}
 }
 
-//BUG: Strange results if player touching >1 platform at a time
-/*
- * 
- */

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 );
 			this.friendly = true;
 		}
 		

src/ifrit/Projectile.as

+package ifrit 
+{
+	import com.jacobalbano.Animation;
+	import flash.display.BitmapData;
+	
+	import flash.display.Bitmap;
+	import flash.display.Sprite;
+	import flash.events.Event;
+	
+	/**
+	 * ...
+	 * @author jake
+	 */
+	public class Projectile extends Sprite
+	{
+		
+		public var animation:Animation;
+		protected var container:Sprite = new Sprite();
+		
+		protected var dx:int;
+		protected var vy:Number;
+		
+		public var friendly:Boolean;
+		
+		public function Projectile(bitmap:Bitmap, frameWidth:int, frameHeight:int, direction:int, x:Number, y:Number, friendly:Boolean = true) 
+		{
+			addChild(container);
+			
+			this.animation = new Animation(bitmap, frameWidth, frameHeight);
+			
+			container.x = -frameWidth /2;
+			container.y = -frameHeight /2;
+			
+			container.addChild(animation);
+			
+			dx = direction;
+			this.x = x;
+			this.y = y;
+			
+			vy = 0;
+			this.friendly = friendly;
+			
+			addEventListener(Event.ENTER_FRAME, enterFrame);
+			
+			this.rotationY = direction > 0 ? 0 : 180;
+		}
+		
+		/**
+		 * Override this; called in enterFrame
+		 */
+		public function update():void
+		{
+			
+		}
+		
+		public function destroy():void
+		{
+			removeEventListener(Event.ENTER_FRAME, enterFrame);
+		}
+		
+		private function enterFrame(e:Event):void 
+		{
+			this.vy += 0.02;
+			this.y += this.vy;
+			
+			/**
+			 * Debugging information; displays trajectory
+			 * Uncomment the lines below to see in action
+			 */
+			//var bmp:Bitmap = new Bitmap(new BitmapData(10, 1, false, 0xff0000));
+			//bmp.x = this.x;
+			//bmp.y = this.y;
+			//Game.stage.addChild(bmp);
+			
+			this.x += dx;
+			
+			this.update();
+		}
+		
+	}
+
+}

src/ifrit/Rules.as

 package ifrit 
 {
-	/**
-	 * ...
-	 * @author ...
-	 */
 	public final class Rules 
 	{
 		public static const gravity:Number = 1;

src/ifrit/Shuriken.as

+package ifrit 
+{
+	import com.jacobalbano.Animation;
+	import com.thaumaturgistgames.flakit.Library;
+	import flash.display.BitmapData;
+	
+	import flash.display.Bitmap;
+	import flash.display.Sprite;
+	import flash.events.Event;
+	/**
+	 * ...
+	 * @author Chris Logsdon
+	 */
+	public class Shuriken extends Projectile
+	{
+		
+		public function Shuriken(direction:int, x:Number, y:Number, friendly:Boolean = true) 
+		{
+			super(Library.IMG("shuriken.png"), 10, 10, direction, x, y, friendly );
+		}
+		
+		override public function update():void 
+		{
+			super.update();
+			if (dx < 0) { this.rotation -= 20; }
+			else if (dx > 0) { this.rotation += 20; }
+		}
+		
+	}
+
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.