public StarlingGameSpriteWithPed() { this.autorotate = true; var textures_ped = new StarlingGameSpriteWithPedTextures( this.new_tex_crop, this.new_texsprite_crop ); this.onbeforefirstframe += delegate { var hud = new Image(textures_ped.hud_look_goggles()).AttachTo(this); // 781 // 15 FPS // 60 FPS // 31 FPS var peds = new List<VisualPed>(); for (int i = 0; i < 32; i++) for (int yi = 0; yi < 32; yi++) { var rr = random.Next() % 1024; var visual0 = new VisualPed(textures_ped, this); visual0.SetPositionAndAngle( i * 128, yi * 128, random.NextDouble() * Math.PI ); peds.Add(visual0); if (i == 0) visual0.WalkLikeZombie = true; } onresize( (w, h) => { } ); onframe += delegate { // animate foreach (var visual0 in peds) { visual0.Animate(1, 1); } { var cm = new Matrix(); cm.scale(0.5, 0.5); cm.translate(16, stage.stageHeight - 64 - 24); hud.transformationMatrix = cm; } }; //#region sortChildren //// http://forum.starling-framework.org/topic/sortchildren-function-causes-flickering //Func<DisplayObject, DisplayObject, int> sorter = // (x, y) => // { // var ix = x as Image; // var iy = y as Image; // if (ix != null) // if (iy != null) // { // if (ix.texture == textures_ped_stand) // if (iy.texture != textures_ped_stand) // return -1; // if (ix.texture != textures_ped_stand) // if (iy.texture == textures_ped_stand) // return 1; // } // return 0; // }; //Content.sortChildren(sorter.ToFunction()); //#endregion }; }
public StarlingGameSpriteWithPed() { this.autorotate = true; var textures_ped = new StarlingGameSpriteWithPedTextures( this.new_tex_crop, this.new_texsprite_crop ); this.onbeforefirstframe += delegate { var hud = new Image(textures_ped.hud_look_goggles()).AttachTo(this); // 781 // 15 FPS // 60 FPS // 31 FPS var peds = new List <VisualPed>(); for (int i = 0; i < 32; i++) { for (int yi = 0; yi < 32; yi++) { var rr = random.Next() % 1024; var visual0 = new VisualPed(textures_ped, this); visual0.SetPositionAndAngle( i * 128, yi * 128, random.NextDouble() * Math.PI ); peds.Add(visual0); if (i == 0) { visual0.WalkLikeZombie = true; } } } onresize( (w, h) => { } ); onframe += delegate { // animate foreach (var visual0 in peds) { visual0.Animate(1, 1); } { var cm = new Matrix(); cm.scale(0.5, 0.5); cm.translate(16, stage.stageHeight - 64 - 24); hud.transformationMatrix = cm; } }; //#region sortChildren //// http://forum.starling-framework.org/topic/sortchildren-function-causes-flickering //Func<DisplayObject, DisplayObject, int> sorter = // (x, y) => // { // var ix = x as Image; // var iy = y as Image; // if (ix != null) // if (iy != null) // { // if (ix.texture == textures_ped_stand) // if (iy.texture != textures_ped_stand) // return -1; // if (ix.texture != textures_ped_stand) // if (iy.texture == textures_ped_stand) // return 1; // } // return 0; // }; //Content.sortChildren(sorter.ToFunction()); //#endregion }; }
public PhysicalPed(StarlingGameSpriteWithPedTextures textures, StarlingGameSpriteWithPhysics Context) { this.CurrentInput = new KeySample(); this.textures = textures; this.Context = Context; for (int i = 0; i < 7; i++) { this.KarmaInput0.Enqueue( new KeySample() ); } visual = new VisualPed(textures, Context, AnimateSeed: Context.random.Next() % 3000 ); #region b2world { var bodyDef = new b2BodyDef(); bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; // stop moving if legs stop walking! bodyDef.linearDamping = 0; bodyDef.angularDamping = 6; //bodyDef.angle = 1.57079633; //bodyDef.fixedRotation = true; body = Context.ground_b2world.CreateBody(bodyDef); var fixDef = new Box2D.Dynamics.b2FixtureDef(); fixDef.density = 0.1; fixDef.friction = 0.0; fixDef.restitution = 0; fixDef.shape = new Box2D.Collision.Shapes.b2CircleShape(1.0); var fix = body.CreateFixture(fixDef); var fix_data = new Action<double>( zombie_forceA => { if (zombie_forceA < 1) return; // zombie runs against a building if (zombie_forceA > 3.6) if (visual.WalkLikeZombie) { Console.WriteLine(new { zombie_forceA }); this.body.SetActive(false); this.damagebody.SetActive(false); this.visual.LayOnTheGround = true; this.SetVelocityFromInput(new KeySample()); } if (oncollision != null) oncollision(this, zombie_forceA); } ); fix.SetUserData(fix_data); } #endregion #region groundkarma_b2world { var bodyDef = new b2BodyDef(); bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; // stop moving if legs stop walking! bodyDef.linearDamping = 0; bodyDef.angularDamping = 6; //bodyDef.angle = 1.57079633; //bodyDef.fixedRotation = true; karmabody = Context.groundkarma_b2world.CreateBody(bodyDef); var fixDef = new Box2D.Dynamics.b2FixtureDef(); fixDef.density = 0.1; fixDef.friction = 0.0; fixDef.restitution = 0; fixDef.shape = new Box2D.Collision.Shapes.b2CircleShape(1.0); var fix = karmabody.CreateFixture(fixDef); } #endregion #region damage_b2world { var bodyDef = new b2BodyDef(); bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; // stop moving if legs stop walking! bodyDef.linearDamping = 0; bodyDef.angularDamping = 6; //bodyDef.angle = 1.57079633; //bodyDef.fixedRotation = true; damagebody = Context.damage_b2world.CreateBody(bodyDef); var fixDef = new Box2D.Dynamics.b2FixtureDef(); fixDef.density = 0.1; fixDef.friction = 0.0; fixDef.restitution = 0; fixDef.shape = new Box2D.Collision.Shapes.b2CircleShape(1.0); var fix = damagebody.CreateFixture(fixDef); var fix_data = new Action<double>( jeep_forceA => { if (jeep_forceA < 0.5) return; if (visual.WalkLikeZombie) { this.body.SetActive(false); this.damagebody.SetActive(false); this.visual.LayOnTheGround = true; this.SetVelocityFromInput(new KeySample()); } //if (jeep_forceA < 1) // return; //if (oncollision != null) // oncollision(this, jeep_forceA); } ); fix.SetUserData(fix_data); } #endregion Context.internalunits.Add(this); }