private static Filter newContactFilter(short categoryBits, short groupIndex, short maskBits) { Filter filter = new Filter(); filter.categoryBits = categoryBits; filter.groupIndex = groupIndex; filter.maskBits = maskBits; return filter; }
// Applies filter to ALL fixtures that have been added so far public void setFilter(short category, short mask) { for (Fixture f : scene.getFixtures()) { Filter filter = f.getFilterData(); filter.categoryBits = category; filter.maskBits = mask; f.setFilterData(filter); } }
public void setBits(short cat, short mask) { Filter filter = new Filter(); filter.categoryBits = cat; filter.maskBits = mask; for (Fixture f : body.getFixtureList()) { f.setFilterData(filter); } }
public void hit() { Gyaya.manager.get("audio/music/background.ogg", Music.class).stop(); Gyaya.manager.get("audio/sounds/uaBArt - Bell.mp3", Sound.class).play(); playerIsDead = true; Filter filter = new Filter(); filter.maskBits = Gyaya.NOTHING_BIT; for (Fixture fixture : b2body.getFixtureList()) fixture.setFilterData(filter); b2body.setLinearVelocity(new Vector2(0, 4f)); }
public void killed() { currentState = State.DEAD; Filter filter = new Filter(); filter.maskBits = SuperMario.NOTHING_BIT; for (Fixture fixture : b2body.getFixtureList()) { fixture.setFilterData(filter); } b2body.applyLinearImpulse(new Vector2(0, 5f), b2body.getWorldCenter(), true); }
@Override protected void initBody(final World world, final Rectangle bounds) { super.initBody(world, bounds); // By default in character class, category = player and mask = ground Filter filter = body.getFixtureList().get(0).getFilterData(); filter.categoryBits = B2DVars.ENEMY_MASK; filter.maskBits = B2DVars.GROUND_MASK | B2DVars.PROJECTILE_MASK | B2DVars.PLAYER_MASK; body.getFixtureList().get(0).setFilterData(filter); }
/** Kill the enemy */ public void kill() { state = State.BUMP; stateTime = 0f; // Now don't collide with player or projectile anymore // He is dead, but we can't remove it now until animation is done Filter filter = body.getFixtureList().get(0).getFilterData(); filter.categoryBits = B2DVars.ENEMY_MASK; filter.maskBits = B2DVars.GROUND_MASK; body.getFixtureList().get(0).setFilterData(filter); }
public OtherBoss() { super("Qubo"); health = maxHealth = 50; size.getTarget().set(2, 2); fixture = rectCollision(2, 2); Filter filter = new Filter(); filter.categoryBits = 0x80; filter.maskBits = 0x7; fixture.setFilterData(filter); fixture.setDensity(9999); damageOnTouch = 1.5f; DomeHat wh = new DomeHat(this, new Vector2(0, 1.2f)); GameScreen.i.getEntities().add(wh); }
public void hit(Enemy enemy) { if (enemy instanceof Turtle && ((Turtle) enemy).currentState == Turtle.State.STANDING_SHELL) ((Turtle) enemy) .kick( enemy.b2body.getPosition().x > b2body.getPosition().x ? Turtle.KICK_RIGHT : Turtle.KICK_LEFT); else { if (marioIsBig) { marioIsBig = false; timeToRedefineMario = true; setBounds(getX(), getY(), getWidth(), getHeight() / 2); MarioBros.manager.get("audio/sounds/powerdown.wav", Sound.class).play(); } else { 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); } } }
private Body createBody(float x, float y, float width, float height, boolean sensor) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.KinematicBody; bodyDef.position.set(new Vector2(x, y)); bodyDef.allowSleep = true; PolygonShape shape = new PolygonShape(); shape.setAsBox(width / 2, height / 2, new Vector2(0, 0), 0); Body _body = WorldUtils.world.createBody(bodyDef); Fixture fixture = _body.createFixture(shape, 1.0f); fixture.setFriction(0); fixture.setSensor(sensor); if (!sensor) { fixture.setUserData(Constants.POTION_FIXTURE); } else { fixture.setUserData(Constants.NOT_COLLIDER_FIXTURE); } Filter filter = new Filter(); filter.categoryBits = Constants.COLLISION_CREATURE; filter.maskBits = Constants.COLLISION_GROUND + Constants.COLLISION_CREATURE + Constants.COLLISION_FIELD; fixture.setFilterData(filter); _body.setUserData(this); return _body; }