public void InitializeConsoleFormWriter( Action <string> Console_Write, Action <string> Console_WriteLine ) { var w = new __OutWriter(); var o = Console.Out; var __reentry = false; w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.SetOut(w); }
public void InitializeConsoleFormWriter( Action<string> Console_Write, Action<string> Console_WriteLine ) { var w = new __OutWriter(); var o = Console.Out; var __reentry = false; w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.SetOut(w); }
/* * 1. add starling */ public ApplicationSprite() { this.loaderInfo.uncaughtErrorEvents.uncaughtError += e => { Console.WriteLine("error: " + new { e.errorID, e.error, e } +"\n run in flash debugger for more details!"); }; #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion this.InvokeWhenStageIsReady( delegate { Initialize(); var shop = new ShopExperience(this); StarlingGameSpriteWithShop.ShopEnter += ped => { // no go //if (ApplicationSpriteWithConnection.CurrentClient == null) // return; //shop.ShopEnter(ped); }; StarlingGameSpriteWithShop.ShopExit += shop.ShopExit; } ); }
public ApplicationSprite() { #region __transport for (int i = 0; i < 7; i++) { lag.Enqueue(new List<string>()); } var lagtimer = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 15); lagtimer.timer += delegate { lag.Enqueue(PendingInput); PendingInput = lag.Dequeue(); foreach (var xml in PendingInput) { this.__transport_in(xml); } PendingInput.Clear(); }; lagtimer.start(); StarlingGameSpriteWithPedSync.__raise_sync += egoid => { // Error 8 Argument 1: cannot convert from 'System.Xml.Linq.XAttribute' to 'System.Xml.Linq.XStreamingElement' X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPedSync\ApplicationSprite.cs 40 33 FlashHeatZeeker.UnitPedSync var xml = new XElement("sync", new XAttribute("egoid", egoid)); if (__transport_out != null) __transport_out(xml.ToString()); }; StarlingGameSpriteWithPedSync.__raise_SetVelocityFromInput += ( string __egoid, string __identity, string __KeySample, string __fixup_x, string __fixup_y, string __fixup_angle ) => { var xml = new XElement("SetVelocityFromInput", new XAttribute("egoid", __egoid), new XAttribute("i", __identity), new XAttribute("k", __KeySample), new XAttribute("x", __fixup_x), new XAttribute("y", __fixup_y), new XAttribute("angle", __fixup_angle) ); if (__transport_out != null) __transport_out(xml.ToString()); }; #endregion #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion this.InvokeWhenStageIsReady( delegate { // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(StarlingGameSpriteWithPedSync).ToClassToken(), this.stage ); //Starling.current.showStats s.showStats = true; #region atresize Action atresize = delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; //b2stage_centerize(); }; atresize(); #endregion StarlingGameSpriteBase.onresize = yield => { this.stage.resize += delegate { atresize(); yield(this.stage.stageWidth, this.stage.stageHeight); }; yield(this.stage.stageWidth, this.stage.stageHeight); }; this.stage.enterFrame += delegate { StarlingGameSpriteBase.onframe(this.stage, s); }; s.start(); } ); }
public static void Initialize() { #region ConsoleFormPackageExperience #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion ExternalInterface.call("setTimeout", "window.__check__SystemConsoleWrite = function (e) { return '__SystemConsoleWrite' in window; };", 0); #region function2 ExternalInterface.call("setTimeout", @"window.function2 = function (e) { console.log('length: ' + e.length); // debugger; var f = null; //try //{ f = eval(e); console.log('done!'); //} //catch (err) //{ // console.log('error! ' + err); // console.log('typeof f: ' + typeof f); // console.log('f: ' + f); //} return 0; };", 0); #endregion #region yield_to_sprite Action<string> yield_to_sprite = delegate { // check again! try { var value = (bool)ExternalInterface.call("__check__SystemConsoleWrite"); Diagnostics("yield_to_sprite: " + new { value }.ToString()); if (value) { InitializeConsoleFormWriter(); } else { // reload javascript // await when ready //reload(); } } catch (Exception ex) { Diagnostics("error? " + new { ex.Message }); } }; #endregion ExternalExtensions.TryAddCallback("WhenReady", yield_to_sprite.ToFunction()); 100.AtDelay( delegate { #region reload Action reload = delegate { var source = KnownEmbeddedResources.Default["assets/Abstractatech.ActionScript.ConsoleFormPackage/view-source"].ToStringAsset(); var q = source; //.Substring(x, 16); q = q.Replace("\\", "\\\\"); try { ExternalInterface.call("function2", q); } catch (Exception ex) { //content.t.Text = "error? " + new { ex.Message, ex.StackTrace }; } }; #endregion try { var value = (bool)ExternalInterface.call("__check__SystemConsoleWrite"); Diagnostics("InvokeWhenStageIsReady: " + new { value }.ToString()); if (value) { InitializeConsoleFormWriter(); } else { // reload javascript // await when ready reload(); } } catch (Exception ex) { Diagnostics("error? " + new { ex.Message }); } #endregion } ); }
public ApplicationSprite() { #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion var SCALE = 15; //how many pixels in a meter var WIDTH_M = DefaultWidth / SCALE; //world width in meters. for this example, world is as large as the screen var HEIGHT_M = DefaultHeight / SCALE; //world height in meters //initialize font to draw text with //var font=new gamejs.font.Font('16px Sans-serif'); //key bindings //var BINDINGS={accelerate:gamejs.event.K_UP, // brake:gamejs.event.K_DOWN, // steer_left:gamejs.event.K_LEFT, // steer_right:gamejs.event.K_RIGHT}; //initialize display //var display = gamejs.display.setMode([WIDTH_PX, HEIGHT_PX]); //SET UP B2WORLD var b2world = new b2World(new b2Vec2(0, 0), false); //set up box2d debug draw to draw the bodies for us. //in a real game, car will propably be drawn as a sprite rotated by the car's angle var debugDraw = new b2DebugDraw(); debugDraw.SetSprite(this); debugDraw.SetDrawScale(SCALE); debugDraw.SetFillAlpha(0.5); debugDraw.SetLineThickness(1.0); debugDraw.SetFlags(b2DebugDraw.e_shapeBit); b2world.SetDebugDraw(debugDraw); var wheels = new[] { //top left new Wheel(b2world: b2world, x: -1, y: -1.2, width: 0.4, length: 0.8, revolving: true, powered: true), //top right new Wheel(b2world: b2world, x: 1, y: -1.2, width: 0.4, length: 0.8, revolving: true, powered: true), //back left new Wheel(b2world: b2world, x: -1, y: 1.2, width: 0.4, length: 0.8, revolving: false, powered: false), //back right new Wheel(b2world: b2world, x: 1, y: 1.2, width: 0.4, length: 0.8, revolving: false, powered: false), }; Func <double, double, double[]> ff = (a, b) => { return(new double[] { a, b }); }; ////initialize car var car = new Car( b2world: b2world, width: 2, length: 4, position: ff(10, 10), angle: 180, power: 60, max_steer_angle: 20, max_speed: 60, wheels: wheels ); var xcar = new Car( b2world: b2world, width: 2, length: 4, position: ff(5, 10), angle: 180, power: 60, max_steer_angle: 20, max_speed: 60, wheels: wheels ); //initialize some props to bounce against var props = new List <BoxProp>(); //outer walls props.Add(new BoxProp(b2world, size: ff(WIDTH_M, 1), position: ff(WIDTH_M / 2, 0.5))); props.Add(new BoxProp(b2world, size: ff(1, HEIGHT_M - 2), position: ff(0.5, HEIGHT_M / 2))); props.Add(new BoxProp(b2world, size: ff(WIDTH_M, 1), position: ff(WIDTH_M / 2, HEIGHT_M - 0.5))); props.Add(new BoxProp(b2world, size: ff(1, HEIGHT_M - 2), position: ff(WIDTH_M - 0.5, HEIGHT_M / 2))); //pen in the center var center = new double[] { WIDTH_M / 2, HEIGHT_M / 2 }; props.Add(new BoxProp(b2world, size: ff(1, 6), position: ff(center[0] - 3, center[1]))); props.Add(new BoxProp(b2world, size: ff(1, 6), position: ff(center[0] + 3, center[1]))); props.Add(new BoxProp(b2world, size: ff(5, 1), position: ff(center[0], center[1] + 2.5))); var frameid = 0; var KEYS_DOWN = new Dictionary <Keys, bool> { { Keys.Left, false }, { Keys.Up, false }, { Keys.Right, false }, { Keys.Down, false }, }; //keep track of what keys are held down by the player this.stage.keyDown += e => { Console.WriteLine("keyDown " + new { e.keyCode }); KEYS_DOWN[(Keys)e.keyCode] = true; }; this.stage.keyUp += e => { Console.WriteLine("keyUp " + new { e.keyCode }); KEYS_DOWN[(Keys)e.keyCode] = false; }; #region tick Action <double> tick = (msDuration) => { frameid++; //if (frameid > 1) // return; //Console.WriteLine(new { frameid }); //GAME LOOP //handle events. Key status (depressed or no) is tracked in via KEYS_DOWN associative array //gamejs.event.get().forEach(function(event){ // //key press // if (event.type === gamejs.event.KEY_DOWN) KEYS_DOWN[event.key] = true; // //key release // else if (event.type === gamejs.event.KEY_UP) KEYS_DOWN[event.key] = false; //}); //set car controls according to player input if (KEYS_DOWN[Keys.Up]) { car.accelerate = ACC_ACCELERATE; } else if (KEYS_DOWN[Keys.Down]) { car.accelerate = ACC_BRAKE; } else { car.accelerate = ACC_NONE; } if (KEYS_DOWN[Keys.Right]) { car.steer = STEER_RIGHT; } else if (KEYS_DOWN[Keys.Left]) { car.steer = STEER_LEFT; } else { car.steer = STEER_NONE; } ////update car car.update(msDuration); //update physics world b2world.Step(msDuration / 1000.0, 10, 8); //clear applied forces, so they don't stack from each update b2world.ClearForces(); //fill background //gamejs.draw.rect(display, '#FFFFFF', new gamejs.Rect([0, 0], [WIDTH_PX, HEIGHT_PX]),0) //let box2d draw it's bodies b2world.DrawDebugData(); //fps and car speed display //display.blit(font.render('FPS: '+parseInt((1000)/msDuration)), [25, 25]); //display.blit(font.render('SPEED: '+parseInt(Math.ceil(car.getSpeedKMH()))+' km/h'), [25, 55]); //Console.WriteLine(new { frameid } + " done!"); }; ////gamejs.time.fpsCallback(tick, this, 60); var sw = new Stopwatch(); sw.Start(); this.enterFrame += delegate { tick(sw.ElapsedMilliseconds); sw.Restart(); }; #endregion }
/* * 1. add starling */ public ApplicationSprite() { this.loaderInfo.uncaughtErrorEvents.uncaughtError += e => { Console.WriteLine("error: " + new { e.errorID, e.error, e } + "\n run in flash debugger for more details!"); }; #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion this.InvokeWhenStageIsReady( delegate { Initialize(); var shop = new ShopExperience(this); StarlingGameSpriteWithShop.ShopEnter += ped => { // no go //if (ApplicationSpriteWithConnection.CurrentClient == null) // return; //shop.ShopEnter(ped); }; StarlingGameSpriteWithShop.ShopExit += shop.ShopExit; } ); }
public ApplicationSprite() { __stage = this.stage; // there can only be one in this VM. :) __sprite = this; // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(Game).ToClassToken(), this.stage ); s.start(); #region resize // http://forum.starling-framework.org/topic/starling-stage-resizing this.stage.resize += delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; }; s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; #endregion #region AtInitializeConsoleFormWriter this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { try { var w = new __OutWriter(); var o = Console.Out; var __reentry = false; w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.SetOut(w); Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); } catch { } }; #endregion this.stage.keyUp += e => { if (e.keyCode == (uint)System.Windows.Forms.Keys.F11) { this.stage.SetFullscreen(true); } }; }
public ApplicationSprite() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; #region bg fill var fill = new Sprite().AttachTo(this); fill.graphics.beginFill(0xA26D41); fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight); this.stage.resize += delegate { fill.graphics.beginFill(0xA26D41); fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight); }; #endregion var egocenter = new Sprite(); var egorotation = new Sprite().AttachTo(egocenter); var map = new Sprite().AttachTo(egorotation); map.graphics.beginFill(0xB27D51); map.graphics.drawRect(0, 0, 4000, 400); // http://wiki.openoffice.org/wiki/SVG_User_Experiences //Enclosed Exception: //The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: flowRoot). // [Embed(source = "/assets/FlashHeatZeeker/touchdown.svg", mimeType = "image/svg-xml")] // ^ //U:\web\FlashHeatZeeker\ApplicationSprite.as(104): col: 9: Error: Unable to transcode /assets/FlashHeatZeeker/touchdown.svg. KnownEmbeddedResources.Default["assets/FlashHeatZeeker/touchdown.svg"].ToSprite().AttachTo(map).MoveTo(100, 0).With( svg => { svg.scaleX = 0.5; svg.scaleY = 0.5; } ); // unit 1 Func <GameUnit> greentank = delegate { var unit1_loc = new Sprite().AttachTo(map); var unit1_rot = new Sprite().AttachTo(unit1_loc); KnownEmbeddedResources.Default["assets/FlashHeatZeeker/greentank.svg"].ToSprite().AttachTo(unit1_rot).MoveTo(-200, -200); return(new GameUnit { loc = unit1_loc, rot = unit1_rot }); }; var unit1 = greentank(); var unit2 = greentank(); var unit3 = greentank(); unit1.loc.MoveTo(300, 200); unit2.loc.MoveTo(0, 400); var CurrentUnit = unit1; KnownEmbeddedResources.Default["assets/FlashHeatZeeker/hill0.svg"].ToSprite().AttachTo(map).MoveTo(0, 0).With( svg => { svg.scaleX = 0.2; svg.scaleY = 0.2; } ); for (int iy = 0; iy < 128; iy++) { KnownEmbeddedResources.Default["assets/FlashHeatZeeker/tree0.svg"].ToSprite().AttachTo(map).MoveTo(400, 0).With( svg => { svg.cacheAsBitmap = true; svg.scaleX = 0.2; svg.scaleY = 0.2; if (iy % 3 == 0) { svg.y += 50; } if (iy % 3 == 1) { svg.y += 100; } svg.x += 15 * iy; } ); } for (int iy = 0; iy < 128; iy++) { KnownEmbeddedResources.Default["assets/FlashHeatZeeker/tree0.svg"].ToSprite().AttachTo(map).MoveTo(400, 0).With( svg => { svg.y += 300; svg.cacheAsBitmap = true; svg.scaleX = 0.2; svg.scaleY = 0.2; if (iy % 3 == 0) { svg.y += 50; } if (iy % 3 == 1) { svg.y += 100; } svg.x += 15 * iy; } ); } // ego is in center map.MoveTo(-300, -200); this.stage.keyUp += e => { //Console.WriteLine("keyUp " + new { e.keyCode }); if (e.keyCode == (uint)System.Windows.Forms.Keys.D3) { CurrentUnit = unit3; egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); } if (e.keyCode == (uint)System.Windows.Forms.Keys.D1) { CurrentUnit = unit1; egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); } if (e.keyCode == (uint)System.Windows.Forms.Keys.D2) { CurrentUnit = unit2; egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); } if (e.keyCode == (uint)System.Windows.Forms.Keys.F11) { this.stage.SetFullscreen(true); } }; this.stage.keyDown += e => { //Console.WriteLine("keyDown " + new { e.keyCode }); if (e.keyCode == (uint)System.Windows.Forms.Keys.Up) { CurrentUnit.loc.x += 2 * Math.Cos((CurrentUnit.rot.rotation + 270).DegreesToRadians()); CurrentUnit.loc.y += 2 * Math.Sin((CurrentUnit.rot.rotation + 270).DegreesToRadians()); } if (e.keyCode == (uint)System.Windows.Forms.Keys.Down) { CurrentUnit.loc.x += -2 * Math.Cos((CurrentUnit.rot.rotation + 270).DegreesToRadians()); CurrentUnit.loc.y += -2 * Math.Sin((CurrentUnit.rot.rotation + 270).DegreesToRadians()); } if (e.keyCode == (uint)System.Windows.Forms.Keys.Left) { CurrentUnit.rot.rotation -= 5; } if (e.keyCode == (uint)System.Windows.Forms.Keys.Right) { CurrentUnit.rot.rotation += 5; } egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); }; #region egocrosshair var egocrosshair = new Sprite().AttachTo(egocenter); egocrosshair.graphics.lineStyle(2, 0x007f00, 1); egocrosshair.graphics.moveTo(-32, 0); egocrosshair.graphics.lineTo(32, 0); egocrosshair.graphics.moveTo(0, -32); egocrosshair.graphics.lineTo(0, 32); #endregion egocenter.AttachTo(this); egocenter.MoveTo(this.stage.stageWidth / 2, this.stage.stageHeight / 2); this.stage.resize += delegate { egocenter.MoveTo(this.stage.stageWidth / 2, this.stage.stageHeight / 2); }; #region AtInitializeConsoleFormWriter this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { try { var w = new __OutWriter(); var o = Console.Out; var __reentry = false; w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.SetOut(w); Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); } catch { } }; #endregion var info = new TextField { selectable = false, mouseEnabled = false, autoSize = TextFieldAutoSize.LEFT }.AttachTo(this).MoveTo(8, 8); var maxframe = new Stopwatch(); var maxframe_elapsed = 0.0; #region fps var sw = new Stopwatch(); sw.Start(); var ii = 0; maxframe.Start(); this.enterFrame += delegate { maxframe.Stop(); // System.TimeSpan for Boolean op_GreaterThan(System.TimeSpan, System.TimeSpan) used at //FlashHeatZeeker.ApplicationSprite+<>c__DisplayClass11.<.ctor>b__d at offset 001e. // TypeError: Error #1009: Cannot access a property or method of a null object reference. //at FlashHeatZeeker::ApplicationSprite___c__DisplayClass11/__ctor_b__d_100663322()[U:\web\FlashHeatZeeker\ApplicationSprite___c__DisplayClass11.as:141] if (maxframe.Elapsed.TotalMilliseconds > maxframe_elapsed) { maxframe_elapsed = maxframe.Elapsed.TotalMilliseconds; } if (sw.ElapsedMilliseconds < 1000) { ii++; maxframe.Restart(); return; } info.text = new { fps = ii, maxframe_elapsed }.ToString(); //if (fps != null) // fps("" + ii); ii = 0; maxframe_elapsed = 0; sw.Restart(); }; #endregion }
public ApplicationSprite() { #region __transport for (int i = 0; i < 7; i++) { lag.Enqueue(new List <string>()); } var lagtimer = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 15); lagtimer.timer += delegate { lag.Enqueue(PendingInput); PendingInput = lag.Dequeue(); foreach (var xml in PendingInput) { this.__transport_in(xml); } PendingInput.Clear(); }; lagtimer.start(); StarlingGameSpriteWithPedSync.__raise_sync += egoid => { // Error 8 Argument 1: cannot convert from 'System.Xml.Linq.XAttribute' to 'System.Xml.Linq.XStreamingElement' X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPedSync\ApplicationSprite.cs 40 33 FlashHeatZeeker.UnitPedSync var xml = new XElement("sync", new XAttribute("egoid", egoid)); if (__transport_out != null) { __transport_out(xml.ToString()); } }; StarlingGameSpriteWithPedSync.__raise_SetVelocityFromInput += ( string __egoid, string __identity, string __KeySample, string __fixup_x, string __fixup_y, string __fixup_angle ) => { var xml = new XElement("SetVelocityFromInput", new XAttribute("egoid", __egoid), new XAttribute("i", __identity), new XAttribute("k", __KeySample), new XAttribute("x", __fixup_x), new XAttribute("y", __fixup_y), new XAttribute("angle", __fixup_angle) ); if (__transport_out != null) { __transport_out(xml.ToString()); } }; #endregion #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion this.InvokeWhenStageIsReady( delegate { // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(StarlingGameSpriteWithPedSync).ToClassToken(), this.stage ); //Starling.current.showStats s.showStats = true; #region atresize Action atresize = delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; //b2stage_centerize(); }; atresize(); #endregion StarlingGameSpriteBase.onresize = yield => { this.stage.resize += delegate { atresize(); yield(this.stage.stageWidth, this.stage.stageHeight); }; yield(this.stage.stageWidth, this.stage.stageHeight); }; this.stage.enterFrame += delegate { StarlingGameSpriteBase.onframe(this.stage, s); }; s.start(); } ); }
public ApplicationSprite() { var t = new TextField { text = "click on me to see console", autoSize = TextFieldAutoSize.LEFT }; t.MoveTo(16, 16); t.AttachTo(this); t.click += delegate { t.text += "\nclicked!"; Console.WriteLine("clicked in flash!"); }; this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { t.appendText("\nAtInitializeConsoleFormWriter"); try { var w = new __OutWriter(); var o = Console.Out; var __reentry = false; w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.SetOut(w); Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); t.appendText("\nAtInitializeConsoleFormWriter done"); } catch (Exception ex) { t.appendText("\n error: " + new { ex, Console_Write, Console_WriteLine }); } }; }
public ApplicationSprite() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; #region bg fill var fill = new Sprite().AttachTo(this); fill.graphics.beginFill(0xA26D41); fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight); this.stage.resize += delegate { fill.graphics.beginFill(0xA26D41); fill.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight); }; #endregion var egocenter = new Sprite(); var egorotation = new Sprite().AttachTo(egocenter); var map = new Sprite().AttachTo(egorotation); map.graphics.beginFill(0xB27D51); map.graphics.drawRect(0, 0, 4000, 400); // http://wiki.openoffice.org/wiki/SVG_User_Experiences //Enclosed Exception: //The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: flowRoot). // [Embed(source = "/assets/FlashHeatZeeker/touchdown.svg", mimeType = "image/svg-xml")] // ^ //U:\web\FlashHeatZeeker\ApplicationSprite.as(104): col: 9: Error: Unable to transcode /assets/FlashHeatZeeker/touchdown.svg. KnownEmbeddedResources.Default["assets/FlashHeatZeeker/touchdown.svg"].ToSprite().AttachTo(map).MoveTo(100, 0).With( svg => { svg.scaleX = 0.5; svg.scaleY = 0.5; } ); // unit 1 Func<GameUnit> greentank = delegate { var unit1_loc = new Sprite().AttachTo(map); var unit1_rot = new Sprite().AttachTo(unit1_loc); KnownEmbeddedResources.Default["assets/FlashHeatZeeker/greentank.svg"].ToSprite().AttachTo(unit1_rot).MoveTo(-200, -200); return new GameUnit { loc = unit1_loc, rot = unit1_rot }; }; var unit1 = greentank(); var unit2 = greentank(); var unit3 = greentank(); unit1.loc.MoveTo(300, 200); unit2.loc.MoveTo(0, 400); var CurrentUnit = unit1; KnownEmbeddedResources.Default["assets/FlashHeatZeeker/hill0.svg"].ToSprite().AttachTo(map).MoveTo(0, 0).With( svg => { svg.scaleX = 0.2; svg.scaleY = 0.2; } ); for (int iy = 0; iy < 128; iy++) { KnownEmbeddedResources.Default["assets/FlashHeatZeeker/tree0.svg"].ToSprite().AttachTo(map).MoveTo(400, 0).With( svg => { svg.cacheAsBitmap = true; svg.scaleX = 0.2; svg.scaleY = 0.2; if (iy % 3 == 0) svg.y += 50; if (iy % 3 == 1) svg.y += 100; svg.x += 15 * iy; } ); } for (int iy = 0; iy < 128; iy++) { KnownEmbeddedResources.Default["assets/FlashHeatZeeker/tree0.svg"].ToSprite().AttachTo(map).MoveTo(400, 0).With( svg => { svg.y += 300; svg.cacheAsBitmap = true; svg.scaleX = 0.2; svg.scaleY = 0.2; if (iy % 3 == 0) svg.y += 50; if (iy % 3 == 1) svg.y += 100; svg.x += 15 * iy; } ); } // ego is in center map.MoveTo(-300, -200); this.stage.keyUp += e => { //Console.WriteLine("keyUp " + new { e.keyCode }); if (e.keyCode == (uint)System.Windows.Forms.Keys.D3) { CurrentUnit = unit3; egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); } if (e.keyCode == (uint)System.Windows.Forms.Keys.D1) { CurrentUnit = unit1; egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); } if (e.keyCode == (uint)System.Windows.Forms.Keys.D2) { CurrentUnit = unit2; egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); } if (e.keyCode == (uint)System.Windows.Forms.Keys.F11) { this.stage.SetFullscreen(true); } }; this.stage.keyDown += e => { //Console.WriteLine("keyDown " + new { e.keyCode }); if (e.keyCode == (uint)System.Windows.Forms.Keys.Up) { CurrentUnit.loc.x += 2 * Math.Cos((CurrentUnit.rot.rotation + 270).DegreesToRadians()); CurrentUnit.loc.y += 2 * Math.Sin((CurrentUnit.rot.rotation + 270).DegreesToRadians()); } if (e.keyCode == (uint)System.Windows.Forms.Keys.Down) { CurrentUnit.loc.x += -2 * Math.Cos((CurrentUnit.rot.rotation + 270).DegreesToRadians()); CurrentUnit.loc.y += -2 * Math.Sin((CurrentUnit.rot.rotation + 270).DegreesToRadians()); } if (e.keyCode == (uint)System.Windows.Forms.Keys.Left) { CurrentUnit.rot.rotation -= 5; } if (e.keyCode == (uint)System.Windows.Forms.Keys.Right) { CurrentUnit.rot.rotation += 5; } egorotation.rotation = -CurrentUnit.rot.rotation; map.MoveTo(-CurrentUnit.loc.x, -CurrentUnit.loc.y); }; #region egocrosshair var egocrosshair = new Sprite().AttachTo(egocenter); egocrosshair.graphics.lineStyle(2, 0x007f00, 1); egocrosshair.graphics.moveTo(-32, 0); egocrosshair.graphics.lineTo(32, 0); egocrosshair.graphics.moveTo(0, -32); egocrosshair.graphics.lineTo(0, 32); #endregion egocenter.AttachTo(this); egocenter.MoveTo(this.stage.stageWidth / 2, this.stage.stageHeight / 2); this.stage.resize += delegate { egocenter.MoveTo(this.stage.stageWidth / 2, this.stage.stageHeight / 2); }; #region AtInitializeConsoleFormWriter this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { var w = new __OutWriter(); var o = Console.Out; var __reentry = false; w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.SetOut(w); Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); } catch { } }; #endregion var info = new TextField { selectable = false, mouseEnabled = false, autoSize = TextFieldAutoSize.LEFT }.AttachTo(this).MoveTo(8, 8); var maxframe = new Stopwatch(); var maxframe_elapsed = 0.0; #region fps var sw = new Stopwatch(); sw.Start(); var ii = 0; maxframe.Start(); this.enterFrame += delegate { maxframe.Stop(); // System.TimeSpan for Boolean op_GreaterThan(System.TimeSpan, System.TimeSpan) used at //FlashHeatZeeker.ApplicationSprite+<>c__DisplayClass11.<.ctor>b__d at offset 001e. // TypeError: Error #1009: Cannot access a property or method of a null object reference. //at FlashHeatZeeker::ApplicationSprite___c__DisplayClass11/__ctor_b__d_100663322()[U:\web\FlashHeatZeeker\ApplicationSprite___c__DisplayClass11.as:141] if (maxframe.Elapsed.TotalMilliseconds > maxframe_elapsed) maxframe_elapsed = maxframe.Elapsed.TotalMilliseconds; if (sw.ElapsedMilliseconds < 1000) { ii++; maxframe.Restart(); return; } info.text = new { fps = ii, maxframe_elapsed }.ToString(); //if (fps != null) // fps("" + ii); ii = 0; maxframe_elapsed = 0; sw.Restart(); }; #endregion }
public ApplicationSprite() { //Security.allowDomain("*"); //Security.allowInsecureDomain("*"); this.InvokeWhenStageIsReady( () => { var deal = KnownEmbeddedResources.Default[Sounds.Assets.deal]; var click = KnownEmbeddedResources.Default[Sounds.Assets.click]; var drag = KnownEmbeddedResources.Default[Sounds.Assets.drag]; var win = KnownEmbeddedResources.Default[Sounds.Assets.win]; content.Sounds.deal = () => deal.ToSoundAsset().play(); content.Sounds.click = () => click.ToSoundAsset().play(); content.Sounds.drag = () => drag.ToSoundAsset().play(); content.Sounds.win = () => win.ToSoundAsset().play(); content.AttachToContainer(this); content.AutoSizeTo(this.stage); if (Security.sandboxType == "application") { // AdMob! // mochiAds wont work on Android! } else { var shadow = new Rectangle(); shadow.Fill = Brushes.Black; shadow.Width = this.stage.stageWidth; shadow.Height = this.stage.stageHeight; shadow.Opacity = 0.5; content.Children.Add(shadow); var clip = new MovieClip().AttachTo(this); //dynamic options = new object(); //options.clip = this; //options.id = "47e72426ba7f4f3f"; //options.res = this.stage.stageWidth + "x" + this.stage.stageHeight; //options.ad_finished = a; // Error: MochiAd is missing the 'clip' parameter. // This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite. // https://www.mochimedia.com/community/forum/topic/desktop-air-application#46785de6 // SecurityError: Error #2047: Security sandbox violation: parent: http://xs.mochiads.com/container/MochiAdsCDN-AS3.swf?do_init=1&cacheBust=1359132511880 cannot access app:/AvalonCardGames.AIRFreeCell.ApplicationSprite.swf. //at flash.display::DisplayObject/get parent() //at com.mochimedia.targeting::MochiAdsTargeting/removedFromStage()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/targeting/MochiAdsTargeting.as:128] //at flash.display::DisplayObjectContainer/removeChildAt() //at mochi.as3::MochiAd$/_cleanup()[W:\opensource\mochimedia.com\MochiAd.as:946] //at Function/<anonymous>()[W:\opensource\mochimedia.com\MochiAd.as:195] //at mochi.as3::MochiAd$/unload()[W:\opensource\mochimedia.com\MochiAd.as:924] //at Function/<anonymous>()[W:\opensource\mochimedia.com\MochiAd.as:275] //at Function/<anonymous>()[W:\opensource\mochimedia.com\MochiAd.as:41] // SecurityError: Error #2047: Security sandbox violation: parent: http://xs.mochiads.com/container/MochiAdsCDN-AS3.swf?do_init=1&cacheBust=1359134133659 cannot access app:/AvalonCardGames.AIRFreeCell.ApplicationSprite.swf. //at flash.display::DisplayObject/get parent() //at com.mochimedia.targeting::MochiAdsTargeting/removedFromStage()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/targeting/MochiAdsTargeting.as:128] //at flash.display::DisplayObjectContainer/removeChildAt() //at mochi.as3::MochiAd$/_cleanup() //at MethodInfo-1806() //at mochi.as3::MochiAd$/unload() //at MethodInfo-1807() //at MethodInfo-1793() // SecurityError: Error #2047: Security sandbox violation: parent: http://xs.mochiads.com/container/MochiAdsCDN-AS3.swf?do_init=1&cacheBust=1359134133659 cannot access app:/AvalonCardGames.AIRFreeCell.ApplicationSprite.swf. //at flash.display::DisplayObject/get parent() //at com.mochimedia.container::MochiAdsContainer/initalize()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/container/MochiAdsContainer.as:40] //at com.mochimedia.targeting::MochiAdsTargeting/onJSONData()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/targeting/MochiAdsTargeting.as:780] //at flash.events::EventDispatcher/dispatchEventFunction() //at flash.events::EventDispatcher/dispatchEvent() //at flash.net::URLLoader/onComplete() var options = new MochiAdOptions { //TypeError: Error #1034: Type Coercion failed: cannot convert AvalonCardGames.AIRFreeCell::ApplicationSprite@14b37041 to flash.display.MovieClip. // at mochi.as3::MochiAd$/load()[W:\opensource\mochimedia.com\MochiAd.as:789] // at mochi.as3::MochiAd$/showPreGameAd()[W:\opensource\mochimedia.com\MochiAd.as:185] // at AvalonCardGames.AIRFreeCell::MochiAdOptions/showPreGameAd_100664136()[U:\web\AvalonCardGames\AIRFreeCell\MochiAdOptions.as:74] // at AvalonCardGames.AIRFreeCell::ApplicationSprite/__ctor_b__1_100663300()[U:\web\AvalonCardGames\AIRFreeCell\ApplicationSprite.as:82] clip = clip, id = _mochiads_game_id, res = this.stage.stageWidth + "x" + this.stage.stageHeight, ad_finished = delegate { this.removeChild(clip); shadow.Orphanize(); { var now = DateTime.Now; Console.WriteLine(now + " ready! " + new { Security.sandboxType }); } } }; { var now = DateTime.Now; Console.WriteLine(now + " can we get some ads? " + new { Security.sandboxType }); } options.showPreGameAd(); } } ); #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion }
public ApplicationSprite() { #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion var SCALE = 15; //how many pixels in a meter var WIDTH_M = DefaultWidth / SCALE; //world width in meters. for this example, world is as large as the screen var HEIGHT_M = DefaultHeight / SCALE; //world height in meters //initialize font to draw text with //var font=new gamejs.font.Font('16px Sans-serif'); //key bindings //var BINDINGS={accelerate:gamejs.event.K_UP, // brake:gamejs.event.K_DOWN, // steer_left:gamejs.event.K_LEFT, // steer_right:gamejs.event.K_RIGHT}; //initialize display //var display = gamejs.display.setMode([WIDTH_PX, HEIGHT_PX]); //SET UP B2WORLD var b2world = new b2World(new b2Vec2(0, 0), false); //set up box2d debug draw to draw the bodies for us. //in a real game, car will propably be drawn as a sprite rotated by the car's angle var debugDraw = new b2DebugDraw(); debugDraw.SetSprite(this); debugDraw.SetDrawScale(SCALE); debugDraw.SetFillAlpha(0.5); debugDraw.SetLineThickness(1.0); debugDraw.SetFlags(b2DebugDraw.e_shapeBit); b2world.SetDebugDraw(debugDraw); var wheels = new[] { //top left new Wheel(b2world: b2world, x :-1, y :-1.2, width :0.4, length :0.8, revolving :true, powered :true), //top right new Wheel(b2world: b2world, x :1, y :-1.2, width :0.4, length :0.8, revolving :true, powered :true), //back left new Wheel(b2world: b2world, x :-1, y :1.2, width :0.4, length :0.8, revolving :false, powered :false), //back right new Wheel(b2world: b2world, x :1, y :1.2, width :0.4, length :0.8, revolving :false, powered :false), }; Func<double, double, double[]> ff = (a, b) => { return new double[] { a, b }; }; ////initialize car var car = new Car( b2world: b2world, width: 2, length: 4, position: ff(10, 10), angle: 180, power: 60, max_steer_angle: 20, max_speed: 60, wheels: wheels ); //initialize some props to bounce against var props = new List<BoxProp>(); //outer walls props.Add(new BoxProp(b2world, size: ff(WIDTH_M, 1), position: ff(WIDTH_M / 2, 0.5))); props.Add(new BoxProp(b2world, size: ff(1, HEIGHT_M - 2), position: ff(0.5, HEIGHT_M / 2))); props.Add(new BoxProp(b2world, size: ff(WIDTH_M, 1), position: ff(WIDTH_M / 2, HEIGHT_M - 0.5))); props.Add(new BoxProp(b2world, size: ff(1, HEIGHT_M - 2), position: ff(WIDTH_M - 0.5, HEIGHT_M / 2))); //pen in the center var center = new double[] { WIDTH_M / 2, HEIGHT_M / 2 }; props.Add(new BoxProp(b2world, size: ff(1, 6), position: ff(center[0] - 3, center[1]))); props.Add(new BoxProp(b2world, size: ff(1, 6), position: ff(center[0] + 3, center[1]))); props.Add(new BoxProp(b2world, size: ff(5, 1), position: ff(center[0], center[1] + 2.5))); var frameid = 0; var KEYS_DOWN = new Dictionary<Keys, bool> { { Keys.Left, false }, { Keys.Up, false }, { Keys.Right, false }, { Keys.Down, false }, }; //keep track of what keys are held down by the player this.stage.keyDown += e => { Console.WriteLine("keyDown " + new { e.keyCode }); KEYS_DOWN[(Keys)e.keyCode] = true; }; this.stage.keyUp += e => { Console.WriteLine("keyUp " + new { e.keyCode }); KEYS_DOWN[(Keys)e.keyCode] = false; }; #region tick Action<double> tick = (msDuration) => { frameid++; //if (frameid > 1) // return; //Console.WriteLine(new { frameid }); //GAME LOOP //handle events. Key status (depressed or no) is tracked in via KEYS_DOWN associative array //gamejs.event.get().forEach(function(event){ // //key press // if (event.type === gamejs.event.KEY_DOWN) KEYS_DOWN[event.key] = true; // //key release // else if (event.type === gamejs.event.KEY_UP) KEYS_DOWN[event.key] = false; //}); //set car controls according to player input if (KEYS_DOWN[Keys.Up]) { car.accelerate = ACC_ACCELERATE; } else if (KEYS_DOWN[Keys.Down]) { car.accelerate = ACC_BRAKE; } else { car.accelerate = ACC_NONE; } if (KEYS_DOWN[Keys.Right]) { car.steer = STEER_RIGHT; } else if (KEYS_DOWN[Keys.Left]) { car.steer = STEER_LEFT; } else { car.steer = STEER_NONE; } ////update car car.update(msDuration); //update physics world b2world.Step(msDuration / 1000.0, 10, 8); //clear applied forces, so they don't stack from each update b2world.ClearForces(); //fill background //gamejs.draw.rect(display, '#FFFFFF', new gamejs.Rect([0, 0], [WIDTH_PX, HEIGHT_PX]),0) //let box2d draw it's bodies b2world.DrawDebugData(); //fps and car speed display //display.blit(font.render('FPS: '+parseInt((1000)/msDuration)), [25, 25]); //display.blit(font.render('SPEED: '+parseInt(Math.ceil(car.getSpeedKMH()))+' km/h'), [25, 55]); //Console.WriteLine(new { frameid } + " done!"); }; ////gamejs.time.fpsCallback(tick, this, 60); var sw = new Stopwatch(); sw.Start(); this.enterFrame += delegate { tick(sw.ElapsedMilliseconds); sw.Restart(); }; #endregion }
public ApplicationSprite() { var t = new TextField { text = "click on me to see console", autoSize = TextFieldAutoSize.LEFT }; t.MoveTo(16, 16); t.AttachTo(this); t.click += delegate { t.text += "\nclicked!"; Console.WriteLine("clicked in flash!"); }; this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { t.appendText("\nAtInitializeConsoleFormWriter"); try { var w = new __OutWriter(); var o = Console.Out; var __reentry = false; w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.SetOut(w); Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); t.appendText("\nAtInitializeConsoleFormWriter done"); } catch (Exception ex) { t.appendText("\n error: " + new { ex, Console_Write, Console_WriteLine }); } }; }
public ApplicationSprite() { #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion }
public ApplicationSprite() { #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion }