@Override public void initialize() { super.initialize(); // doStep true = not simulate inactive bodies world = new World(new Vector2(0.0f, 10.0f), true); world.setContinuousPhysics(true); world.setWarmStarting(true); world.setAutoClearForces(true); ValueMap valueMap = game.getGameState(); valueMap.setValue((String) null, VAR_PH_WORLD, world); velocityIterations = 24; positionIterations = 8; for (SceneElement e : effect.getElements()) { createBody(world, e, valueMap); } for (SceneElement e : effect.getJoints()) { createBody(world, e, valueMap); } RevoluteJointDef jd = new RevoluteJointDef(); jd.collideConnected = false; for (int i = 0; i < effect.getJoints().size() - 1; i += 2) { SceneElement e1 = effect.getJoints().get(i); SceneElement e2 = effect.getJoints().get(i + 1); Body b1 = (Body) valueMap.getValue(e1.getId(), VAR_PH_BODY, null); Body b2 = (Body) valueMap.getValue(e2.getId(), VAR_PH_BODY, null); jd.initialize(b2, b1, new Vector2(b1.getPosition().x, b1.getPosition().y)); world.createJoint(jd); } }
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 void createIceBall() { // gear base BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; bodyDef.position.x = x; bodyDef.position.y = y; CircleShape circleShape = new CircleShape(); circleShape.setRadius(1); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.isSensor = true; fixtureDef.shape = circleShape; gearBody = world.createBody(bodyDef); gearBody.createFixture(fixtureDef); circleShape = new CircleShape(); circleShape.setRadius(size); BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType.DynamicBody; boxBodyDef.position.x = x; boxBodyDef.position.y = y; fixtureDef = new FixtureDef(); fixtureDef.shape = circleShape; fixtureDef.friction = 0f; fixtureDef.density = 4.10f; fixtureDef.restitution = 1.5f; fixtureDef.isSensor = true; fixtureDef.filter.groupIndex = -1; gearBase = world.createBody(boxBodyDef); SpriteInfo spriteTemp = new SpriteInfo(assets.getSprite("star")); spriteTemp.setName("star"); gearBase.setUserData(spriteTemp); gearBase.createFixture(fixtureDef); // iceBody.createFixture(circleShape, .1f); RevoluteJointDef wheeljointDef = new RevoluteJointDef(); wheeljointDef.bodyA = gearBase; wheeljointDef.bodyB = gearBody; wheeljointDef.localAnchorA.y = 0; wheeljointDef.localAnchorB.y = 0; wheeljointDef.motorSpeed = .5f; wheeljointDef.enableMotor = true; wheeljointDef.maxMotorTorque = 100000f; // Joint joint = // wheeljointDef.bodyA.getWorld().createJoint(wheeljointDef); world.createJoint(wheeljointDef); circleShape.dispose(); }
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