private Body createEdge (BodyType type, float x1, float y1, float x2, float y2, float density) { BodyDef def = new BodyDef(); def.type = type; Body box = world.createBody(def); EdgeShape poly = new EdgeShape(); poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1)); box.createFixture(poly, density); box.setTransform(x1, y1, 0); poly.dispose(); return box; }
public void getVertex0 (Vector2 vec) { jniGetVertex0(addr, vertex); vec.x = vertex[0]; vec.y = vertex[1]; }
EdgeShape shape = new EdgeShape(); shape.set(new Vector2(-20, 0), new Vector2(20, 0)); ground.createFixture(shape, 0); shape.dispose(); EdgeShape shape = new EdgeShape(); shape.setRadius(0); shape.set(new Vector2(-8, 1), new Vector2(-6, 1)); ground.createFixture(shape, 0); shape.set(new Vector2(-6, 1), new Vector2(-4, 1)); ground.createFixture(shape, 0); shape.set(new Vector2(-4, 1), new Vector2(-2, 1)); ground.createFixture(shape, 0); shape.dispose(); EdgeShape shape = new EdgeShape(); float d = 2 * 2 * 0.005f; shape.setRadius(0); shape.set(new Vector2(-1 + d, 3), new Vector2(1 - d, 3)); ground.createFixture(shape, 0); shape.set(new Vector2(1, 3 + d), new Vector2(1, 5 - d)); ground.createFixture(shape, 0); shape.set(new Vector2(1 - d, 5), new Vector2(-1 + d, 5)); ground.createFixture(shape, 0); shape.set(new Vector2(-1, 5 - d), new Vector2(-1, 3 + d)); ground.createFixture(shape, 0); shape.dispose();
/** Returns the shape of this fixture */ public Shape getShape () { if (shape == null) { org.jbox2d.collision.shapes.Shape shape2 = fixture.getShape(); ShapeType type = shape2.getType(); if (type == ShapeType.CHAIN) shape = new ChainShape((org.jbox2d.collision.shapes.ChainShape)shape2); if (type == ShapeType.CIRCLE) shape = new CircleShape((org.jbox2d.collision.shapes.CircleShape)shape2); if (type == ShapeType.EDGE) shape = new EdgeShape((org.jbox2d.collision.shapes.EdgeShape)shape2); if (type == ShapeType.POLYGON) shape = new PolygonShape((org.jbox2d.collision.shapes.PolygonShape)shape2); } return shape; }
/** Set this as an isolated edge. */ public void set (Vector2 v1, Vector2 v2) { set(v1.x, v1.y, v2.x, v2.y); }
edge.getVertex1(vertices[0]); edge.getVertex2(vertices[1]); transform.mul(vertices[0]); transform.mul(vertices[1]);
public void defineMario(){ BodyDef bdef = new BodyDef(); bdef.position.set(32 / MarioBros.PPM, 32 / MarioBros.PPM); bdef.type = BodyDef.BodyType.DynamicBody; b2body = world.createBody(bdef); FixtureDef fdef = new FixtureDef(); CircleShape shape = new CircleShape(); shape.setRadius(6 / MarioBros.PPM); fdef.filter.categoryBits = MarioBros.MARIO_BIT; fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT | MarioBros.ITEM_BIT; fdef.shape = shape; b2body.createFixture(fdef).setUserData(this); EdgeShape head = new EdgeShape(); head.set(new Vector2(-2 / MarioBros.PPM, 6 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 6 / MarioBros.PPM)); fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT; fdef.shape = head; fdef.isSensor = true; b2body.createFixture(fdef).setUserData(this); }
EdgeShape shape = new EdgeShape(); shape.set(new Vector2(-20, 0), new Vector2(20, 0)); ground.createFixture(shape, 0); shape.dispose(); EdgeShape shape = new EdgeShape(); shape.setRadius(0); shape.set(new Vector2(-8, 1), new Vector2(-6, 1)); ground.createFixture(shape, 0); shape.set(new Vector2(-6, 1), new Vector2(-4, 1)); ground.createFixture(shape, 0); shape.set(new Vector2(-4, 1), new Vector2(-2, 1)); ground.createFixture(shape, 0); shape.dispose(); EdgeShape shape = new EdgeShape(); float d = 2 * 2 * 0.005f; shape.setRadius(0); shape.set(new Vector2(-1 + d, 3), new Vector2(1 - d, 3)); ground.createFixture(shape, 0); shape.set(new Vector2(1, 3 + d), new Vector2(1, 5 - d)); ground.createFixture(shape, 0); shape.set(new Vector2(1 - d, 5), new Vector2(-1 + d, 5)); ground.createFixture(shape, 0); shape.set(new Vector2(-1, 5 - d), new Vector2(-1, 3 + d)); ground.createFixture(shape, 0); shape.dispose();
/** Returns the shape of this fixture */ public Shape getShape () { if (shape == null) { long shapeAddr = jniGetShape(addr); if (shapeAddr == 0) throw new GdxRuntimeException("Null shape address!"); int type = Shape.jniGetType(shapeAddr); switch (type) { case 0: shape = new CircleShape(shapeAddr); break; case 1: shape = new EdgeShape(shapeAddr); break; case 2: shape = new PolygonShape(shapeAddr); break; case 3: shape = new ChainShape(shapeAddr); break; default: throw new GdxRuntimeException("Unknown shape type!"); } } return shape; }
/** Set this as an isolated edge. */ public void set (Vector2 v1, Vector2 v2) { set(v1.x, v1.y, v2.x, v2.y); }
edge.getVertex1(vertices[0]); edge.getVertex2(vertices[1]); transform.mul(vertices[0]); transform.mul(vertices[1]);
@Override protected void createWorld (World world) { { BodyDef bd = new BodyDef(); Body ground = world.createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vector2(-40, 0), new Vector2(40, 0)); ground.createFixture(shape, 0); shape.dispose(); } { CircleShape shape = new CircleShape(); shape.setRadius(1.0f); for (int i = 0; i < e_count; i++) { BodyDef bd = new BodyDef(); bd.type = BodyType.DynamicBody; bd.position.set(0, 4.0f + 3.0f * i); Body body = world.createBody(bd); body.createFixture(shape, 1.0f); } shape.dispose(); } }
public void redefineMario(){ Vector2 position = b2body.getPosition(); world.destroyBody(b2body); BodyDef bdef = new BodyDef(); bdef.position.set(position); bdef.type = BodyDef.BodyType.DynamicBody; b2body = world.createBody(bdef); FixtureDef fdef = new FixtureDef(); CircleShape shape = new CircleShape(); shape.setRadius(6 / MarioBros.PPM); fdef.filter.categoryBits = MarioBros.MARIO_BIT; fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT | MarioBros.ITEM_BIT; fdef.shape = shape; b2body.createFixture(fdef).setUserData(this); EdgeShape head = new EdgeShape(); head.set(new Vector2(-2 / MarioBros.PPM, 6 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 6 / MarioBros.PPM)); fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT; fdef.shape = head; fdef.isSensor = true; b2body.createFixture(fdef).setUserData(this); timeToRedefineMario = false; }
/** Returns the shape of this fixture */ public Shape getShape () { if (shape == null) { long shapeAddr = jniGetShape(addr); if (shapeAddr == 0) throw new GdxRuntimeException("Null shape address!"); int type = Shape.jniGetType(shapeAddr); switch (type) { case 0: shape = new CircleShape(shapeAddr); break; case 1: shape = new EdgeShape(shapeAddr); break; case 2: shape = new PolygonShape(shapeAddr); break; case 3: shape = new ChainShape(shapeAddr); break; default: throw new GdxRuntimeException("Unknown shape type!"); } } return shape; }
/** Set this as an isolated edge. */ public void set (Vector2 v1, Vector2 v2) { set(v1.x, v1.y, v2.x, v2.y); }
edge.getVertex1(vertices[0]); edge.getVertex2(vertices[1]); transform.mul(vertices[0]); transform.mul(vertices[1]);
public void getVertex0 (Vector2 vec) { jniGetVertex0(addr, vertex); vec.x = vertex[0]; vec.y = vertex[1]; }
public void defineBigMario(){ Vector2 currentPosition = b2body.getPosition(); world.destroyBody(b2body); BodyDef bdef = new BodyDef(); bdef.position.set(currentPosition.add(0, 10 / MarioBros.PPM)); bdef.type = BodyDef.BodyType.DynamicBody; b2body = world.createBody(bdef); FixtureDef fdef = new FixtureDef(); CircleShape shape = new CircleShape(); shape.setRadius(6 / MarioBros.PPM); fdef.filter.categoryBits = MarioBros.MARIO_BIT; fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT | MarioBros.ITEM_BIT; fdef.shape = shape; b2body.createFixture(fdef).setUserData(this); shape.setPosition(new Vector2(0, -14 / MarioBros.PPM)); b2body.createFixture(fdef).setUserData(this); EdgeShape head = new EdgeShape(); head.set(new Vector2(-2 / MarioBros.PPM, 6 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 6 / MarioBros.PPM)); fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT; fdef.shape = head; fdef.isSensor = true; b2body.createFixture(fdef).setUserData(this); timeToDefineBigMario = false; }