com.badlogic.gdx.physics.box2d.Filter Java Examples

The following examples show how to use com.badlogic.gdx.physics.box2d.Filter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RayHandler.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
final boolean considerFixture( Fixture fixture ) {
	Filter filter = map.get( fixture );
	if( filter == null ) {
		filter = fixture.getFilterData();
		map.put( fixture, filter );
	}

	return ((requestingLight.maskBits & filter.categoryBits) != 0);
}
 
Example #2
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
public static FixtureDef createFixtureDef(final float pDensity, final float pElasticity, final float pFriction, final boolean pSensor, final short pCategoryBits, final short pMaskBits, final short pGroupIndex) {
	final FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.density = pDensity;
	fixtureDef.restitution = pElasticity;
	fixtureDef.friction = pFriction;
	fixtureDef.isSensor = pSensor;
	final Filter filter = fixtureDef.filter;
	filter.categoryBits = pCategoryBits;
	filter.maskBits = pMaskBits;
	filter.groupIndex = pGroupIndex;
	return fixtureDef;
}
 
Example #3
Source File: Light.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
boolean contactFilter(Fixture fixtureB) {
	Filter filterB = fixtureB.getFilterData();

	if (filterA.groupIndex != 0 &&
		filterA.groupIndex == filterB.groupIndex)
		return filterA.groupIndex > 0;

	return  (filterA.maskBits & filterB.categoryBits) != 0 &&
			(filterA.categoryBits & filterB.maskBits) != 0;
}
 
Example #4
Source File: Light.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new contact filter for this light with given parameters
 * 
 * @param categoryBits - see {@link Filter#categoryBits}
 * @param groupIndex   - see {@link Filter#groupIndex}
 * @param maskBits     - see {@link Filter#maskBits}
 */
public void setContactFilter(short categoryBits, short groupIndex,
		short maskBits) {
	filterA = new Filter();
	filterA.categoryBits = categoryBits;
	filterA.groupIndex = groupIndex;
	filterA.maskBits = maskBits;
}
 
Example #5
Source File: Light.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
boolean globalContactFilter(Fixture fixtureB) {
	Filter filterB = fixtureB.getFilterData();

	if (globalFilterA.groupIndex != 0 &&
		globalFilterA.groupIndex == filterB.groupIndex)
		return globalFilterA.groupIndex > 0;

	return  (globalFilterA.maskBits & filterB.categoryBits) != 0 &&
			(globalFilterA.categoryBits & filterB.maskBits) != 0;
}
 
Example #6
Source File: Light.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new contact filter for ALL LIGHTS with give parameters
 * 
 * @param categoryBits - see {@link Filter#categoryBits}
 * @param groupIndex   - see {@link Filter#groupIndex}
 * @param maskBits     - see {@link Filter#maskBits}
 */
static public void setGlobalContactFilter(short categoryBits, short groupIndex,
		short maskBits) {
	globalFilterA = new Filter();
	globalFilterA.categoryBits = categoryBits;
	globalFilterA.groupIndex = groupIndex;
	globalFilterA.maskBits = maskBits;
}
 
Example #7
Source File: EnemySystem.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
private void handleBoss1(int entityId) {
    Body body = rigidBody.body;
    ActorBuilder actorBuilder = ActorBuilder.init(body.getWorld(), world);

    if (boss1TargetCorners[boss1CurrentTarget].dst2(body.getPosition()) < 0.1f) {
        boss1CurrentTarget = MathUtils.random(0, 3);
    }

    if (enemy.receivedDamage > 0) {
        if (enemy.state != Enemy.State.DAMAGED) {
            enemy.damage(1);    // boss only take 1 damage per time

            // chance to create PowerUp item
            if (Math.random() < 0.2) {
                actorBuilder.createPowerUp(body.getPosition().x, body.getPosition().y - 2f);
            }
        }
        enemy.receivedDamage = 0;
        enemy.state = Enemy.State.DAMAGED;
    }

    if (enemy.hp <= 0) {
        enemy.state = Enemy.State.DYING;
    }

    enemy.lifetime += world.getDelta();

    // Boss1 attack
    if (enemy.hp > 0 && MathUtils.random() < 0.005) {
        enemy.state = Enemy.State.ATTACKING_DOWN;
    }

    switch (enemy.state) {
        case ATTACKING_LEFT:
        case ATTACKING_RIGHT:
        case ATTACKING_UP:
        case ATTACKING_DOWN:
            state.setCurrentState("attacking_down");
            if (state.getStateTime() > 0.6f) {
                actorBuilder.createExplosion(body.getPosition().x, body.getPosition().y - 4f, 1);
                GameManager.getInstance().playSound("Boss1Hammer.ogg");
                changeWalkingState(enemy);
            }
            break;
        case DAMAGED:
            state.setCurrentState("damaged");
            if (state.getStateTime() > 0.2f) {
                changeWalkingState(enemy);
            }
            break;
        case DYING:
            state.setCurrentState("dying");
            Filter filter = body.getFixtureList().get(0).getFilterData();
            filter.maskBits = GameManager.NOTHING_BIT;
            body.getFixtureList().get(0).setFilterData(filter);

            if (state.getStateTime() <= 0) {
                actorBuilder.createBoss1Explosion(body.getPosition().x, body.getPosition().y);
                enemy.lifetime = 0;
            }

            if (enemy.lifetime > 0.2f) {
                GameManager.getInstance().playSound("Explosion.ogg", 1.0f, MathUtils.random(0.9f, 1.1f), 0);
                enemy.lifetime -= 0.4f;
            }

            if (state.getStateTime() > 2.2f) {
                // decrease enemy count
                GameManager.enemiesLeft--;

                // if no enemy left, create the portal
                if (GameManager.enemiesLeft <= 0) {
                    actorBuilder.createPortal();
                    GameManager.getInstance().playSound("PortalAppears.ogg");
                    GameManager.getInstance().playMusic("Victory.ogg", false);
                }

                body.getWorld().destroyBody(body);
                world.delete(entityId);
            }
            break;
        case WALKING_LEFT:
        case WALKING_RIGHT:
        case WALKING_UP:
        case WALKING_DOWN:
        default:
            state.setCurrentState("walking_down");
            toVector.set(boss1TargetCorners[boss1CurrentTarget]);
            toVector.sub(body.getPosition());
            toVector.nor();

            if (body.getLinearVelocity().len2() < enemy.getSpeed() * enemy.getSpeed()) {
                body.applyLinearImpulse(toVector.scl(enemy.getSpeed()), body.getWorldCenter(), true);
            }
            break;
    }
}
 
Example #8
Source File: Light.java    From box2dlights with Apache License 2.0 4 votes vote down vote up
/**
 * Sets given contact filter for this light
 */
public void setContactFilter(Filter filter) {
	filterA = filter;
}
 
Example #9
Source File: Light.java    From box2dlights with Apache License 2.0 4 votes vote down vote up
/**
 * Sets given contact filter for ALL LIGHTS
 */
static public void setGlobalContactFilter(Filter filter) {
	globalFilterA = filter;
}