public static Joint addRevolute( World world, Body bodyA, Body bodyB, float lowerAngle, float upperAngle, Vector2 anchor) { RevoluteJointDef joint = new RevoluteJointDef(); if (lowerAngle != 0f || upperAngle != 0f) joint.enableLimit = true; joint.lowerAngle = lowerAngle; joint.upperAngle = upperAngle; joint.motorSpeed = 1; joint.maxMotorTorque = 1; joint.initialize(bodyA, bodyB, anchor); return world.createJoint(joint); }
public Car( World world, int CarNum, int ColorNum, int playerNum, ScreenAssets assets, boolean testing) { this.playerNum = playerNum; this.carNum = CarNum; this.assets = assets; whichCar(CarNum, ColorNum); if (testing) { if (GameScreen.getMapNum() == 0) { lapCounter = 4; } else { lapCounter = 1; } } car_car = assets.manager.get(ScreenAssets.car_car_sound); car_wall1 = assets.manager.get(ScreenAssets.car_wall_sound1); car_wall2 = assets.manager.get(ScreenAssets.car_wall_sound2); car_wall3 = assets.manager.get(ScreenAssets.car_wall_sound3); car_Tire = assets.manager.get(ScreenAssets.car_tire_sound); car_lap_complete = assets.manager.get(ScreenAssets.lap_complete_sound); car_fueling = assets.manager.get(ScreenAssets.refueling_loop); car_going_on_fuel = assets.manager.get(ScreenAssets.getting_on_fuel_sound); fuelAreas = new Array<FuelAreaType>(); currentCheckpoints = new Array<Integer>(); tires = new Array<Tire>(); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.DynamicBody; bodyDef.position.set(InitialPosition); body = world.createBody(bodyDef); body.setAngularDamping(3); Vector2[] vertices = new Vector2[8]; vertices[0] = new Vector2(0.75f, -2.5f); vertices[1] = new Vector2(1.5f, -2f); vertices[2] = new Vector2(1.5f, 2f); vertices[3] = new Vector2(0.75f, 2.5f); vertices[4] = new Vector2(-0.75f, 2.5f); vertices[5] = new Vector2(-1.5f, 2f); vertices[6] = new Vector2(-1.5f, -2f); vertices[7] = new Vector2(-0.75f, -2.5f); PolygonShape polygonShape = new PolygonShape(); polygonShape.set(vertices); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = polygonShape; fixtureDef.isSensor = false; fixtureDef.density = density; fixtureDef.filter.categoryBits = Constants.CAR; fixtureDef.filter.maskBits = Constants.GROUND | Constants.TIREOBS | Constants.CAR | Constants.WALL | Constants.FUEL | Constants.FINISH | Constants.BRIDGE | Constants.METAL | Constants.ICE; Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(new CarType(carSprite, this)); // body.applyTorque(1000, true); carSprite = new Sprite(new Texture(carLink)); carSprite.setSize(3, 6); carSprite.setOrigin(carSprite.getWidth() / 2, carSprite.getHeight() / 2); body.setUserData(new CarType(carSprite, this)); RevoluteJointDef jointDef = new RevoluteJointDef(); jointDef.bodyA = body; jointDef.enableLimit = true; jointDef.lowerAngle = 0; jointDef.upperAngle = 0; jointDef.localAnchorB.setZero(); float maxForwardSpeed = maxFSpeed; float maxBackwardSpeed = maxBSpeed; float backTireMaxDriveForce = backTireMDriveForce; float frontTireMaxDriveForce = frontTireMDriveForce; float backTireMaxLateralImpulse = backTireMLateralImpulse; float frontTireMaxLateralImpulse = frontTireMLateralImpulse; float breakingForcePourcentage = breakingFPourcentage; // Lower Left Tire tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, backTireMaxDriveForce, backTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(-1.125f, -1.5f); world.createJoint(jointDef); tires.add(tire); // Lower Right tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, backTireMaxDriveForce, backTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(1.125f, -1.5f); world.createJoint(jointDef); tires.add(tire); // Upper Left tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, frontTireMaxDriveForce, frontTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(-1.125f, 1.5f); leftJoint = (RevoluteJoint) world.createJoint(jointDef); tires.add(tire); // Upper Right tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, frontTireMaxDriveForce, frontTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(1.125f, 1.5f); rightJoint = (RevoluteJoint) world.createJoint(jointDef); tires.add(tire); } // end of car