Skip to content

Commit

Permalink
fix(mazes): fix incorrect box2d fixtures for maze tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminAmos committed Jan 30, 2022
1 parent 62b07db commit 72fbf6b
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ public MazeTileObject build(SolGame game, MazeTile tile, Vector2 position, float
drawables.add(s);
RectSprite s2 = SpriteManager.createSprite(backgroundTexture.name, MazeBuilder.TILE_SZ, 0, 0, new Vector2(), DrawableLevel.DECO, 0, 0, SolColor.WHITE, false);
drawables.add(s2);
Body body = buildBody(game, angle, position, tile, flipped);
Body body = buildBody(game, angle, position, tile);
MazeTileObject res = new MazeTileObject(tile, drawables, body, position, angle, flipped);
body.setUserData(res);
return res;
}

private Body buildBody(SolGame game, float angle, Vector2 position, MazeTile tile, boolean flipped) {
private Body buildBody(SolGame game, float angle, Vector2 position, MazeTile tile) {
BodyDef def = new BodyDef();
def.type = BodyDef.BodyType.KinematicBody;
def.position.set(position);
Expand All @@ -209,14 +209,9 @@ private Body buildBody(SolGame game, float angle, Vector2 position, MazeTile til
for (List<Vector2> pts : tile.points) {
ChainShape shape = new ChainShape();
List<Vector2> points = new ArrayList<>();
int sz = pts.size();
for (int i = 0; i < sz; i++) {
Vector2 curr = pts.get(flipped ? sz - i - 1 : i);
for (Vector2 curr : pts) {
Vector2 v = new Vector2(curr);
v.add(-.5f, -.5f);
if (flipped) {
v.x *= -1;
}
v.scl(MazeBuilder.TILE_SZ);
points.add(v);
}
Expand Down

0 comments on commit 72fbf6b

Please sign in to comment.