public PhysicalWatertower(StarlingGameSpriteWithBunkerTextures textures, StarlingGameSpriteWithPhysics Context) { this.CurrentInput = new KeySample(); this.driverseat = new DriverSeat(); this.textures = textures; this.Context = Context; for (int i = 0; i < 7; i++) { this.KarmaInput0.Enqueue( new KeySample() ); } visualshadow = new Image( textures.watertower0_shadow() ).AttachTo(Context.Content_layer2_shadows); visual = new Image( textures.watertower0() ).AttachTo(Context.Content_layer3_buildings); { //initialize body var bdef = new b2BodyDef(); bdef.angle = 0; bdef.fixedRotation = true; this.body = Context.ground_b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2CircleShape(1.2); fixdef.shape = shape; fixdef.restitution = 0.4; //positively bouncy! var fix = this.body.CreateFixture(fixdef); var fix_data = new Action<double>( force => { if (force < 1) return; Context.oncollision(this, force); } ); fix.SetUserData(fix_data); } { //initialize body var bdef = new b2BodyDef(); bdef.angle = 0; bdef.fixedRotation = true; this.karmabody = Context.groundkarma_b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2CircleShape(1.2); fixdef.shape = shape; fixdef.restitution = 0.4; //positively bouncy! this.karmabody.CreateFixture(fixdef); } Context.internalunits.Add(this); }
public PhysicalBunker(StarlingGameSpriteWithBunkerTextures textures, StarlingGameSpriteWithPhysics Context, bool IsShop = false) { var textures_bunker = textures; this.CurrentInput = new KeySample(); this.driverseat = new DriverSeat(); this.textures = textures; this.Context = Context; for (int i = 0; i < 7; i++) { this.KarmaInput0.Enqueue( new KeySample() ); } visualshadow = new Image( textures.bunker2_shadow() ).AttachTo(Context.Content_layer2_shadows); visual = new Sprite().AttachTo(Context.Content_layer3_buildings); visual_body = new Image( textures.bunker2() ).AttachTo(visual); visual_shopoverlay = new Image( textures.bunker2_shopoverlay() ).AttachTo(visual); visual_shopoverlay_arrow = new Image( textures.bunker2_shopoverlay_arrow() ).AttachTo(visual); if (IsShop) { #region hud_arrow var hud_arrow = new Image( textures_bunker.bunker2_shopoverlay_arrow() ).AttachTo(Context); StarlingGameSpriteWithPhysics.onframe += (ScriptCoreLib.ActionScript.flash.display.Stage stage, Starling starling) => { var gap = new __vec2( (float)(this.body.GetPosition().x - Context.current.body.GetPosition().x), (float)(this.body.GetPosition().y - Context.current.body.GetPosition().y) ); var distance = gap.GetLength(); if (distance < 40) { visual_shopoverlay_arrow.visible = true; hud_arrow.visible = false; return; } //if (distance < 50) //{ // visual_shopoverlay_arrow.visible = false; // hud_arrow.visible = false; // return; //} visual_shopoverlay_arrow.visible = false; hud_arrow.visible = true; var cm = new Matrix(); // var yy = 8 * Math.Sin(this.Context.gametime.ElapsedMilliseconds * 0.002); cm.translate(-128, -128 - 64 + yy); cm.scale(Context.stagescale, Context.stagescale); cm.rotate(gap.GetRotation() - Context.current.body.GetAngle() + Context.current.CameraRotation); cm.translate( (stage.stageWidth * 0.5), (stage.stageHeight * Context.internal_center_y) ); hud_arrow.transformationMatrix = cm; }; #endregion } this.IsShop = IsShop; #region damage_b2world { //initialize body var bdef = new b2BodyDef(); bdef.angle = 0; bdef.fixedRotation = true; this.damagebody = Context.damage_b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2PolygonShape(); fixdef.shape = shape; shape.SetAsBox(4.5, 4.5); fixdef.restitution = 0.4; //positively bouncy! var fix = this.damagebody.CreateFixture(fixdef); var fix_data = new Action<double>( force => { if (force < 1) return; Context.oncollision(this, force); } ); fix.SetUserData(fix_data); } #endregion #region ground_b2world { //initialize body var bdef = new b2BodyDef(); bdef.angle = 0; bdef.fixedRotation = true; this.body = Context.ground_b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2PolygonShape(); fixdef.shape = shape; shape.SetAsBox(4.5, 4.5); fixdef.restitution = 0.4; //positively bouncy! var fix = this.body.CreateFixture(fixdef); var fix_data = new Action<double>( force => { if (force < 1) return; Context.oncollision(this, force); } ); fix.SetUserData(fix_data); } #endregion { //initialize body var bdef = new b2BodyDef(); bdef.angle = 0; bdef.fixedRotation = true; this.karmabody = Context.groundkarma_b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2PolygonShape(); fixdef.shape = shape; shape.SetAsBox(4.5, 4.5); fixdef.restitution = 0.4; //positively bouncy! this.karmabody.CreateFixture(fixdef); } Context.internalunits.Add(this); }
public PhysicalCannon(StarlingGameSpriteWithCannonTextures textures, StarlingGameSpriteWithPhysics Context) { this.CurrentInput = new KeySample(); this.driverseat = new DriverSeat(); this.Context = Context; visual = new VisualCannon(textures, Context); for (int i = 0; i < 7; i++) { this.KarmaInput0.Enqueue( new KeySample() ); } { //initialize body var bdef = new b2BodyDef(); bdef.angle = 0; bdef.fixedRotation = true; this.body = Context.ground_b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2PolygonShape(); fixdef.shape = shape; shape.SetAsBox(2, 2); fixdef.restitution = 0.4; //positively bouncy! var fix = this.body.CreateFixture(fixdef); var fix_data = new Action<double>( jeep_forceA => { if (jeep_forceA < 1) return; Context.oncollision(this, jeep_forceA); } ); fix.SetUserData(fix_data); } { //initialize body var bdef = new b2BodyDef(); bdef.angle = 0; bdef.fixedRotation = true; this.karmabody = Context.groundkarma_b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2PolygonShape(); fixdef.shape = shape; shape.SetAsBox(2, 2); fixdef.restitution = 0.4; //positively bouncy! this.karmabody.CreateFixture(fixdef); } Context.internalunits.Add(this); }
public PhysicalTank(StarlingGameSpriteWithTankTextures textures, StarlingGameSpriteWithPhysics Context) { this.CurrentInput = new KeySample(); this.textures = textures; this.Context = Context; this.driverseat = new DriverSeat(); this.visual = new VisualTank(textures, Context); for (int i = 0; i < 7; i++) { this.KarmaInput0.Enqueue( new KeySample() ); } #region b2world { var bodyDef = new b2BodyDef(); bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; // stop moving if legs stop walking! bodyDef.linearDamping = 1.0; bodyDef.angularDamping = 8; //bodyDef.angle = 1.57079633; //bodyDef.fixedRotation = true; body = Context.ground_b2world.CreateBody(bodyDef); //current = body; var fixDef = new Box2D.Dynamics.b2FixtureDef(); fixDef.density = 0.1; fixDef.friction = 0.01; fixDef.restitution = 0; var fixdef_shape = new b2PolygonShape(); fixDef.shape = fixdef_shape; // physics unit is looking to right fixdef_shape.SetAsBox(3, 2); var fix = body.CreateFixture(fixDef); var fix_data = new Action<double>( jeep_forceA => { if (jeep_forceA < 1) return; Context.oncollision(this, jeep_forceA); } ); fix.SetUserData(fix_data); } { var bodyDef = new b2BodyDef(); bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; // stop moving if legs stop walking! bodyDef.linearDamping = 1.0; bodyDef.angularDamping = 8; //bodyDef.angle = 1.57079633; //bodyDef.fixedRotation = true; karmabody = Context.groundkarma_b2world.CreateBody(bodyDef); //current = body; var fixDef = new Box2D.Dynamics.b2FixtureDef(); fixDef.density = 0.1; fixDef.friction = 0.01; fixDef.restitution = 0; var fixdef_shape = new b2PolygonShape(); fixDef.shape = fixdef_shape; // physics unit is looking to right fixdef_shape.SetAsBox(3, 2); var fix = karmabody.CreateFixture(fixDef); } #endregion #region b2world { var bodyDef = new b2BodyDef(); bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; // stop moving if legs stop walking! bodyDef.linearDamping = 1.0; bodyDef.angularDamping = 8; //bodyDef.angle = 1.57079633; //bodyDef.fixedRotation = true; damagebody = Context.damage_b2world.CreateBody(bodyDef); //current = body; var fixDef = new Box2D.Dynamics.b2FixtureDef(); fixDef.density = 0.1; fixDef.friction = 0.01; fixDef.restitution = 0; var fixdef_shape = new b2PolygonShape(); fixDef.shape = fixdef_shape; // physics unit is looking to right fixdef_shape.SetAsBox(3, 2); var fix = damagebody.CreateFixture(fixDef); var fix_data = new Action<double>( jeep_forceA => { if (jeep_forceA < 1) return; Context.oncollision(this, jeep_forceA); } ); fix.SetUserData(fix_data); } #endregion Context.internalunits.Add(this); }