Commits

Leonardo Santagada committed d92a969

first

  • Participants

Comments (0)

Files changed (6)

+Add this: "-defaults-css-url Default.css"
+to the project's additonal compiler arguments.
+package
+{
+	import org.flixel.*;
+
+	public class MenuState extends FlxState
+	{
+		override public function create():void
+		{
+			var t:FlxText;
+			t = new FlxText(0,FlxG.height/2-10,FlxG.width,"flything");
+			t.size = 16;
+			t.alignment = "center";
+			add(t);
+			t = new FlxText(FlxG.width/2-50,FlxG.height-20,100,"click to play");
+			t.alignment = "center";
+			add(t);
+
+			FlxG.mouse.show();
+		}
+
+		override public function update():void
+		{
+			super.update();
+
+			if(FlxG.mouse.justPressed())
+			{
+				FlxG.mouse.hide();
+				FlxG.state = new PlayState();
+			}
+		}
+	}
+}
+package
+{
+	import org.flixel.*;
+
+	public class Plane extends FlxSprite
+	{
+/*		[Embed(source="../data/stand01.png")] private var ImgRunner:Class;*/
+		public var mydrag:Number=0.6
+		public var bombs:FlxGroup
+
+		public function Plane(X:Number=0,Y:Number=0, Bombs:FlxGroup=null)
+		{
+			super(X,Y);
+			createGraphic(16,8);
+			drawLine(0,4,16,4,0xff0000, 3)
+			drawLine(12,4,16,4,0x00ff00, 2)
+			angle = 180
+			velocity.x = 100
+			bombs = Bombs
+		}
+		
+		public function apply_drag(Velocity:Number,Drag:Number):Number
+		{
+			var d:Number = Drag*FlxG.elapsed;
+			if(Velocity - d > 0)
+				Velocity = Velocity - d
+			else if(Velocity + d < 0)
+				Velocity += d
+			else
+				Velocity = 0
+			return Velocity
+		}
+		
+		public override function update():void
+		{
+			
+        	if(FlxG.keys.A){
+				thrust = 200
+			} else {
+				thrust = 100
+			}
+			acceleration.y = 100
+
+			/* simulate gravity on the propeler thrust directly */
+			if(angle < 180)
+				thrust = thrust /** Math.abs(Math.cos(angle * -0.017453293))*/
+			else
+				thrust = thrust /** Math.abs(Math.sin(angle * -0.017453293))*/
+			
+			
+			/* Drag force, for now constant */
+			var velangle:Number = Math.atan2(velocity.y, velocity.x) * (180/Math.PI)
+
+			var lift:FlxPoint = new FlxPoint(0,0)
+			var liftcoef:Number = 10 * FlxG.elapsed
+			FlxU.rotatePoint(velocity.x * liftcoef, velocity.y * liftcoef, 0, 0, 90, lift)
+	
+
+			var drags:FlxPoint = new FlxPoint(0, 0)
+			var dragfactor:Number = 5 * FlxG.elapsed
+			FlxU.rotatePoint(velocity.x * dragfactor, velocity.y * dragfactor, 0, 0, 180, drags)
+
+			velocity.x += lift.x
+			velocity.y += lift.y
+			velocity.x += drags.x
+			velocity.y += drags.y
+
+/*			FlxU.rotatePoint(40, 0, 0, 0, velangle, drags)
+			velocity.x = velocity.x - (drags.x * FlxG.elapsed)
+			velocity.y = velocity.y - (drags.y * FlxG.elapsed)
+*/
+/*			var linearvel:Number = Math.sqrt(velocity.x*velocity.x + velocity.y* velocity.y)
+
+			if(linearvel > 30)
+				acceleration.y = 0
+			else
+				acceleration.y = (30 - linearvel) * 2
+*/
+			
+			if(FlxG.keys.LEFT){
+				angle = (angle - 1) % 360
+			}else if(FlxG.keys.RIGHT){
+				angle = (angle + 1) % 360
+			}
+			
+			if(FlxG.keys.justPressed('X'))
+			{
+				var s:FlxSprite = new FlxSprite(x+width/2, y+height/2)
+				s.createGraphic(4,4)
+				s.velocity.x = velocity.x
+				s.velocity.y = velocity.y
+				s.acceleration.y = 100
+				s.maxVelocity.y = 200
+				bombs.add(s)
+			}
+
+       		super.update();
+		}
+	}
+}
+package
+{
+	import org.flixel.*;
+
+	public class PlayState extends FlxState
+	{
+		
+		public var plane:Plane
+		public var bombs:FlxGroup
+		
+		override public function create():void
+		{
+			bombs = new FlxGroup()
+			plane = new Plane(250,150, bombs)
+			add(plane)
+			add(bombs)
+		}
+	}
+}
+package
+{
+	import org.flixel.*;
+
+	public class Preloader extends FlxPreloader
+	{
+		public function Preloader()
+		{
+			className = "flything";
+			super();
+		}
+	}
+}
+package
+{
+	import org.flixel.*;
+	[SWF(width="1024", height="640", backgroundColor="#000000")]
+	[Frame(factoryClass="Preloader")]
+
+	public class flything extends FlxGame
+	{
+		public function flything()
+		{
+			super(1024,640,MenuState,1);
+		}
+	}
+}