pieces fit together right but their position and dragging is broken
This commit is contained in:
@@ -32,7 +32,7 @@ import jigsawx.math.Vec2;
|
|||||||
class HabitState extends FlxState {
|
class HabitState extends FlxState {
|
||||||
public function drawPieceShape( surface: FlxSprite, jig: JigsawPiece, c: FlxColor )
|
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]);
|
points.push(points[0]);
|
||||||
FlxSpriteUtil.drawPolygon(
|
FlxSpriteUtil.drawPolygon(
|
||||||
surface,
|
surface,
|
||||||
|
@@ -55,42 +55,39 @@
|
|||||||
|
|
||||||
(set rewardSprites (new FlxTypedGroup))
|
(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)
|
(/ rewardSprite.width PUZZLE_WIDTH)
|
||||||
PIECE_HEIGHT
|
PIECE_HEIGHT
|
||||||
(/ rewardSprite.height PUZZLE_HEIGHT)
|
(/ rewardSprite.height PUZZLE_HEIGHT)
|
||||||
:Array<FlxPoint> startingPoints []
|
:Array<FlxPoint> startingPoints []]
|
||||||
:Array<Rectangle> sourceRectangles []
|
|
||||||
pieceAssetWidth (Std.int (/ rewardSprite.pixels.width PUZZLE_WIDTH))
|
|
||||||
pieceAssetHeight (Std.int (/ rewardSprite.pixels.height PUZZLE_HEIGHT))]
|
|
||||||
(doFor y (range PUZZLE_HEIGHT)
|
(doFor y (range PUZZLE_HEIGHT)
|
||||||
(doFor x (range PUZZLE_WIDTH)
|
(doFor x (range PUZZLE_WIDTH)
|
||||||
(startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))
|
(startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))))
|
||||||
(sourceRectangles.push (new Rectangle (* x pieceAssetWidth) (* y pieceAssetHeight) pieceAssetWidth pieceAssetHeight))))
|
//(r.shuffle startingPoints)
|
||||||
(let [r (new FlxRandom (Strings.hashCode currentRewardFile.path))]
|
(set jigsaw j)
|
||||||
(r.shuffle startingPoints)
|
(doFor i (range (- p currentRewardFile.startingPoints))
|
||||||
(set jigsaw (new Jigsawx pieceAssetWidth pieceAssetHeight EDGE_LEEWAY PUZZLE_HEIGHT PUZZLE_WIDTH r))
|
(let [jig (nth jigsaw.jigs i)
|
||||||
(doFor i (range (- p currentRewardFile.startingPoints))
|
pos (nth startingPoints i)
|
||||||
(let [pos (nth startingPoints i)
|
s (new FlxExtendedSprite pos.x pos.y)
|
||||||
s (new FlxExtendedSprite pos.x pos.y)
|
mask (new FlxSprite)]
|
||||||
source (new FlxSprite)
|
(set s.draggable true)
|
||||||
mask (new FlxSprite)]
|
(s.enableMouseDrag false true)
|
||||||
(set s.draggable true)
|
|
||||||
(s.enableMouseDrag false true)
|
(mask.makeGraphic graphicWidth graphicHeight FlxColor.TRANSPARENT true)
|
||||||
(s.makeGraphic pieceAssetWidth pieceAssetHeight FlxColor.TRANSPARENT true)
|
(drawPieceShape mask jig FlxColor.BLACK)
|
||||||
|
|
||||||
(source.makeGraphic pieceAssetWidth pieceAssetHeight FlxColor.TRANSPARENT true)
|
|
||||||
(source.pixels.copyPixels rewardSprite.pixels (nth sourceRectangles i) (new Point 0 0))
|
|
||||||
|
|
||||||
(mask.makeGraphic pieceAssetWidth pieceAssetHeight FlxColor.TRANSPARENT true)
|
(FlxSpriteUtil.alphaMask s rewardSprite.pixels mask.pixels)
|
||||||
(drawPieceShape mask (nth jigsaw.jigs i) FlxColor.BLACK)
|
(s.setGraphicSize (Std.int rewardSprite.width) (Std.int rewardSprite.height))
|
||||||
|
(s.updateHitbox)
|
||||||
(FlxSpriteUtil.alphaMask s source.pixels mask.pixels)
|
|
||||||
(s.setGraphicSize PIECE_WIDTH PIECE_HEIGHT)
|
|
||||||
(s.updateHitbox)
|
|
||||||
|
|
||||||
(rewardSprites.add s)))
|
(rewardSprites.add s)))
|
||||||
(add rewardSprites)))))
|
(add rewardSprites))))
|
||||||
|
|
||||||
|
|
||||||
(when entryTexts (remove entryTexts))
|
(when entryTexts (remove entryTexts))
|
||||||
|
@@ -26,8 +26,8 @@ class Jigsawx {
|
|||||||
pieces = [];
|
pieces = [];
|
||||||
jigs = [];
|
jigs = [];
|
||||||
sides = [];
|
sides = [];
|
||||||
dx = pieceWidth - edgeLeeway * 2;
|
dx = pieceWidth;
|
||||||
dy = pieceHeight - edgeLeeway * 2;
|
dy = pieceHeight;
|
||||||
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.
|
||||||
|
Reference in New Issue
Block a user