public CirclePlatform (int x, int y, float radius, float da) { platform = createCircle(BodyType.KinematicBody, radius, 1); platform.setTransform(x, y, 0); platform.getFixtureList().get(0).setUserData("p"); platform.setAngularVelocity(da); platform.setUserData(this); }
public MovingPlatform (float x, float y, float width, float height, float dx, float dy, float da, float maxDist) { platform = createBox(BodyType.KinematicBody, width, height, 1); pos.x = x; pos.y = y; dir.x = dx; dir.y = dy; this.maxDist = maxDist; platform.setTransform(pos, 0); platform.getFixtureList().get(0).setUserData("p"); platform.setAngularVelocity(da); platform.setUserData(this); }
protected void renderBody (Body body) { Transform transform = body.getTransform(); int len = body.getFixtureList().size; Array<Fixture> fixtures = body.getFixtureList(); for (int i = 0; i < len; i++) { Fixture fixture = fixtures.get(i); if (drawBodies) { if (body.isActive() == false && drawInactiveBodies) drawShape(fixture, transform, SHAPE_NOT_ACTIVE); else if (body.getType() == BodyType.StaticBody) drawShape(fixture, transform, SHAPE_STATIC); else if (body.getType() == BodyType.KinematicBody) drawShape(fixture, transform, SHAPE_KINEMATIC); else if (body.isAwake() == false) drawShape(fixture, transform, SHAPE_NOT_AWAKE); else drawShape(fixture, transform, SHAPE_AWAKE); } if (drawAABBs) { drawAABB(fixture, transform); } } }
protected void renderBody (Body body) { Transform transform = body.getTransform(); for (Fixture fixture : body.getFixtureList()) { if (drawBodies) { drawShape(fixture, transform, getColorByBody(body)); if (drawVelocities) { Vector2 position = body.getPosition(); drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR); } } if (drawAABBs) { drawAABB(fixture, transform); } } }
/** Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during * callbacks. * @warning This automatically deletes all associated shapes and joints. * @warning This function is locked during callbacks. */ public void destroyBody (Body body) { Array<JointEdge> jointList = body.getJointList(); while (jointList.size > 0) destroyJoint(body.getJointList().get(0).joint); jniDestroyBody(addr, body.addr); body.setUserData(null); this.bodies.remove(body.addr); Array<Fixture> fixtureList = body.getFixtureList(); while(fixtureList.size > 0) { Fixture fixtureToDelete = fixtureList.removeIndex(0); this.fixtures.remove(fixtureToDelete.addr).setUserData(null); freeFixtures.free(fixtureToDelete); } freeBodies.free(body); }
public static Ball create(World world, float x, float y, float radius, Color primaryColor, Color secondaryColor) { Body ballBody = Box2DFactory.createCircle(world, x, y, radius, false); ballBody.setBullet(true); // Default is radius of 0.5, if different we want the mass to be the same (could be // configurable if needed), so adjust density proportional to square of the radius. if (radius != 0.5f) { ballBody.getFixtureList().get(0).setDensity((0.5f*0.5f) / (radius*radius)); ballBody.resetMassData(); } return new Ball(ballBody, primaryColor, secondaryColor); }
public void draw(IFieldRenderer renderer) { CircleShape shape = (CircleShape)body.getFixtureList().get(0).getShape(); Vector2 center = body.getPosition(); float radius = shape.getRadius(); renderer.fillCircle(center.x, center.y, radius, primaryColor); // Draw a smaller circle to show the ball's rotation. float angle = body.getAngle(); float smallCenterX = center.x + (radius / 2) * MathUtils.cos(angle); float smallCenterY = center.y + (radius / 2) * MathUtils.sin(angle); renderer.fillCircle(smallCenterX, smallCenterY, radius / 4, secondaryColor); }
protected void renderBody (Body body) { Transform transform = body.getTransform(); for (Fixture fixture : body.getFixtureList()) { if (drawBodies) { drawShape(fixture, transform, getColorByBody(body)); if (drawVelocities) { Vector2 position = body.getPosition(); drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR); } } if (drawAABBs) { drawAABB(fixture, transform); } } }
@Override public void createBodies(World world) { this.anchorBody = Box2DFactory.createCircle(world, this.cx, this.cy, 0.05f, true); // Joint angle is 0 when flipper is horizontal. // The flipper needs to be slightly extended past anchorBody to rotate correctly. float ext = (this.flipperLength > 0) ? -0.05f : +0.05f; // Width larger than 0.12 slows rotation? this.flipperBody = Box2DFactory.createWall(world, cx+ext, cy-0.12f, cx+flipperLength, cy+0.12f, 0f); flipperBody.setType(BodyDef.BodyType.DynamicBody); flipperBody.setBullet(true); flipperBody.getFixtureList().get(0).setDensity(5.0f); jointDef = new RevoluteJointDef(); jointDef.initialize(anchorBody, flipperBody, new Vector2(this.cx, this.cy)); jointDef.enableLimit = true; jointDef.enableMotor = true; // counterclockwise rotations are positive, so flip angles for flippers extending left jointDef.lowerAngle = (this.flipperLength>0) ? this.minangle : -this.maxangle; jointDef.upperAngle = (this.flipperLength>0) ? this.maxangle : -this.minangle; jointDef.maxMotorTorque = 1000f; this.joint = (RevoluteJoint)world.createJoint(jointDef); flipperBodySet = Collections.singletonList(flipperBody); this.setEffectiveMotorSpeed(-this.downspeed); // Force flipper to bottom when field is first created. }
public void die() { if (!isDead()) { MarioBros.manager.get("audio/music/mario_music.ogg", Music.class).stop(); MarioBros.manager.get("audio/sounds/mariodie.wav", Sound.class).play(); marioIsDead = true; Filter filter = new Filter(); filter.maskBits = MarioBros.NOTHING_BIT; for (Fixture fixture : b2body.getFixtureList()) { fixture.setFilterData(filter); } b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.getWorldCenter(), true); } }
/** Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during * callbacks. * @warning This automatically deletes all associated shapes and joints. * @warning This function is locked during callbacks. */ public void destroyBody (Body body) { Array<JointEdge> jointList = body.getJointList(); while (jointList.size > 0) destroyJoint(body.getJointList().get(0).joint); jniDestroyBody(addr, body.addr); body.setUserData(null); this.bodies.remove(body.addr); Array<Fixture> fixtureList = body.getFixtureList(); while(fixtureList.size > 0) { Fixture fixtureToDelete = fixtureList.removeIndex(0); this.fixtures.remove(fixtureToDelete.addr).setUserData(null); freeFixtures.free(fixtureToDelete); } freeBodies.free(body); }
for(Fixture f : b.getFixtureList()) { b.destroyFixture(f);
Array<Fixture> fs = body.getFixtureList(); for (Fixture f : fs) { f.setUserData(carType);
Filter filter = body.getFixtureList().get(0).getFilterData(); filter.maskBits = Player.invincibleMaskBit; body.getFixtureList().get(0).setFilterData(filter); renderer.setColor(new Color(1, 1, 1, 1.2f + MathUtils.sin(player.invincibleCountDown * 24))); } else { Filter filter = body.getFixtureList().get(0).getFilterData(); filter.maskBits = Player.defaultMaskBits; body.getFixtureList().get(0).setFilterData(filter); renderer.setColor(Color.WHITE); case DYING: state.setCurrentState("dying"); Filter filter = body.getFixtureList().get(0).getFilterData(); filter.maskBits = GameManager.NOTHING_BIT; body.getFixtureList().get(0).setFilterData(filter);
case DYING: state.setCurrentState("dying"); Filter filter = body.getFixtureList().get(0).getFilterData(); filter.maskBits = GameManager.NOTHING_BIT; body.getFixtureList().get(0).setFilterData(filter);
case DYING: state.setCurrentState("dying"); Filter filter = body.getFixtureList().get(0).getFilterData(); filter.maskBits = GameManager.NOTHING_BIT; body.getFixtureList().get(0).setFilterData(filter);
case DYING: state.setCurrentState("dying"); Filter filter = body.getFixtureList().get(0).getFilterData(); filter.maskBits = GameManager.NOTHING_BIT; body.getFixtureList().get(0).setFilterData(filter);