public void update (float deltaTime) { dist += dir.len() * deltaTime; if (dist > maxDist) { dir.scl(-1); dist = 0; } platform.setLinearVelocity(dir); } }
private void launch () { m_body.setTransform(new Vector2(0, 20), 0); m_angularVelocity = (float)Math.random() * 100 - 50; m_body.setLinearVelocity(new Vector2(0, -100)); m_body.setAngularVelocity(m_angularVelocity); }
@Override public boolean keyDown (int keyCode) { if (keyCode == Keys.D) m_platform.setType(BodyType.DynamicBody); if (keyCode == Keys.S) m_platform.setType(BodyType.StaticBody); if (keyCode == Keys.K) { m_platform.setType(BodyType.KinematicBody); m_platform.setLinearVelocity(tmp.set(-m_speed, 0)); m_platform.setAngularVelocity(0); } return false; }
@Override public void render () { if (m_platform.getType() == BodyType.KinematicBody) { Vector2 p = m_platform.getTransform().getPosition(); Vector2 v = m_platform.getLinearVelocity(); if ((p.x < -10 && v.x < 0) || (p.x > 10 && v.x > 0)) { v.x = -v.x; m_platform.setLinearVelocity(v); } } super.render(); // if (renderer.batch != null) { // renderer.batch.begin(); // // renderer.batch.drawText(renderer.font, "Keys: (d) dynamic, (s) static, (k) kinematic", 0, Gdx.app.getGraphics() // // .getHeight(), Color.WHITE); // renderer.batch.end(); // } } }
@Override public boolean keyDown (int keyCode) { if (keyCode == Input.Keys.COMMA) { if (m_bullet != null) { world.destroyBody(m_bullet); m_bullet = null; } { CircleShape shape = new CircleShape(); shape.setRadius(0.25f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 20.0f; fd.restitution = 0.05f; BodyDef bd = new BodyDef(); bd.type = BodyType.DynamicBody; bd.bullet = true; bd.position.set(-31, 5); m_bullet = world.createBody(bd); m_bullet.createFixture(fd); m_bullet.setLinearVelocity(new Vector2(400, 0)); } } return false; }
player.setLinearVelocity(vel.x, vel.y); player.setLinearVelocity(vel.x * 0.9f, vel.y); } else { stillTime = 0; jump = false; if (grounded) { player.setLinearVelocity(vel.x, 0); System.out.println("jump before: " + player.getLinearVelocity()); player.setTransform(pos.x, pos.y + 0.01f, 0);
public void create () { cam = new OrthographicCamera(48, 32); cam.position.set(0, 15, 0); renderer = new Box2DDebugRenderer(); world = new World(new Vector2(0, -10), true); Body body = world.createBody(new BodyDef()); CircleShape shape = new CircleShape(); shape.setRadius(1f); MassData mass = new MassData(); mass.mass = 1f; body.setMassData(mass); body.setFixedRotation(true); body.setType(BodyType.KinematicBody); body.createFixture(shape, 1); body.setBullet(true); body.setTransform(new Vector2(0, 0), body.getAngle()); body.setLinearVelocity(new Vector2(50f, 0)); }
@Override protected void createWorld (World world) { { BodyDef bd = new BodyDef(); bd.position.set(0, 0); Body body = world.createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vector2(-10, 0), new Vector2(10, 0)); body.createFixture(shape, 0); shape.dispose(); PolygonShape poly = new PolygonShape(); poly.setAsBox(0.2f, 1.0f, new Vector2(0.5f, 1.0f), 0); body.createFixture(poly, 0); poly.dispose(); } { BodyDef bd = new BodyDef(); bd.type = BodyType.DynamicBody; bd.position.set(0, 20); PolygonShape shape = new PolygonShape(); shape.setAsBox(2, 0.1f); m_body = world.createBody(bd); m_body.createFixture(shape, 1); m_angularVelocity = 33.468121f; m_body.setLinearVelocity(new Vector2(0, -100)); m_body.setAngularVelocity(m_angularVelocity); shape.dispose(); } }
public void resetPhysics () { body.setAngularVelocity(0); body.setLinearVelocity(0, 0); impacts = 0; }
@Override public void act(float delta) { super.act(delta); body.setLinearVelocity(getUserData().getLinearVelocity()); }
/** * Launches a new ball. The position and velocity of the ball are controlled by the parameters * in the field layout JSON. */ public Ball launchBall() { List<Float> position = layout.getLaunchPosition(); List<Float> velocity = layout.getLaunchVelocity(); float radius = layout.getBallRadius(); Ball ball = Ball.create(world, position.get(0), position.get(1), radius, layout.getBallColor(), layout.getSecondaryBallColor()); ball.getBody().setLinearVelocity(new Vector2(velocity.get(0), velocity.get(1))); this.balls.add(ball); audioPlayer.playBall(); return ball; }
@Override public void update(float dt) { setRegion(getFrame(dt)); if(currentState == State.STANDING_SHELL && stateTime > 5){ currentState = State.WALKING; velocity.x = 1; System.out.println("WAKE UP SHELL"); } setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - 8 /MarioBros.PPM); b2body.setLinearVelocity(velocity); }
@Override public void onBeforePhysicsSubstep () { super.onBeforePhysicsSubstep(); // let's subclasses behave as needed, ask them to fill carForces with new data onComputeCarForces(carForces); // trigger event, new forces have been computed if (triggerEvents) { GameEvents.playerCar.data.setForces(carForces); GameEvents.playerCar.trigger(this, CarEvent.Type.onPhysicsForcesReady); } // put newly computed forces into the system body.setLinearVelocity(carForces.velocity_x, carForces.velocity_y); body.setAngularVelocity(-carForces.angularVelocity); }
private void restart() { bottleModel.setTransform(0, 3, 0.2f); bottleModel.setLinearVelocity(0, 0); bottleModel.setAngularVelocity(0); ballModels[i].setLinearVelocity(vec.set(0, 0)); ballModels[i].setAngularVelocity(0); ballModels[i].setTransform(vec.set(tx, ty), angle);
@Override public void update(float dt) { super.update(dt); setPosition(body.getPosition().x - getWidth() / 2, body.getPosition().y - getHeight() / 2); velocity.y = body.getLinearVelocity().y; body.setLinearVelocity(velocity); } }
public void update(float dt){ stateTime += dt; if(setToDestroy && !destroyed){ world.destroyBody(b2body); destroyed = true; setRegion(new TextureRegion(screen.getAtlas().findRegion("goomba"), 32, 0, 16, 16)); stateTime = 0; } else if(!destroyed) { b2body.setLinearVelocity(velocity); setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - getHeight() / 2); setRegion(walkAnimation.getKeyFrame(stateTime, true)); } }
public void update(float dt){ stateTime += dt; setRegion(fireAnimation.getKeyFrame(stateTime, true)); setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - getHeight() / 2); if((stateTime > 3 || setToDestroy) && !destroyed) { world.destroyBody(b2body); destroyed = true; } if(b2body.getLinearVelocity().y > 2f) b2body.setLinearVelocity(b2body.getLinearVelocity().x, 2f); if((fireRight && b2body.getLinearVelocity().x < 0) || (!fireRight && b2body.getLinearVelocity().x > 0)) setToDestroy(); }
public void defineFireBall(){ BodyDef bdef = new BodyDef(); bdef.position.set(fireRight ? getX() + 12 /MarioBros.PPM : getX() - 12 /MarioBros.PPM, getY()); bdef.type = BodyDef.BodyType.DynamicBody; if(!world.isLocked()) b2body = world.createBody(bdef); FixtureDef fdef = new FixtureDef(); CircleShape shape = new CircleShape(); shape.setRadius(3 / MarioBros.PPM); fdef.filter.categoryBits = MarioBros.FIREBALL_BIT; fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT; fdef.shape = shape; fdef.restitution = 1; fdef.friction = 0; b2body.createFixture(fdef).setUserData(this); b2body.setLinearVelocity(new Vector2(fireRight ? 2 : -2, 2.5f)); }
@Test public void getSpeed() { Body body = BodyUtilities.createDummyBody(); body.setLinearVelocity(1f, 2f); final Shard shard = new Shard(body, drawables); assertTrue(shard.getVelocity().epsilonEquals(1f, 2f, 0.01f)); assertTrue(SHARD_CONSTANT.getVelocity().epsilonEquals(0f, 0f, 0.01f)); }
ballBody.setLinearVelocity(10, 10);