From b63470fff3468f349ccf48853aa3f9e11cee1979 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 8 Jul 2022 23:50:35 +0000 Subject: [PATCH] pieces fit together right but their position and dragging is broken --- .../source/HabitState.hx | 2 +- .../source/HabitState.kiss | 55 +++++++++---------- .../source/jigsawx/Jigsawx.hx | 4 +- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx index 1859a01d..466a38c6 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx @@ -32,7 +32,7 @@ import jigsawx.math.Vec2; class HabitState extends FlxState { public function drawPieceShape( surface: FlxSprite, jig: JigsawPiece, c: FlxColor ) { - var points = [for (point in jig.getPoints()) new FlxPoint(point.x, point.y)]; + var points = [for (point in jig.getPoints()) new FlxPoint(jig.xy.x + point.x, jig.xy.y + point.y)]; points.push(points[0]); FlxSpriteUtil.drawPolygon( surface, diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index ed976ecb..5b5f9840 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -55,42 +55,39 @@ (set rewardSprites (new FlxTypedGroup)) - (let [PIECE_WIDTH + (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)) + j (new Jigsawx pieceAssetWidth pieceAssetHeight EDGE_LEEWAY PUZZLE_HEIGHT PUZZLE_WIDTH r) + PIECE_WIDTH (/ rewardSprite.width PUZZLE_WIDTH) PIECE_HEIGHT (/ rewardSprite.height PUZZLE_HEIGHT) - :Array startingPoints [] - :Array sourceRectangles [] - pieceAssetWidth (Std.int (/ rewardSprite.pixels.width PUZZLE_WIDTH)) - pieceAssetHeight (Std.int (/ rewardSprite.pixels.height PUZZLE_HEIGHT))] + :Array startingPoints []] (doFor y (range PUZZLE_HEIGHT) (doFor x (range PUZZLE_WIDTH) - (startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT)))) - (sourceRectangles.push (new Rectangle (* x pieceAssetWidth) (* y pieceAssetHeight) pieceAssetWidth pieceAssetHeight)))) - (let [r (new FlxRandom (Strings.hashCode currentRewardFile.path))] - (r.shuffle startingPoints) - (set jigsaw (new Jigsawx pieceAssetWidth pieceAssetHeight EDGE_LEEWAY PUZZLE_HEIGHT PUZZLE_WIDTH r)) - (doFor i (range (- p currentRewardFile.startingPoints)) - (let [pos (nth startingPoints i) - s (new FlxExtendedSprite pos.x pos.y) - source (new FlxSprite) - mask (new FlxSprite)] - (set s.draggable true) - (s.enableMouseDrag false true) - (s.makeGraphic pieceAssetWidth pieceAssetHeight FlxColor.TRANSPARENT true) - - (source.makeGraphic pieceAssetWidth pieceAssetHeight FlxColor.TRANSPARENT true) - (source.pixels.copyPixels rewardSprite.pixels (nth sourceRectangles i) (new Point 0 0)) + (startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT)))))) + //(r.shuffle startingPoints) + (set jigsaw j) + (doFor i (range (- p currentRewardFile.startingPoints)) + (let [jig (nth jigsaw.jigs i) + pos (nth startingPoints i) + s (new FlxExtendedSprite pos.x pos.y) + mask (new FlxSprite)] + (set s.draggable true) + (s.enableMouseDrag false true) + + (mask.makeGraphic graphicWidth graphicHeight FlxColor.TRANSPARENT true) + (drawPieceShape mask jig FlxColor.BLACK) - (mask.makeGraphic pieceAssetWidth pieceAssetHeight FlxColor.TRANSPARENT true) - (drawPieceShape mask (nth jigsaw.jigs i) FlxColor.BLACK) - - (FlxSpriteUtil.alphaMask s source.pixels mask.pixels) - (s.setGraphicSize PIECE_WIDTH PIECE_HEIGHT) - (s.updateHitbox) + (FlxSpriteUtil.alphaMask s rewardSprite.pixels mask.pixels) + (s.setGraphicSize (Std.int rewardSprite.width) (Std.int rewardSprite.height)) + (s.updateHitbox) - (rewardSprites.add s))) - (add rewardSprites))))) + (rewardSprites.add s))) + (add rewardSprites)))) (when entryTexts (remove entryTexts)) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/Jigsawx.hx b/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/Jigsawx.hx index 71c0ebff..7adbc0f6 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/Jigsawx.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/Jigsawx.hx @@ -26,8 +26,8 @@ class Jigsawx { pieces = []; jigs = []; sides = []; - dx = pieceWidth - edgeLeeway * 2; - dy = pieceHeight - edgeLeeway * 2; + dx = pieceWidth; + dy = pieceHeight; rows = rows_; cols = cols_; //corners, theoretically JigsawSideData could be modified to allow these to have a random element.