Aggregation of horizontal walls

This commit is contained in:
Collin Smith 2019-05-06 10:29:09 -07:00
parent c36313304b
commit 7e2b2679ba

View File

@ -192,30 +192,41 @@ public class WallAggregatorTool extends ApplicationAdapter {
IntMap<Filter> filters = new IntMap<>(); IntMap<Filter> filters = new IntMap<>();
for (int y = 0; y < 280; y++) { for (Map.Zone zone : map.zones) {
for (int x = 0; x < 200; x++) { //Map.Zone zone = map.zones.first();
int flags = map.flags(x, y); for (int y = 0, ty = zone.y, height = zone.height; y < height; y++, ty++) {
if (flags != 0) { for (int x = 0, tx = zone.x, width = zone.width; x < width; x++, tx++) {
BodyDef def = new BodyDef(); int flags = map.flags(tx, ty);
def.type = BodyDef.BodyType.StaticBody; if (flags != 0) {
def.position.set(x, -(y)); int endX = tx + 1;
while (endX < width && map.flags(endX, ty) == flags) {
endX++;
}
PolygonShape shape = new PolygonShape(); BodyDef def = new BodyDef();
shape.setAsBox(0.5f, 0.5f); def.type = BodyDef.BodyType.StaticBody;
def.position.set((endX + tx) / 2f, -ty);
Filter filter = filters.get(flags); PolygonShape shape = new PolygonShape();
if (filter == null) { shape.setAsBox((endX - tx) / 2f, 0.5f);
filters.put(flags, filter = new Filter());
filter.categoryBits = 0xFF; Filter filter = filters.get(flags);
filter.maskBits = (short) flags; if (filter == null) {
filter.groupIndex = 0; filters.put(flags, filter = new Filter());
filter.categoryBits = 0xFF;
filter.maskBits = (short) flags;
filter.groupIndex = 0;
}
Body body = world.createBody(def);
Fixture f = body.createFixture(shape, 0);
f.setFilterData(filter);
shape.dispose();
x += endX - tx - 1;
tx = endX - 1;
} }
Body body = world.createBody(def);
Fixture f = body.createFixture(shape, 0);
f.setFilterData(filter);
shape.dispose();
} }
} }
} }