Skip to content

Commit

Permalink
BSPMapGen: Snapped drawn rectangles to the nearest pixel to fix HaxeF…
Browse files Browse the repository at this point in the history
  • Loading branch information
UncertainProd committed Apr 8, 2023
1 parent 7b0d27b commit 6f63b28
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions Other/BSPMapGen/source/generate/Leaf.hx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Leaf
// Place the room within leaf, but not against sides (would merge)
var roomPos = new FlxPoint(FlxG.random.float(1, width - roomSize.x - 1), FlxG.random.float(1, height - roomSize.y - 1));

room = new Rectangle(x + roomPos.x, y + roomPos.y, roomSize.x, roomSize.y);
room = new Rectangle(Math.floor(x + roomPos.x), Math.floor(y + roomPos.y), Math.floor(roomSize.x), Math.floor(roomSize.y));
}
}

Expand All @@ -144,31 +144,31 @@ class Leaf
{
if (FlxG.random.float() > 0.5)
{
hallways.push(new Rectangle(point2.x, point1.y, Math.abs(w), 1));
hallways.push(new Rectangle(point2.x, point2.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point1.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point2.y), 1, Math.ceil(Math.abs(h))));
}
else
{
hallways.push(new Rectangle(point2.x, point2.y, Math.abs(w), 1));
hallways.push(new Rectangle(point1.x, point2.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point2.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point2.y), 1, Math.ceil(Math.abs(h))));
}
}
else if (h > 0)
{
if (FlxG.random.float() > 0.5)
{
hallways.push(new Rectangle(point2.x, point1.y, Math.abs(w), 1));
hallways.push(new Rectangle(point2.x, point1.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point1.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point1.y), 1, Math.ceil(Math.abs(h))));
}
else
{
hallways.push(new Rectangle(point2.x, point2.y, Math.abs(w), 1));
hallways.push(new Rectangle(point1.x, point1.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point2.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point1.y), 1, Math.ceil(Math.abs(h))));
}
}
else
{
hallways.push(new Rectangle(point2.x, point2.y, Math.abs(w), 1));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point2.y), Math.ceil(Math.abs(w)), 1));
}
}
else if (w > 0)
Expand All @@ -177,42 +177,42 @@ class Leaf
{
if (FlxG.random.float() > 0.5)
{
hallways.push(new Rectangle(point1.x, point2.y, Math.abs(w), 1));
hallways.push(new Rectangle(point1.x, point2.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point2.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point2.y), 1, Math.ceil(Math.abs(h))));
}
else
{
hallways.push(new Rectangle(point1.x, point1.y, Math.abs(w), 1));
hallways.push(new Rectangle(point2.x, point2.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point1.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point2.y), 1, Math.ceil(Math.abs(h))));
}
}
else if (h > 0)
{
if (FlxG.random.float() > 0.5)
{
hallways.push(new Rectangle(point1.x, point1.y, Math.abs(w), 1));
hallways.push(new Rectangle(point2.x, point1.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point1.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point1.y), 1, Math.ceil(Math.abs(h))));
}
else
{
hallways.push(new Rectangle(point1.x, point2.y, Math.abs(w), 1));
hallways.push(new Rectangle(point1.x, point1.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point2.y), Math.ceil(Math.abs(w)), 1));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point1.y), 1, Math.ceil(Math.abs(h))));
}
}
else
{
hallways.push(new Rectangle(point1.x, point1.y, Math.abs(w), 1));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point1.y), Math.ceil(Math.abs(w)), 1));
}
}
else
{
if (h < 0)
{
hallways.push(new Rectangle(point2.x, point2.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point2.x), Math.ceil(point2.y), 1, Math.ceil(Math.abs(h))));
}
else if (h > 0)
{
hallways.push(new Rectangle(point1.x, point1.y, 1, Math.abs(h)));
hallways.push(new Rectangle(Math.ceil(point1.x), Math.ceil(point1.y), 1, Math.ceil(Math.abs(h))));
}
}
}
Expand Down

0 comments on commit 6f63b28

Please sign in to comment.