当前位置: 首页>>代码示例>>Java>>正文


Java World类代码示例

本文整理汇总了Java中com.badlogic.gdx.physics.box2d.World的典型用法代码示例。如果您正苦于以下问题:Java World类的具体用法?Java World怎么用?Java World使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


World类属于com.badlogic.gdx.physics.box2d包,在下文中一共展示了World类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Extracts common values from the definition parameter map, and calls finishCreate to allow
 * subclasses to further initialize themselves. Subclasses should override finishCreate, and
 * should not override this method.
 */
public void initialize(Map<String, ?> params, FieldElementCollection collection, World world)
        throws DependencyNotAvailableException {
    this.parameters = params;
    this.box2dWorld = world;
    this.elementID = (String)params.get(ID_PROPERTY);

    @SuppressWarnings("unchecked")
    List<Number> colorList = (List<Number>)params.get(COLOR_PROPERTY);
    if (colorList!=null) {
        this.initialColor = Color.fromList(colorList);
    }

    if (params.containsKey(SCORE_PROPERTY)) {
        this.score = ((Number)params.get(SCORE_PROPERTY)).longValue();
    }

    this.finishCreateElement(params, collection);
    this.createBodies(world);
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:25,代码来源:FieldElement.java

示例2: createBodies

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
@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.
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:26,代码来源:FlipperElement.java

示例3: createCircle

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/** Creates a circle object with the given position and radius. Resitution defaults to 0.6. */
public static Body createCircle(World world, float x, float y, float radius, boolean isStatic) {
    CircleShape sd = new CircleShape();
    sd.setRadius(radius);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = sd;
    fdef.density = 1.0f;
    fdef.friction = 0.3f;
    fdef.restitution = 0.6f;

    BodyDef bd = new BodyDef();
    bd.allowSleep = true;
    bd.position.set(x, y);
    Body body = world.createBody(bd);
    body.createFixture(fdef);
    if (isStatic) {
        body.setType(BodyDef.BodyType.StaticBody);
    }
    else {
        body.setType(BodyDef.BodyType.DynamicBody);
    }
    return body;
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:25,代码来源:Box2DFactory.java

示例4: createWall

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax),
 * and rotating the box counterclockwise through the given angle, with specified restitution.
 */
public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax,
        float angle, float restitution) {
    float cx = (xmin + xmax) / 2;
    float cy = (ymin + ymax) / 2;
    float hx = Math.abs((xmax - xmin) / 2);
    float hy = Math.abs((ymax - ymin) / 2);
    PolygonShape wallshape = new PolygonShape();
    // Don't set the angle here; instead call setTransform on the body below. This allows future
    // calls to setTransform to adjust the rotation as expected.
    wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = wallshape;
    fdef.density = 1.0f;
    if (restitution>0) fdef.restitution = restitution;

    BodyDef bd = new BodyDef();
    bd.position.set(cx, cy);
    Body wall = world.createBody(bd);
    wall.createFixture(fdef);
    wall.setType(BodyDef.BodyType.StaticBody);
    wall.setTransform(cx, cy, angle);
    return wall;
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:29,代码来源:Box2DFactory.java

示例5: initFromLevel

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
void initFromLevel(Map<String, ?> layoutMap, World world) {
    this.width = asFloat(layoutMap.get(WIDTH_PROPERTY), 20.0f);
    this.height = asFloat(layoutMap.get(HEIGHT_PROPERTY), 30.0f);
    this.gravity = asFloat(layoutMap.get(GRAVITY_PROPERTY), 4.0f);
    this.targetTimeRatio = asFloat(layoutMap.get(TARGET_TIME_RATIO_PROPERTY));
    this.numberOfBalls = asInt(layoutMap.get(NUM_BALLS_PROPERTY), 3);
    this.ballRadius = asFloat(layoutMap.get(BALL_RADIUS_PROPERTY), 0.5f);
    this.ballColor = colorFromMap(layoutMap, BALL_COLOR_PROPERTY, DEFAULT_BALL_COLOR);
    this.secondaryBallColor = colorFromMap(
            layoutMap, SECONDARY_BALL_COLOR_PROPERTY, DEFAULT_SECONDARY_BALL_COLOR);
    this.launchPosition = asFloatList(listForKey(layoutMap, LAUNCH_POSITION_PROPERTY));
    this.launchVelocity = asFloatList(listForKey(layoutMap, LAUNCH_VELOCITY_PROPERTY));
    this.launchVelocityRandomDelta = asFloatList(
            listForKey(layoutMap, LAUNCH_RANDOM_VELOCITY_PROPERTY));
    this.launchDeadZoneRect = asFloatList(listForKey(layoutMap, LAUNCH_DEAD_ZONE_PROPERTY));

    this.allParameters = layoutMap;
    this.fieldElements = createFieldElements(layoutMap, world);
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:20,代码来源:FieldLayout.java

示例6: makePlatform

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Creates a pivoted platform from the given object, at the given world.
 *
 * @param world  The world were the platform will be.
 * @param object The object used to initialize the platform.
 * @return The Platform Model of the created platform.
 */
static PlatformModel makePlatform(World world, RectangleMapObject object) {
    PlatformModel platform = new PlatformModel(world, object);

    Boolean pivoted = object.getProperties().get("pivoted", boolean.class);
    if (pivoted != null && pivoted == true) {
        Rectangle rect = object.getRectangle();
        RectangleMapObject anchorRect = new RectangleMapObject(
                rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2, 1, 1
        );
        Body anchor = makeRectGround(world, anchorRect);

        RevoluteJointDef jointDef = new RevoluteJointDef();
        jointDef.initialize(anchor, platform.getBody(), platform.getBody().getWorldCenter());
        world.createJoint(jointDef);
    }

    return platform;
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:26,代码来源:B2DFactory.java

示例7: makePolygonGround

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Creates polygon ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makePolygonGround(World world, PolygonMapObject object) {
    Polygon polygon = object.getPolygon();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * polygon.getX(), PIXEL_TO_METER * polygon.getY());

    Body body = world.createBody(bdef);

    float[] new_vertices = polygon.getVertices().clone();
    for (int i = 0; i < new_vertices.length; i++)
        new_vertices[i] *= PIXEL_TO_METER;

    shape.set(new_vertices);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:32,代码来源:B2DFactory.java

示例8: makeRectGround

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Creates rectangular ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makeRectGround(World world, RectangleMapObject object) {
    Rectangle rect = object.getRectangle();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    Body body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:28,代码来源:B2DFactory.java

示例9: makePowerUp

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Creates a PowerUp from the given object, at the given world.
 *
 * @param world  The world were the PowerUp will be.
 * @param object The object used to initialize the PowerUp.
 * @return The created PowerUp.
 */
static PowerUp makePowerUp(World world, RectangleMapObject object) {
    String classProperty = object.getProperties().get("class", String.class);
    if (classProperty == null) {
        System.err.println("PowerUp has no class set!");
        return null;
    }

    switch (classProperty) {
        case "gravity":
            return new GravityPowerUp(world, object);
        case "velocity":
            return new SpeedPowerUp(world, object);
        case "jump":
            return new JumpPowerUp(world, object);
        default:
            return new RandomPowerUp(world, object);
    }
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:26,代码来源:B2DFactory.java

示例10: BoxModel

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Box's Constructor.
 * Creates a Box in the given with world, from the given object.
 *
 * @param world  Physics world where the box will be in.
 * @param object Object used to create the box.
 */
public BoxModel(World world, RectangleMapObject object) {
    super(world, object.getRectangle().getCenter(new Vector2()).scl(PIXEL_TO_METER), ModelType.BOX, ANGULAR_DAMP, LINEAR_DAMP);

    // Fetch density from properties
    Float property = object.getProperties().get("density", float.class);
    if (property != null)
        density = property;

    // Create Fixture's Shape
    Shape shape = createPolygonShape(new float[]{
            0, 0, 64, 0, 64, 64, 0, 64
    }, new Vector2(64, 64));

    createFixture(new FixtureProperties(shape, density, FRICTION, RESTITUTION, GROUND_BIT, (short) (BALL_BIT | GROUND_BIT | FLUID_BIT)));
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:23,代码来源:BoxModel.java

示例11: WaterModel

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
/**
 * Water Model's constructor.
 * Creates a water model from the given object, into the given world.
 *
 * @param world The world the water model will be in.
 * @param rect  The rectangle to create the water model with.
 */
public WaterModel(World world, Rectangle rect) {
    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    this.body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = FLUID_BIT;
    fdef.isSensor = true;
    fdef.density = 1f;
    fdef.friction = 0.1f;
    fdef.restitution = 0f;
    body.createFixture(fdef);

    body.setUserData(new BuoyancyController(world, body.getFixtureList().first()));

}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:31,代码来源:WaterModel.java

示例12: loadStaticBodies

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
public void loadStaticBodies(String bodylayer, TiledMap tiledMap) {

	world = new World(new Vector2(0, -5), true);
	// loop each object group.
	// a object group is all objects in a layer.
	for (int i = 0; i < tiledMap.objectGroups.size(); i++) {
	    TiledObjectGroup group = tiledMap.objectGroups.get(i);

	    // Find the object group of "static" layer
	    if (bodylayer.equals(group.name)) {
		// foreach objects in this group
		for (int j = 0; j < group.objects.size(); j++) {
		    TiledObject object = group.objects.get(j);
		    // create static body from the object
		    createStaticBody(object);
		}
	    }
	}
    }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:20,代码来源:PhysicsManager.java

示例13: loadStaticBodies

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
protected void loadStaticBodies(String bodylayer) {

		world = new World(new Vector2(0, -5), true);
		// loop each object group.
		// a object group is all objects in a layer.
		for (int i = 0; i < tiledMap.objectGroups.size(); i++) {
			TiledObjectGroup group = tiledMap.objectGroups.get(i);

			// Find the object group of "static" layer
			if (bodylayer.equals(group.name)) {
				// foreach objects in this group
				for (int j = 0; j < group.objects.size(); j++) {
					TiledObject object = group.objects.get(j);
					// create static body from the object
					createStaticBody(object);
				}
			}
		}
	}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:20,代码来源:PhysicsTiledScene.java

示例14: InteractiveTileObject

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
public InteractiveTileObject(World world, TiledMap map, Rectangle bounds){
    this.world = world;
    this.map = map;
    this.bounds = bounds;

    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set((bounds.getX() + bounds.getWidth() / 2) / NoObjectionGame.PPM, (bounds.getY() + bounds.getHeight() / 2 )/ NoObjectionGame.PPM);

    body = world.createBody(bdef);
    shape.setAsBox(bounds.getWidth() / 2 / NoObjectionGame.PPM, bounds.getHeight() / 2 / NoObjectionGame.PPM);
    fdef.shape = shape;
    fixture = body.createFixture(fdef);
}
 
开发者ID:MissionBit,项目名称:summer17-android,代码行数:18,代码来源:InteractiveTileObject.java

示例15: createSpinner

import com.badlogic.gdx.physics.box2d.World; //导入依赖的package包/类
public static Body createSpinner(World world) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(Constants.SPINNER_POSITIONS);
    Body body = world.createBody(bodyDef);
    CircleShape circle = new CircleShape();
    circle.setRadius(Constants.SPINNER_SIZE);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;
    fixtureDef.density = Constants.SPENNER_DENSITY;
    fixtureDef.friction = 0f;
    fixtureDef.restitution = 0.45f;
    body.createFixture(fixtureDef);
    circle.dispose();
    return body;
}
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:17,代码来源:WorldUtils.java


注:本文中的com.badlogic.gdx.physics.box2d.World类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。