Leonardo Santagada avatar Leonardo Santagada committed 83b7885

so much stuff, but basicly the only thing missing is an attack table

Comments (0)

Files changed (2)

         /*      [Embed(source="../data/stand01.png")] private var ImgRunner:Class;*/
         public var mydrag:Number=0.6
         public var bombs:FlxGroup
+		public var debugtext:FlxText
 
-        public function Plane(X:Number=0,Y:Number=0, Bombs:FlxGroup=null)
+        public function Plane(X:Number=0,Y:Number=0, Bombs:FlxGroup=null, DebugText:FlxText=null)
         {
             super(X,Y);
+            this.bombs = Bombs
+			this.debugtext = DebugText
             createGraphic(100,100);
-            this.angle = 0
-            this.bombs = Bombs
             this.velocity.x = 100
         }
 
 
         public override function update():void
         {
+			// Draw the plane
             fill(0x000000)
             drawLine(origin.x-8,origin.y+2,origin.x+8,origin.y+2,0xff0000, 3)
             drawLine(origin.x+4,origin.y+2,origin.x+8,origin.y+2,0x00ff00, 2)
 
-            if(FlxG.keys.A){
-                thrust = -200
-            } else {
-                thrust = -50
-            }
-            var thrustComponents:FlxPoint;
-            thrustComponents = FlxU.rotatePoint(-thrust,0,0,0,angle);
-            drawVector(thrustComponents, 0x00ff00)
+			// Sets gravity
+            acceleration.x = 0
+            acceleration.y = 120
 
-            acceleration.x = 0
-            acceleration.y = 100
-            // var velangle:Number = Math.atan2(velocity.y, velocity.x) * (180/Math.PI)
+			var thrustv:FlxPoint, thrustc:Number
 
+			// Two speed motor
+			// thrust is negative because flixel negates them later
+            if(FlxG.keys.A)
+                thrustc = 200
+            else
+                thrustc = 50
 
-            var attackAngle:Number = FlxU.getAngle(velocity.x - thrustComponents.x, velocity.y - thrustComponents.y) + 5
+            thrustv = FlxU.rotatePoint(thrustc, 0, 0, 0 , angle)
 
-            var lift:FlxPoint, liftcoef:Number
-            liftcoef = 0.2 * attackAngle
-            FlxG.log(attackAngle)
-            lift = FlxU.rotatePoint(velocity.x * liftcoef, velocity.y * liftcoef, 0, 0, -90)
-            drawVector(lift, 0x0000ff)
+
+            var velocitya:Number = FlxU.getAngle(velocity.x, velocity.y)
+			var attacka:Number = velocitya - angle + 5
+
+
+            var liftv:FlxPoint, liftc:Number
+			if(attacka < -80 || attacka > 30)
+				liftc = 0.2
+			else
+            	liftc = 0.03 * -attacka
+            debugtext.text = "Attack: " + String(attacka) + "Liftc: " + String(liftc)
+            liftv = FlxU.rotatePoint(velocity.x * liftc, velocity.y * liftc, 0, 0, -90)
+
+            var dragv:FlxPoint, dragc:Number
+			dragc = 0.4
+            dragv = FlxU.rotatePoint(velocity.x * dragc, velocity.y * dragc, 0, 0, 180)
+
+            drawVector(thrustv, 0x00ff00)
+            drawVector(liftv, 0x0000ff)
+            drawVector(dragv, 0xff00ff)
             drawVector(velocity, 0xff00ff)
+			
+			// Sums forces
+            acceleration.x += thrustv.x + liftv.x + dragv.x
+            acceleration.y += thrustv.y + liftv.y + dragv.y
 
-            var drags:FlxPoint = new FlxPoint(0, 0)
-            var dragfactor:Number = 0.2
-            FlxU.rotatePoint(velocity.x * dragfactor, velocity.y * dragfactor, 0, 0, 180, drags)
-
-            acceleration.x += lift.x
-            acceleration.y += lift.y
-            acceleration.x += drags.x
-            acceleration.y += drags.y
+			// drawVector(acceleration, 0xffffff)
 
             if(FlxG.keys.LEFT){
-                angle = (angle - 1) % 360
+                angle = angle - 1
+				if(angle < 0)
+					angle += 360
             }else if(FlxG.keys.RIGHT){
                 angle = (angle + 1) % 360
             }
 		override public function create():void
 		{
 			bombs = new FlxGroup()
-			plane = new Plane(250,150, bombs)
+			var t:FlxText
+			t = new FlxText(FlxG.width-220,FlxG.height-30,200,"Attack: 0 Lift:0")
+			t.alignment = "right"
+			add(t)
+			plane = new Plane(250,150, bombs, t)
 			add(plane)
 			add(bombs)
 		}
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.