player.applyLinearImpulse(0, -24, pos.x, pos.y, true); player.applyLinearImpulse(-2f, 0, pos.x, pos.y, true); player.applyLinearImpulse(2f, 0, pos.x, pos.y, true); System.out.println("jump before: " + player.getLinearVelocity()); player.setTransform(pos.x, pos.y + 0.01f, 0); player.applyLinearImpulse(0, 40, pos.x, pos.y, true); System.out.println("jump, " + player.getLinearVelocity());
public void applyLinearImpulse(Vector2 impulse) { body.applyLinearImpulse(impulse, body.getWorldCenter(), true); }
public void jump(){ if ( currentState != State.JUMPING ) { b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.getWorldCenter(), true); currentState = State.JUMPING; } }
public void jump() { if (!(jumping || dodging || hit)) { body.applyLinearImpulse(getUserData().getJumpingLinearImpulse(), body.getWorldCenter(), true); jumping = true; } }
public void handleInput(float dt){ //control our player using immediate impulses if(player.currentState != Mario.State.DEAD) { if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) player.jump(); if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) && player.b2body.getLinearVelocity().x <= 2) player.b2body.applyLinearImpulse(new Vector2(0.1f, 0), player.b2body.getWorldCenter(), true); if (Gdx.input.isKeyPressed(Input.Keys.LEFT) && player.b2body.getLinearVelocity().x >= -2) player.b2body.applyLinearImpulse(new Vector2(-0.1f, 0), player.b2body.getWorldCenter(), true); if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) player.fire(); } }
private void createBall(Vector2 orig, Vector2 force) { Random rand = new Random(); float radius = rand.nextFloat() * 0.02f + 0.02f; BodyDef bd = new BodyDef(); bd.type = BodyType.DynamicBody; bd.angularDamping = 0.5f; bd.linearDamping = 0.5f; bd.position.set(orig); bd.angle = rand.nextFloat() * MathUtils.PI; Body b = world.createBody(bd); b.applyLinearImpulse(force, orig, true);//TODO probably a bug ballsBodies.add(b); CircleShape shape = new CircleShape(); shape.setRadius(radius); FixtureDef fd = new FixtureDef(); fd.density = 1f; fd.friction = 0.5f; fd.restitution = 1f; fd.shape = shape; b.createFixture(fd); Sprite sp = new Sprite(Assets.inst().get("data/ball.png", Texture.class)); sp.setSize(radius * 2, radius * 2); sp.setOrigin(sp.getWidth() / 2, sp.getHeight() / 2); ballsSprites.add(sp); }
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); } }
@Override public boolean touchUp(int x, int y, int arg2, int arg3) { Vector3 coordinates = new Vector3(x,y,0); camera.unproject(coordinates); if(lastTouchPolygon != null){ Vector2 impulse = new Vector2(coordinates.x, coordinates.y). sub(lastTouchCoordinates).scl(lastTouchPolygon.getMass()); Log.log("LiveMode.touchUp", "applying impulse: " + impulse + " on body: " + lastTouchPolygon.getPosition()); lastTouchPolygon.applyLinearImpulse(impulse, lastTouchPolygonLocalCoordinates.add(lastTouchPolygon.getPosition()),true); lastTouchCoordinates = null; lastTouchPolygon = null; lastTouchPolygonLocalCoordinates = null; } return false; }
state.setCurrentState("walking_left"); if (body.getLinearVelocity().x > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(-enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_right"); if (body.getLinearVelocity().x < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_up"); if (body.getLinearVelocity().y < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true); state.setCurrentState("walking_down"); if (body.getLinearVelocity().y > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, -enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true);
state.setCurrentState("walking_left"); if (body.getLinearVelocity().x > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(-enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_right"); if (body.getLinearVelocity().x < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(enemy.getSpeed() * body.getMass(), 0), body.getWorldCenter(), true); state.setCurrentState("walking_up"); if (body.getLinearVelocity().y < enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true); state.setCurrentState("walking_down"); if (body.getLinearVelocity().y > -enemy.getSpeed()) { body.applyLinearImpulse(new Vector2(0, -enemy.getSpeed() * body.getMass()), body.getWorldCenter(), true);
if (player.invincible || !hitBombVertical(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x, body.getPosition().y + 0.5f))) { if (Math.abs(linearVelocity.y) < maxSpeed) { body.applyLinearImpulse(new Vector2(0, player.acceleration * body.getMass()), body.getWorldCenter(), true); if (player.invincible || !hitBombVertical(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x, body.getPosition().y - 0.5f))) { if (Math.abs(linearVelocity.y) < maxSpeed) { body.applyLinearImpulse(new Vector2(0, -player.acceleration * body.getMass()), body.getWorldCenter(), true); if (player.invincible || !hitBombHorizontal(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x - 0.5f, body.getPosition().y))) { if (Math.abs(linearVelocity.x) < maxSpeed) { body.applyLinearImpulse(new Vector2(-player.acceleration * body.getMass(), 0), body.getWorldCenter(), true); if (player.invincible || !hitBombHorizontal(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x + 0.5f, body.getPosition().y))) { if (Math.abs(linearVelocity.x) < maxSpeed) { body.applyLinearImpulse(new Vector2(player.acceleration * body.getMass(), 0), body.getWorldCenter(), true);
body.applyLinearImpulse(toVector.scl(enemy.getSpeed()), body.getWorldCenter(), true);