private boolean isPlayerGrounded (float deltaTime) { groundedPlatform = null; Array<Contact> contactList = world.getContactList(); for (int i = 0; i < contactList.size; i++) { Contact contact = contactList.get(i); if (contact.isTouching() && (contact.getFixtureA() == playerSensorFixture || contact.getFixtureB() == playerSensorFixture)) { Vector2 pos = player.getPosition(); WorldManifold manifold = contact.getWorldManifold(); boolean below = true; for (int j = 0; j < manifold.getNumberOfContactPoints(); j++) { below &= (manifold.getPoints()[j].y < pos.y - 1.5f); } if (below) { if (contact.getFixtureA().getUserData() != null && contact.getFixtureA().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureA().getBody().getUserData(); } if (contact.getFixtureB().getUserData() != null && contact.getFixtureB().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureB().getBody().getUserData(); } return true; } return false; } } return false; }
public GameActor(Body body) { this.body = body; this.userData = (UserData) body.getUserData(); screenRectangle = new Rectangle(); }
public static boolean bodyIsGround(Body body) { UserData userData = (UserData) body.getUserData(); return userData != null && userData.getUserDataType() == UserDataType.GROUND; }
public static boolean bodyIsRunner(Body body) { UserData userData = (UserData) body.getUserData(); return userData != null && userData.getUserDataType() == UserDataType.RUNNER; }
public static boolean bodyIsEnemy(Body body) { UserData userData = (UserData) body.getUserData(); return userData != null && userData.getUserDataType() == UserDataType.ENEMY; }
protected Body[] getBodyAB(World world){ Body[] bodies = new Body[2]; Array<Body> bodyArray = new Array<>(world.getBodyCount()); world.getBodies(bodyArray); for(Body body : bodyArray){ if(this.bodyA.equals(body.getUserData())) bodies[0] = body; else if(this.bodyB.equals(body.getUserData())) bodies[1] = body; } return bodies; }
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { // Print contact info Gdx.app.log(TAG, " Contact!! " + fixture.getBody().getUserData() + " at [" + point.x + ";" + point.y + "]"); return -1; // Continue with the rest of the fixtures } };
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) { Entity bombEntity = (Entity) fixture.getBody().getUserData(); kickingBomb = bombEntity.getComponent(Bomb.class); return 0; } return 0; } };
public static boolean bodyInBounds(Body body) { UserData userData = (UserData) body.getUserData(); switch (userData.getUserDataType()) { case RUNNER: case ENEMY: return body.getPosition().x + userData.getWidth() / 2 > 0; } return true; }
@Override public void act(float delta) { super.act(delta); if (body.getUserData() != null) { updateRectangle(); } else { // This means the world destroyed the body (enemy or runner went out of bounds) remove(); } }
void freeBalloons() { Iterator<Body> i = balloons.iterator(); while (i.hasNext()) { Body balloon = i.next(); boolean broken = (Boolean) balloon.getUserData(); if(((balloon.getPosition().y - BALLOON_HEIGHT*0.5f) > SCENE_HEIGHT) || // Top limit (balloon.getPosition().y + BALLOON_HEIGHT*0.5f) < 1.0f || // Bottom limit (balloon.getPosition().x - BALLOON_WIDTH*0.5f) > SCENE_WIDTH || // Right limit (balloon.getPosition().x + BALLOON_WIDTH*0.5f) < 0 || // Left limit broken) { world.destroyBody(balloon); i.remove(); } } }
world.getBodies(bodyArray); for(Body body : bodyArray) if(body.getUserData() instanceof String) usedBodyNames.put((String)body.getUserData(), body); HashMap<String, Body> bodies = new HashMap<>(); List<GDXShape> shapes = new ArrayList<>();
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getFilterData().categoryBits == GameManager.INDESTRUCTIIBLE_BIT) { canExplodeThrough = false; return 0; } if (fixture.getFilterData().categoryBits == GameManager.BREAKABLE_BIT) { canExplodeThrough = false; Entity e = (Entity) fixture.getBody().getUserData(); Breakable breakable = e.getComponent(Breakable.class); breakable.state = Breakable.State.EXPLODING; return 0; } return 0; } };
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { collision.set(point); Box2DQuerySample.this.normal.set(normal).add(point); // Show contact info title = fixture.getBody().getUserData() + " at [" + point.x + ";" + point.y + "]"; layout.setText(font, title); titleWidth = layout.width * 0.5f; return 1; // Continue with the rest of the fixtures } };
@Override public void beginContact(Contact contact) { // TODO Auto-generated method stub Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); Body bodyA = fixtureA.getBody(); Body bodyB = fixtureB.getBody(); if (fixtureA.isSensor()) { Enemy e = (Enemy) bodyA.getUserData(); e.setAngry(true); //Gdx.app.log(TAG, "T-Rex is angry!!!"); } else if(fixtureB.isSensor()) { Enemy e = (Enemy) bodyB.getUserData(); e.setAngry(true); //Gdx.app.log(TAG, "T-Rex is angry!!!"); } }
@Override public Body getPhysicsObject(String name) { Array<Body> bodyArray = new Array<>(world.getBodyCount()); world.getBodies(bodyArray); for (Body body : bodyArray) if (name != null && name.equals(body.getUserData())) return body; return null; }
@Override public boolean isNear(String origin, String target, float distance) { Body originBody = null, targetBody = null; Array<Body> bodyArray = new Array<>(world.getBodyCount()); world.getBodies(bodyArray); for (Body body : bodyArray) { if (origin != null && origin.equals(body.getUserData())) originBody = body; if (target != null && target.equals(body.getUserData())) targetBody = body; } return originBody.getPosition().dst(targetBody.getPosition()) < distance; }
Entity e = (Entity) fixtureA.getBody().getUserData(); Player player = e.getComponent(Player.class); player.receivedDamage++; } else if (fixtureB.getFilterData().categoryBits == GameManager.PLAYER_BIT) { Entity e = (Entity) fixtureB.getBody().getUserData(); Player player = e.getComponent(Player.class); player.receivedDamage++; Entity e = (Entity) fixtureA.getBody().getUserData(); Enemy enemy = e.getComponent(Enemy.class); enemy.receivedDamage++; } else if (fixtureB.getFilterData().categoryBits == GameManager.ENEMY_BIT) { Entity e = (Entity) fixtureB.getBody().getUserData(); Enemy enemy = e.getComponent(Enemy.class); enemy.receivedDamage++; Entity e = (Entity) fixtureA.getBody().getUserData(); Bomb bomb = e.getComponent(Bomb.class); bomb.countDown = 0; } else if (fixtureB.getFilterData().categoryBits == GameManager.BOMB_BIT) { Entity e = (Entity) fixtureB.getBody().getUserData(); Bomb bomb = e.getComponent(Bomb.class); bomb.countDown = 0; Entity e = (Entity) fixtureA.getBody().getUserData(); Breakable breakable = e.getComponent(Breakable.class); breakable.state = Breakable.State.EXPLODING; } else if (fixtureB.getFilterData().categoryBits == GameManager.BREAKABLE_BIT) { Entity e = (Entity) fixtureB.getBody().getUserData();
Enemy e = (Enemy) bodyA.getUserData(); e.setAngry(false); Enemy e = (Enemy) bodyB.getUserData(); e.setAngry(false);
Object userData = f.getUserData(); if ((body != null) && (userData == CarType.PlayerCar || userData == CarType.ReplayCar)) { Car car = (Car)body.getUserData(); float[] impulses = impulse.getNormalImpulses(); tmpVec2.set(impulses[0], impulses[1]);