Commits

Jake Albano committed 3bf7f03 Merge

Merge

  • Participants
  • Parent commits 5fb170e, 53ed1d2

Comments (0)

Files changed (5)

obj/IfritConfig.old

File contents unchanged.

obj/IfritConfig.xml

File contents unchanged.

src/Game.as

File contents unchanged.

src/ifrit/HorizontalWall.as

+package ifrit 
+{
+	import com.thaumaturgistgames.flakit.Library;
+	
+	import flash.display.Bitmap;
+	import flash.display.DisplayObject;
+	import flash.display.Sprite;
+	import flash.events.Event;
+	
+	
+	//TODO: block any and all objects
+	/*
+	 * Put all objects into an array and have each wall 
+	 * block every element in that object array
+	 */
+	public class HorizontalWall extends Sprite
+	{		
+		public var hWall:Bitmap = Library.IMG("horizontal.png");
+		public var hWallC:Sprite = new Sprite();
+		
+		private var obj:DisplayObject;
+		
+		public function HorizontalWall(object:DisplayObject, x:Number, y:Number, vertical:Boolean) 
+		{
+			addChild(hWallC);
+			
+			hWallC.x = hWall.x - (hWall.width / 2);
+			hWallC.y = hWall.y - (hWall.height / 2);
+			
+			this.x = x;
+			this.y = y;
+			
+			if (vertical) this.rotation = 90;
+			else this.rotation = 0;
+			
+			hWallC.addChild(hWall);
+			
+			obj = object;
+			
+			addEventListener(Event.ENTER_FRAME, enterFrame);
+		}
+		
+		private function enterFrame(e:Event):void 
+		{
+			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
+			
+			if (this.hitTestObject(obj))
+			{
+				if (this.rotation == 0)
+				{
+					if (obj.y < this.y) // top
+					{
+						obj.y -= oy;
+						Man.gravUp = false;
+						Man.jumpTimer.reset();
+					}
+					else if (obj.y > this.y) // bottom
+					{
+						Man.vy = 0;
+						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;
+						Man.gravUp = false;
+						Man.jumpTimer.reset();
+					}
+					else if (obj.y >= this.y) // bottom
+					{
+						obj.y += oy;
+						Man.vy = 0;
+					}
+				}
+			}
+			
+			//trace("obj x: " + obj.x);
+			//trace("obj y: " + obj.y);
+			//trace("ox: " + ox);
+			//trace("oy: " + oy);
+			//trace("dx: " + dx);
+			//trace("dy: " + Math.abs(dy));
+			//trace("objHalfW: " + objHalfW);
+			//trace("objHalfH: " + objHalfH);
+			//trace("thisHalfW: " + thisHalfW);
+			//trace("thisHalfH: " + thisHalfH);
+			//trace("this x: " + this.x);
+			//trace("this y: " + this.y);
+			//trace("----------------------");
+		} // end enter frame
+	}
+}
+
+//BUG: player forced down if touching >1 platform at a time
+/*
+ * 
+ */
+package ifrit 
+{
+	import com.thaumaturgistgames.flakit.Library;
+	
+	import flash.display.Sprite;
+	import flash.display.Bitmap;
+	import flash.events.Event;
+	import flash.utils.Timer;
+	
+	/**
+	 * ...
+	 * @author Chris Logsdon
+	 */
+	public class Man extends Sprite
+	{		
+		private var man:Bitmap = Library.IMG("rogue.png");
+		private var manC:Sprite = new Sprite;
+		
+		public static var vx:Number;
+		public static var vy:Number;
+		private var speedLimitX:Number;
+		private var speedLimitY:Number;
+		private var jumpSpeedLimit:Number;
+		
+		public static var gravity:Number;
+		
+		public static var L:Boolean;
+		public static var R:Boolean;
+		public static var SB:Boolean; // spacebar
+		
+		public static var jumpTimer:Timer = new Timer(0, 2);
+		
+		public static var gravUp:Boolean;
+		
+		public function Man(x:Number, y:Number) 
+		{
+			addChild(manC);
+			manC.x = man.x - (man.width / 2);
+			manC.y = man.y - (man.height / 2);
+			man.smoothing = true;
+			manC.addChild(man);
+			
+			this.x = x;
+			this.y = y;
+			
+			vx = 0;
+			vy = 0;
+			speedLimitX = 7;
+			speedLimitY = 20;
+			jumpSpeedLimit = 7;
+			gravity = 1;
+			
+			addEventListener(Event.ENTER_FRAME, onEnterFrame);
+		}
+		
+		
+		//BUG: Upward thrust when player hits corner of platform
+		private function onEnterFrame(e:Event):void
+		{
+			trace(vy);
+			
+			if (gravUp)	vy += gravity;
+			else vy = 0;
+			
+			// Jump(rise) until spacebar up or until timer ends.
+			if (SB && jumpTimer.currentCount < jumpTimer.repeatCount && vy <= 1)
+			{
+				if (!jumpTimer.running) {  jumpTimer.start();  }
+				
+				vy += -5;
+			}
+			if (jumpTimer.currentCount == jumpTimer.repeatCount) {  jumpTimer.stop();  }
+			
+			if (vx >= speedLimitX) {  vx = speedLimitX;  }
+			if (vx < -speedLimitX) {  vx = -speedLimitX;  }
+			if (vy >= speedLimitY) {  vy = speedLimitY;  }
+			if (vy < -jumpSpeedLimit) {  vy = -jumpSpeedLimit;  }
+			
+			// Apply physics to player movement
+			this.x += vx;
+			this.y += vy;
+			
+			// Stage boundaries
+			var thisHalfW:uint = (this.width / 2);
+			var thisHalfH:uint = (this.height / 2);
+			if (this.x + thisHalfW > stage.stageWidth)
+			{
+				this.x = stage.stageWidth - thisHalfW;
+				vx = 0;
+			}
+			if (this.x - thisHalfW < 0)
+			{
+				this.x = 0 + thisHalfW;
+				vx = 0;
+			}
+			if (this.y + thisHalfH > stage.stageHeight)
+			{
+				vy = 0;
+				this.y = stage.stageHeight - thisHalfH;
+				
+				jumpTimer.reset();
+			}
+			if (this.y - thisHalfH < 0)
+			{
+				vy = 0;
+				this.y = 0 + thisHalfH;
+			}
+			
+			gravUp = true;
+		} // End enter frame
+	}
+}