public Apple(Fixture connectedFixture, GameContent gameContent, World world) { this.world = world; this.gameContent = gameContent; texture = gameContent.apple; fallenFromAir = false; CreatBody(); State = LeafState.Grow; if (connectedFixture != null) { this.connectedFixture = connectedFixture; AABB aabb; connectedFixture.GetAABB(out aabb); body.Position = aabb.GetCenter(); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.bodyA = body; rjd.bodyB = connectedFixture.GetBody(); rjd.localAnchorA = Vector2.Zero; rjd.localAnchorB = connectedFixture.GetBody().GetLocalPoint(body.Position); revoJoint = (RevoluteJoint)world.CreateJoint(rjd); } }
internal GearJoint(GearJointDef def) : base(def) { JointType type1 = def.joint1.JointType; JointType type2 = def.joint2.JointType; Debug.Assert(type1 == JointType.Revolute || type1 == JointType.Prismatic); Debug.Assert(type2 == JointType.Revolute || type2 == JointType.Prismatic); Debug.Assert(def.joint1.GetBodyA().GetType() == BodyType.Static); Debug.Assert(def.joint2.GetBodyA().GetType() == BodyType.Static); _revolute1 = null; _prismatic1 = null; _revolute2 = null; _prismatic2 = null; float coordinate1, coordinate2; _ground1 = def.joint1.GetBodyA(); _bodyA = def.joint1.GetBodyB(); if (type1 == JointType.Revolute) { _revolute1 = (RevoluteJoint)def.joint1; _groundAnchor1 = _revolute1._localAnchor1; _localAnchor1 = _revolute1._localAnchor2; coordinate1 = _revolute1.GetJointAngle(); } else { _prismatic1 = (PrismaticJoint)def.joint1; _groundAnchor1 = _prismatic1._localAnchor1; _localAnchor1 = _prismatic1._localAnchor2; coordinate1 = _prismatic1.GetJointTranslation(); } _ground2 = def.joint2.GetBodyA(); _bodyB = def.joint2.GetBodyB(); if (type2 == JointType.Revolute) { _revolute2 = (RevoluteJoint)def.joint2; _groundAnchor2 = _revolute2._localAnchor1; _localAnchor2 = _revolute2._localAnchor2; coordinate2 = _revolute2.GetJointAngle(); } else { _prismatic2 = (PrismaticJoint)def.joint2; _groundAnchor2 = _prismatic2._localAnchor1; _localAnchor2 = _prismatic2._localAnchor2; coordinate2 = _prismatic2.GetJointTranslation(); } _ratio = def.ratio; _ant = coordinate1 + _ratio * coordinate2; _impulse = 0.0f; }
public Branch(Path2D path, GameContent gameContent, World world, Branch nearestBranch) { this.gameContent = gameContent; dot = gameContent.dot; circle = gameContent.jointCircle; square = gameContent.jointSquare; cursor = gameContent.cursor; BodyDef bd = new BodyDef(); bd.position = path.Keys[0]; bd.type = BodyType.Dynamic; body = world.CreateBody(bd); fixtureCount = path.Keys.Count; for (int i = 0; i < path.Keys.Count; i++) CreateFixture(path.Keys[i] - path.Keys[0]); if (nearestBranch != null) { RevoluteJointDef revJd = new RevoluteJointDef(); revJd.bodyA = body; revJd.bodyB = nearestBranch.body; revJd.localAnchorA = Vector2.Zero; AABB aabb; nearestBranch.nearestFixture.GetAABB(out aabb); Vector2 p = aabb.GetCenter(); revJd.localAnchorB = nearestBranch.nearestFixture.GetBody().GetLocalPoint(p); revJd.enableMotor = true; revJd.referenceAngle = nearestBranch.nearestFixture.GetBody().Rotation; revoJoint = (RevoluteJoint)world.CreateJoint(revJd); revoJoint.SetUserData((Branch)nearestBranch); nearestBranch.nearestFixture.SetUserData((Branch)this); } newGrow = true; }
internal static Joint Create(JointDef def) { Joint joint = null; switch (def.type) { case JointType.Distance: { joint = new DistanceJoint((DistanceJointDef)def); } break; case JointType.Mouse: { joint = new MouseJoint((MouseJointDef)def); } break; case JointType.Prismatic: { joint = new PrismaticJoint((PrismaticJointDef)def); } break; case JointType.Revolute: { joint = new RevoluteJoint((RevoluteJointDef)def); } break; case JointType.Pulley: { joint = new PulleyJoint((PulleyJointDef)def); } break; case JointType.Gear: { joint = new GearJoint((GearJointDef)def); } break; case JointType.Line: { joint = new LineJoint((LineJointDef)def); } break; case JointType.Weld: { joint = new WeldJoint((WeldJointDef)def); } break; case JointType.Friction: { joint = new FrictionJoint((FrictionJointDef)def); } break; case JointType.MaxDistance: { joint = new MaxDistanceJoint((MaxDistanceJointDef)def); } break; default: Debug.Assert(false); break; } return joint; }
/// <summary> /// Creates a new motorcycle and a driver into the given Box2D world. /// Creates all the parts of the motorcycle and driver and joints them together. /// </summary> /// <param name="pBikeSpeed">A pointer to the variable that describes the speed of the /// motorcycle</param> /// <param name="pRotationData">RotationData to provide the information of the rotation /// of the device</param> /// <param name="pWorld">The Box2D world where the bike is created into</param> /// <param name="pCamPos">A pointer to the variable that describes the position of the /// camera</param> /// <param name="pContent">The used ContentManager instance</param> /// <param name="pSpriteBatch">The used SpriteBatch instance</param> public Bike(float []pBikeSpeed, RotationData pRotationData, World pWorld, float[] pCamPos, ContentManager pContent) { OffTheBike = false; camPos = pCamPos; world = pWorld; content = pContent; RotationData = pRotationData; bikeSpeed = pBikeSpeed; frontWheel = CreateCirclePart("wheel", frontWheelInitPos, 35.0f, 0, 0.1f, 0.9f, 0.2f); frontFork = CreateBoxPart("susp_lower_long", frontForkInitPos, 20.53f, 21.33f, 0, 0.8f, 1.0f, 0.2f); rearWheel = CreateCirclePart("rearWheel", rearWheelInitPos, 32.0f, 0, 0.4f, 1.0f, 0.2f); rearFork = CreateBoxPart("rearFork", rearForkInitPos, 64.0f, 17.0f, rearForkInitRot, 0.5f, 1.0f, 0.2f); bikeBody = CreateBikeBody(bikeBodyInitPos, bikeBodyInitRot, 0.5f, 1.0f, 0.2f); RevoluteJointDef motorDef = new RevoluteJointDef(); motorDef.Initialize(rearWheel, rearFork, rearWheel.GetWorldCenter()); motorDef.maxMotorTorque = 2.0f; motorDef.enableMotor = true; motor = (RevoluteJoint)world.CreateJoint(motorDef); RevoluteJointDef rearForkBodyDef = new RevoluteJointDef(); Vector2 anchor = rearFork.GetWorldCenter(); anchor.X += (32.0f / Level.FACTOR); anchor.Y += (13.5f / Level.FACTOR); rearForkBodyDef.Initialize(rearFork, bikeBody, anchor); rearForkBodyDef.bodyA = rearFork; rearForkBodyDef.bodyB = bikeBody; rearForkBodyDef.maxMotorTorque = 300.0f; world.CreateJoint(rearForkBodyDef); RevoluteJointDef frontWheelJointDef = new RevoluteJointDef(); frontWheelJointDef.Initialize(frontWheel, frontFork, frontWheel.GetWorldCenter()); frontWheelJointDef.maxMotorTorque = 300.0f; world.CreateJoint(frontWheelJointDef); DistanceJointDef frontSuspToBikeDef = new DistanceJointDef(); frontSuspToBikeDef.Initialize(bikeBody, frontFork, frontFork.GetWorldCenter() + new Vector2(0, 0.4f), frontFork.GetWorldCenter()); frontSuspToBikeDef.frequencyHz = 4.0f; frontSuspToBikeDef.dampingRatio = 0.1f; frontSuspToBikeDef.collideConnected = true; world.CreateJoint(frontSuspToBikeDef); DistanceJointDef rearForkDistanceDef = new DistanceJointDef(); rearForkDistanceDef.Initialize(bikeBody, rearFork, rearFork.GetWorldCenter() + new Vector2(0, 0.4f), rearFork.GetWorldCenter()); rearForkDistanceDef.frequencyHz = 7.0f; rearForkDistanceDef.dampingRatio = 0.1f; rearForkDistanceDef.collideConnected = true; world.CreateJoint(rearForkDistanceDef); PrismaticJointDef fSuspBikePrismaticDef = new PrismaticJointDef(); fSuspBikePrismaticDef.Initialize(bikeBody, frontFork, bikeBody.GetWorldCenter(), new Vector2(0, 1)); fSuspBikePrismaticDef.enableLimit = true; fSuspBikePrismaticDef.lowerTranslation = -0.2f; fSuspBikePrismaticDef.upperTranslation = 0.2f; fSuspBikePrismaticDef.collideConnected = true; world.CreateJoint(fSuspBikePrismaticDef); humanBody = CreateBoxPart("human", humanBodyInitPos, 17.0f, 64.0f, 0, 0.1f, 1.0f, 0.2f); head = CreateBoxPart("head", headInitPos, 38.4f, 29.9f, headInitRot, 0.1f, 1.0f, 0.2f); hand = CreateBoxPart("hand", handInitPos, 34.13f, 8.53f, handInitRot, 0.1f, 1.0f, 0.2f); arm = CreateBoxPart("arm", armInitPos, 42.67f, 8.53f, armInitRot, 0.1f, 1.0f, 0.2f); WeldJointDef headToHumanDef = new WeldJointDef(); headToHumanDef.Initialize(head, humanBody, head.GetWorldCenter()); world.CreateJoint(headToHumanDef); RevoluteJointDef humanToBikeDef = new RevoluteJointDef(); anchor = humanBody.GetWorldCenter(); anchor.Y += (30.0f / Level.FACTOR); humanToBikeDef.Initialize(humanBody, bikeBody, anchor); humanToBikeDef.maxMotorTorque = 300.0f; humanToBike = world.CreateJoint(humanToBikeDef); RevoluteJointDef humanToArmDef = new RevoluteJointDef(); anchor = arm.GetWorldPoint(new Vector2(-21.33f / Level.FACTOR, 4.26f / Level.FACTOR)); humanToArmDef.Initialize(humanBody, arm, anchor); humanToArmDef.maxMotorTorque = 300.0f; world.CreateJoint(humanToArmDef); RevoluteJointDef armToHandDef = new RevoluteJointDef(); anchor = arm.GetWorldPoint(new Vector2(21.33f / Level.FACTOR, 4.26f / Level.FACTOR)); armToHandDef.Initialize(arm, hand, anchor); armToHandDef.maxMotorTorque = 300.0f; world.CreateJoint(armToHandDef); RevoluteJointDef handToBikeDef = new RevoluteJointDef(); anchor = hand.GetWorldPoint(new Vector2(17.06f / Level.FACTOR, 4.26f / Level.FACTOR)); handToBikeDef.Initialize(hand, bikeBody, anchor); handToBikeDef.maxMotorTorque = 300.0f; handToBike = world.CreateJoint(handToBikeDef); DistanceJointDef armToBikeDef = new DistanceJointDef(); armToBikeDef.Initialize(hand, bikeBody, hand.GetWorldPoint(new Vector2(-17.00f / Level.FACTOR, 4.26f / Level.FACTOR)), bikeBody.GetWorldCenter()); armToBikeDef.length = 40.0f / Level.FACTOR; armToBikeDef.frequencyHz = 10.0f; armToBikeDef.dampingRatio = 1.0f; armToBikeDef.collideConnected = true; armToBike = world.CreateJoint(armToBikeDef); }
public override void OnUpdateComplete(GameTime gameTime) { base.OnUpdateComplete(gameTime); if (isDoorOpen && rOpenBed != null) { world.DestroyJoint(rOpenBed); rOpenBed = null; } }
public override void OnUpdateComplete(GameTime gameTime) { base.OnUpdateComplete(gameTime); if (signalHit) { signalHit = false; if (rSignal != null) { world.DestroyJoint(rSignal); rSignal = null; } } if (needsTeleport) { needsTeleport = false; teleporter.Teleport(walker, 0); } }
void CreateWheels() { float width = gameContent.playerCar.Width, height = gameContent.playerCar.Height; Vector2 halfws = wheelSize / 2 / gameContent.Scale; PolygonShape ps = new PolygonShape(); BodyDef bd = new BodyDef(); bd.type = BodyType.Dynamic; FixtureDef fd = new FixtureDef(); fd.density = 0.1f; // Steer Wheel bd.position = body.Position + new Vector2(0, -(height - width / 2)) / gameContent.Scale; ps.SetAsBox(halfws.X, halfws.Y); fd.shape = ps; steerWheel = world.CreateBody(bd); steerWheel.CreateFixture(fd); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.Initialize(body, steerWheel, steerWheel.GetWorldCenter()); rjd.enableMotor = true; rjd.maxMotorTorque = 100; steerJoint = world.CreateJoint(rjd) as RevoluteJoint; // Drive Wheel bd.position = body.Position + new Vector2(0, -halfws.Y); ps.SetAsBox(halfws.X, halfws.Y); fd.shape = ps; driveWheel = world.CreateBody(bd); driveWheel.CreateFixture(fd); PrismaticJointDef pjd = new PrismaticJointDef(); pjd.Initialize(body, driveWheel, driveWheel.GetWorldCenter(), new Vector2(1, 0)); pjd.lowerTranslation = pjd.upperTranslation = 0; pjd.enableLimit = true; world.CreateJoint(pjd); }
internal static Joint Create(JointDef def) { Joint joint = null; switch (def.type) { case JointType.Distance: { joint = new DistanceJoint((DistanceJointDef)def); } break; case JointType.Mouse: { joint = new MouseJoint((MouseJointDef)def); } break; case JointType.Prismatic: { joint = new PrismaticJoint((PrismaticJointDef)def); } break; case JointType.Revolute: { joint = new RevoluteJoint((RevoluteJointDef)def); } break; case JointType.Pulley: { joint = new PulleyJoint((PulleyJointDef)def); } break; case JointType.Gear: { joint = new GearJoint((GearJointDef)def); } break; case JointType.Line: { joint = new LineJoint((LineJointDef)def); } break; case JointType.Weld: { joint = new WeldJoint((WeldJointDef)def); } break; case JointType.Friction: { joint = new FrictionJoint((FrictionJointDef)def); } break; case JointType.MaxDistance: { joint = new MaxDistanceJoint((MaxDistanceJointDef)def); } break; default: Debug.Assert(false); break; } return(joint); }