pieces stick together (janky)
This commit is contained in:
@@ -16,6 +16,7 @@ import openfl.geom.Rectangle;
|
|||||||
import openfl.geom.Point;
|
import openfl.geom.Point;
|
||||||
import openfl.geom.ColorTransform;
|
import openfl.geom.ColorTransform;
|
||||||
import flixel.util.FlxSpriteUtil;
|
import flixel.util.FlxSpriteUtil;
|
||||||
|
using flixel.util.FlxSpriteUtil;
|
||||||
import flixel.util.FlxSave;
|
import flixel.util.FlxSave;
|
||||||
import flixel.input.mouse.FlxMouseEventManager;
|
import flixel.input.mouse.FlxMouseEventManager;
|
||||||
import flixel.addons.display.FlxExtendedSprite;
|
import flixel.addons.display.FlxExtendedSprite;
|
||||||
|
@@ -24,6 +24,16 @@
|
|||||||
// Hold left-click to hide the habit text and see the image clearly:
|
// Hold left-click to hide the habit text and see the image clearly:
|
||||||
(when entryTexts (if FlxG.mouse.pressed (remove entryTexts) (add entryTexts)))
|
(when entryTexts (if FlxG.mouse.pressed (remove entryTexts) (add entryTexts)))
|
||||||
|
|
||||||
|
// drag along connected pieces
|
||||||
|
(when draggingSprite
|
||||||
|
(let [dx (- draggingSprite.x draggingLastPos.x)
|
||||||
|
dy (- draggingSprite.y draggingLastPos.y)]
|
||||||
|
(set draggingLastPos (new FlxPoint draggingSprite.x draggingSprite.y))
|
||||||
|
(doFor s (recursivelyConnectedPieces draggingSprite)
|
||||||
|
(+= s.x dx)
|
||||||
|
(+= s.y dy))))
|
||||||
|
|
||||||
|
|
||||||
// Left and right arrow keys can switch between unlocked puzzles
|
// Left and right arrow keys can switch between unlocked puzzles
|
||||||
(when FlxG.keys.justPressed.LEFT
|
(when FlxG.keys.justPressed.LEFT
|
||||||
(unless (= rewardFileIndex 0)
|
(unless (= rewardFileIndex 0)
|
||||||
@@ -62,6 +72,9 @@
|
|||||||
|
|
||||||
(var SCROLL_BOUND_MARGIN 200)
|
(var SCROLL_BOUND_MARGIN 200)
|
||||||
|
|
||||||
|
(prop &mut :FlxExtendedSprite draggingSprite null)
|
||||||
|
(prop &mut :FlxPoint draggingLastPos null)
|
||||||
|
|
||||||
(method setModel [m &opt :RewardFile currentRewardFile]
|
(method setModel [m &opt :RewardFile currentRewardFile]
|
||||||
(set model m)
|
(set model m)
|
||||||
(set shortcutHandler (new FlxKeyShortcutHandler))
|
(set shortcutHandler (new FlxKeyShortcutHandler))
|
||||||
@@ -145,9 +158,16 @@
|
|||||||
(dictSet indexMap s i)
|
(dictSet indexMap s i)
|
||||||
(set s.draggable true)
|
(set s.draggable true)
|
||||||
(s.enableMouseDrag false true)
|
(s.enableMouseDrag false true)
|
||||||
|
(set s.mouseStartDragCallback
|
||||||
|
->:Void [s x y]
|
||||||
|
{
|
||||||
|
(set draggingSprite s)
|
||||||
|
(set draggingLastPos (new FlxPoint s.x s.y))
|
||||||
|
})
|
||||||
(set s.mouseStopDragCallback
|
(set s.mouseStopDragCallback
|
||||||
->:Void [s x y]
|
->:Void [s x y]
|
||||||
{
|
{
|
||||||
|
(set draggingSprite null)
|
||||||
(checkMatches i)
|
(checkMatches i)
|
||||||
(pieceCamera.calculateScrollBounds rewardSprites SCROLL_BOUND_MARGIN)
|
(pieceCamera.calculateScrollBounds rewardSprites SCROLL_BOUND_MARGIN)
|
||||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) i (new FlxPoint s.x s.y))
|
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) i (new FlxPoint s.x s.y))
|
||||||
@@ -239,9 +259,12 @@
|
|||||||
(method :FlxRect matchZoneDown [:FlxExtendedSprite s]
|
(method :FlxRect matchZoneDown [:FlxExtendedSprite s]
|
||||||
(new FlxRect (+ s.x s.origin.x) (- (+ s.y s.height) EDGE_LEEWAY) EDGE_LEEWAY EDGE_LEEWAY))
|
(new FlxRect (+ s.x s.origin.x) (- (+ s.y s.height) EDGE_LEEWAY) EDGE_LEEWAY EDGE_LEEWAY))
|
||||||
|
|
||||||
|
(prop &mut c 0)
|
||||||
(method :Void connectPiece [id self toSprite]
|
(method :Void connectPiece [id self toSprite]
|
||||||
(let [thisConnectedPieces (dictGet connectedPieces id)
|
(let [thisConnectedPieces (dictGet connectedPieces id)
|
||||||
toConnectedPieces (dictGet connectedPieces (dictGet indexMap toSprite))]
|
toConnectedPieces (dictGet connectedPieces (dictGet indexMap toSprite))]
|
||||||
|
(print "connection $c found")
|
||||||
|
(+= c 1)
|
||||||
// Don't add duplicates
|
// Don't add duplicates
|
||||||
(thisConnectedPieces.remove toSprite)
|
(thisConnectedPieces.remove toSprite)
|
||||||
(thisConnectedPieces.push toSprite)
|
(thisConnectedPieces.push toSprite)
|
||||||
@@ -254,15 +277,39 @@
|
|||||||
jig (dictGet pieceData id)
|
jig (dictGet pieceData id)
|
||||||
row jig.row
|
row jig.row
|
||||||
col jig.col]
|
col jig.col]
|
||||||
|
|
||||||
|
/* // TODO tune the match zones
|
||||||
|
(let [l (matchZoneLeft s)
|
||||||
|
r (matchZoneRight s)]
|
||||||
|
(s.drawRect (- l.x s.x) (- l.y s.y) l.width l.height)
|
||||||
|
(s.drawRect (- r.x s.x) (- r.y s.y) r.width r.height)) */
|
||||||
|
|
||||||
(whenLet [toLeft (dictGet matchingPiecesLeft id)
|
(whenLet [toLeft (dictGet matchingPiecesLeft id)
|
||||||
mzl (matchZoneLeft s)
|
mzl (matchZoneLeft s)
|
||||||
mzr (matchZoneRight toLeft)]
|
mzr (matchZoneRight toLeft)]
|
||||||
(unless .isEmpty (mzl.intersection mzr)
|
(unless .isEmpty (mzl.intersection mzr)
|
||||||
(connectPiece id s toLeft)))
|
(connectPiece id s toLeft)))
|
||||||
// TODO implement these:
|
(whenLet [toRight (dictGet matchingPiecesRight id)
|
||||||
(whenLet [toRight (dictGet matchingPiecesRight id)]
|
mzr (matchZoneRight s)
|
||||||
(dictSet matchingPiecesRight id toRight))
|
mzl (matchZoneLeft toRight)]
|
||||||
(whenLet [toUp (dictGet matchingPiecesUp id)]
|
(unless .isEmpty (mzl.intersection mzr)
|
||||||
(dictSet matchingPiecesUp id toUp))
|
(connectPiece id s toRight)))
|
||||||
(whenLet [toDown (dictGet matchingPiecesDown id)]
|
(whenLet [toUp (dictGet matchingPiecesUp id)
|
||||||
(dictSet matchingPiecesDown id toDown))))
|
mzu (matchZoneUp s)
|
||||||
|
mzd (matchZoneDown toUp)]
|
||||||
|
(unless .isEmpty (mzu.intersection mzd)
|
||||||
|
(connectPiece id s toUp)))
|
||||||
|
(whenLet [toDown (dictGet matchingPiecesDown id)
|
||||||
|
mzd (matchZoneDown s)
|
||||||
|
mzu (matchZoneUp toDown)]
|
||||||
|
(unless .isEmpty (mzu.intersection mzd)
|
||||||
|
(connectPiece id s toDown)))))
|
||||||
|
|
||||||
|
(method :Array<FlxExtendedSprite> recursivelyConnectedPieces [s &opt :Array<FlxExtendedSprite> collected]
|
||||||
|
(unless collected (set collected []))
|
||||||
|
(let [directlyConnected (dictGet connectedPieces (dictGet indexMap s))]
|
||||||
|
(doFor piece directlyConnected
|
||||||
|
(unless (contains collected piece)
|
||||||
|
(collected.push piece)
|
||||||
|
(recursivelyConnectedPieces piece collected))))
|
||||||
|
collected)
|
Reference in New Issue
Block a user