Solve the black bar jigsaw problem. close #104

This commit is contained in:
2022-08-10 18:02:33 +00:00
parent 150614aec6
commit 3c708cd6f6
4 changed files with 51 additions and 16 deletions

View File

@@ -195,8 +195,8 @@
(let [r (new FlxRandom (Strings.hashCode currentRewardFile.path))
graphicWidth rewardSprite.pixels.width
graphicHeight rewardSprite.pixels.height
pieceAssetWidth (Std.int (/ graphicWidth PUZZLE_WIDTH))
pieceAssetHeight (Std.int (/ graphicHeight PUZZLE_HEIGHT))
pieceAssetWidth (/ (- graphicWidth (* EDGE_LEEWAY 2)) PUZZLE_WIDTH)
pieceAssetHeight (/ (- graphicHeight (* EDGE_LEEWAY 2)) PUZZLE_HEIGHT)
j (new Jigsawx pieceAssetWidth pieceAssetHeight graphicWidth graphicHeight EDGE_LEEWAY BUBBLE_SIZE PUZZLE_HEIGHT PUZZLE_WIDTH r)
PIECE_WIDTH
(/ rewardSprite.width PUZZLE_WIDTH)

View File

@@ -35,6 +35,29 @@ class JigsawPiece{
points = [];
stepAngle = JigsawMagicNumbers.stepSize*Math.PI/180;
first = lt;
lt = lt.copy();
rt = rt.copy();
lb = lb.copy();
rb = rb.copy();
var edgeLeeway = lt.x;
if (sideData.north == null) {
lt.y = 0;
rt.y = 0;
}
if (sideData.east == null) {
rt.x += edgeLeeway;
rb.x += edgeLeeway;
}
if (sideData.south == null) {
lb.y += edgeLeeway;
rb.y += edgeLeeway;
}
if (sideData.west == null) {
lt.x = 0;
lb.x = 0;
}
// NORTH side
if( sideData.north != null ) createVertSide( lt, rt, bubbleSize, sideData.north, NORTH );
points.push( rt );

View File

@@ -35,7 +35,7 @@ class Jigsawx {
rows = rows_;
cols = cols_;
//corners, theoretically JigsawSideData could be modified to allow these to have a random element.
var xy = new Vec2( edgeLeeway, edgeLeeway );
var xy = new Vec2( 0, 0 );
var lt = new Vec2( edgeLeeway, edgeLeeway );
var rt = new Vec2( edgeLeeway + dx, edgeLeeway );
var rb = new Vec2( edgeLeeway + dx, dy + edgeLeeway );
@@ -72,7 +72,7 @@ class Jigsawx {
jigs.push( jig );
xy.x += dx;
}
xy.x = edgeLeeway;
xy.x = 0;
xy.y += dy;
}
@@ -80,8 +80,12 @@ class Jigsawx {
var corners = ["top left", "top right", "bottom left", "bottom right"];
function contains(p:JigsawPiece, v:Vec2) {
var minOffset = Math.POSITIVE_INFINITY;
for (pt in p.getPoints()) {
if (pt.x == v.x - p.xy.x && pt.y == v.y - p.xy.y)
var offset = Math.abs(pt.x - (v.x - p.xy.x)) + Math.abs(pt.y - (v.y - p.xy.y));
if (offset < minOffset)
minOffset = offset;
if (offset < 1)
return true;
}
return false;
@@ -100,7 +104,9 @@ class Jigsawx {
}
}
if (!containsAllCorners) {
throw "jigsawX geometry doesn't cover the whole image dimensions!";
#if debug
throw "jigsawX geometry doesn't align with the whole image dimensions!";
#end
}
}
}

View File

@@ -6,4 +6,10 @@ class Vec2{
x = x_;
y = y_;
}
public function copy() {
return new Vec2(x, y);
}
public function toString() {
return '(${x}, ${y})';
}
}