Solve the black bar jigsaw problem. close #104
This commit is contained in:
@@ -195,8 +195,8 @@
|
|||||||
(let [r (new FlxRandom (Strings.hashCode currentRewardFile.path))
|
(let [r (new FlxRandom (Strings.hashCode currentRewardFile.path))
|
||||||
graphicWidth rewardSprite.pixels.width
|
graphicWidth rewardSprite.pixels.width
|
||||||
graphicHeight rewardSprite.pixels.height
|
graphicHeight rewardSprite.pixels.height
|
||||||
pieceAssetWidth (Std.int (/ graphicWidth PUZZLE_WIDTH))
|
pieceAssetWidth (/ (- graphicWidth (* EDGE_LEEWAY 2)) PUZZLE_WIDTH)
|
||||||
pieceAssetHeight (Std.int (/ graphicHeight PUZZLE_HEIGHT))
|
pieceAssetHeight (/ (- graphicHeight (* EDGE_LEEWAY 2)) PUZZLE_HEIGHT)
|
||||||
j (new Jigsawx pieceAssetWidth pieceAssetHeight graphicWidth graphicHeight EDGE_LEEWAY BUBBLE_SIZE PUZZLE_HEIGHT PUZZLE_WIDTH r)
|
j (new Jigsawx pieceAssetWidth pieceAssetHeight graphicWidth graphicHeight EDGE_LEEWAY BUBBLE_SIZE PUZZLE_HEIGHT PUZZLE_WIDTH r)
|
||||||
PIECE_WIDTH
|
PIECE_WIDTH
|
||||||
(/ rewardSprite.width PUZZLE_WIDTH)
|
(/ rewardSprite.width PUZZLE_WIDTH)
|
||||||
|
|||||||
@@ -35,6 +35,29 @@ class JigsawPiece{
|
|||||||
points = [];
|
points = [];
|
||||||
stepAngle = JigsawMagicNumbers.stepSize*Math.PI/180;
|
stepAngle = JigsawMagicNumbers.stepSize*Math.PI/180;
|
||||||
first = lt;
|
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
|
// NORTH side
|
||||||
if( sideData.north != null ) createVertSide( lt, rt, bubbleSize, sideData.north, NORTH );
|
if( sideData.north != null ) createVertSide( lt, rt, bubbleSize, sideData.north, NORTH );
|
||||||
points.push( rt );
|
points.push( rt );
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Jigsawx {
|
|||||||
rows = rows_;
|
rows = rows_;
|
||||||
cols = cols_;
|
cols = cols_;
|
||||||
//corners, theoretically JigsawSideData could be modified to allow these to have a random element.
|
//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 lt = new Vec2( edgeLeeway, edgeLeeway );
|
||||||
var rt = new Vec2( edgeLeeway + dx, edgeLeeway );
|
var rt = new Vec2( edgeLeeway + dx, edgeLeeway );
|
||||||
var rb = new Vec2( edgeLeeway + dx, dy + edgeLeeway );
|
var rb = new Vec2( edgeLeeway + dx, dy + edgeLeeway );
|
||||||
@@ -72,7 +72,7 @@ class Jigsawx {
|
|||||||
jigs.push( jig );
|
jigs.push( jig );
|
||||||
xy.x += dx;
|
xy.x += dx;
|
||||||
}
|
}
|
||||||
xy.x = edgeLeeway;
|
xy.x = 0;
|
||||||
xy.y += dy;
|
xy.y += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,18 +80,22 @@ class Jigsawx {
|
|||||||
var corners = ["top left", "top right", "bottom left", "bottom right"];
|
var corners = ["top left", "top right", "bottom left", "bottom right"];
|
||||||
|
|
||||||
function contains(p:JigsawPiece, v:Vec2) {
|
function contains(p:JigsawPiece, v:Vec2) {
|
||||||
|
var minOffset = Math.POSITIVE_INFINITY;
|
||||||
for (pt in p.getPoints()) {
|
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));
|
||||||
return true;
|
if (offset < minOffset)
|
||||||
}
|
minOffset = offset;
|
||||||
return false;
|
if (offset < 1)
|
||||||
}
|
return true;
|
||||||
var containsCorners = [
|
}
|
||||||
contains(pieces[0][0], new Vec2(0, 0)),
|
return false;
|
||||||
contains(pieces[0][-1], new Vec2(totalWidth, 0)),
|
}
|
||||||
contains(pieces[-1][0], new Vec2(0, totalHeight)),
|
var containsCorners = [
|
||||||
contains(pieces[-1][-1], new Vec2(totalWidth, totalHeight))
|
contains(pieces[0][0], new Vec2(0, 0)),
|
||||||
];
|
contains(pieces[0][-1], new Vec2(totalWidth, 0)),
|
||||||
|
contains(pieces[-1][0], new Vec2(0, totalHeight)),
|
||||||
|
contains(pieces[-1][-1], new Vec2(totalWidth, totalHeight))
|
||||||
|
];
|
||||||
var containsAllCorners = true;
|
var containsAllCorners = true;
|
||||||
for (i in 0...corners.length) {
|
for (i in 0...corners.length) {
|
||||||
if (!containsCorners[i]) {
|
if (!containsCorners[i]) {
|
||||||
@@ -100,7 +104,9 @@ class Jigsawx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!containsAllCorners) {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,10 @@ class Vec2{
|
|||||||
x = x_;
|
x = x_;
|
||||||
y = y_;
|
y = y_;
|
||||||
}
|
}
|
||||||
|
public function copy() {
|
||||||
|
return new Vec2(x, y);
|
||||||
|
}
|
||||||
|
public function toString() {
|
||||||
|
return '(${x}, ${y})';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user