habit game snap matches together. close #91
This commit is contained in:
@@ -405,10 +405,23 @@
|
|||||||
(matchZone s SOUTH))
|
(matchZone s SOUTH))
|
||||||
|
|
||||||
(prop &mut c 0)
|
(prop &mut c 0)
|
||||||
(method :Void connectPiece [id self toSprite]
|
(method :Void connectPiece [id self toSprite selfMatchZone toSpriteMatchZone]
|
||||||
(let [thisConnectedPieces (dictGet connectedPieces id)
|
(let [thisConnectedPieces (dictGet connectedPieces id)
|
||||||
toConnectedPieces (dictGet connectedPieces (dictGet indexMap toSprite))]
|
toConnectedPieces (dictGet connectedPieces (dictGet indexMap toSprite))]
|
||||||
(+= c 1)
|
(+= c 1)
|
||||||
|
|
||||||
|
// Snap the pieces together
|
||||||
|
(let [offsetX (- toSpriteMatchZone.x selfMatchZone.x)
|
||||||
|
offsetY (- toSpriteMatchZone.y selfMatchZone.y)]
|
||||||
|
(doFor piece (.concat (recursivelyConnectedPieces self) [self])
|
||||||
|
~"snip snap"
|
||||||
|
(+= piece.x offsetX)
|
||||||
|
(+= piece.y offsetY))
|
||||||
|
// TODO check for matches created by snapping all the pieces?
|
||||||
|
// Or is it fine not to?
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
// Don't add duplicates
|
// Don't add duplicates
|
||||||
(thisConnectedPieces.remove toSprite)
|
(thisConnectedPieces.remove toSprite)
|
||||||
(thisConnectedPieces.push toSprite)
|
(thisConnectedPieces.push toSprite)
|
||||||
@@ -426,22 +439,22 @@
|
|||||||
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 mzl mzr)))
|
||||||
(whenLet [toRight (dictGet matchingPiecesRight id)
|
(whenLet [toRight (dictGet matchingPiecesRight id)
|
||||||
mzr (matchZoneRight s)
|
mzr (matchZoneRight s)
|
||||||
mzl (matchZoneLeft toRight)]
|
mzl (matchZoneLeft toRight)]
|
||||||
(unless .isEmpty (mzl.intersection mzr)
|
(unless .isEmpty (mzl.intersection mzr)
|
||||||
(connectPiece id s toRight)))
|
(connectPiece id s toRight mzr mzl)))
|
||||||
(whenLet [toUp (dictGet matchingPiecesUp id)
|
(whenLet [toUp (dictGet matchingPiecesUp id)
|
||||||
mzu (matchZoneUp s)
|
mzu (matchZoneUp s)
|
||||||
mzd (matchZoneDown toUp)]
|
mzd (matchZoneDown toUp)]
|
||||||
(unless .isEmpty (mzu.intersection mzd)
|
(unless .isEmpty (mzu.intersection mzd)
|
||||||
(connectPiece id s toUp)))
|
(connectPiece id s toUp mzu mzd)))
|
||||||
(whenLet [toDown (dictGet matchingPiecesDown id)
|
(whenLet [toDown (dictGet matchingPiecesDown id)
|
||||||
mzd (matchZoneDown s)
|
mzd (matchZoneDown s)
|
||||||
mzu (matchZoneUp toDown)]
|
mzu (matchZoneUp toDown)]
|
||||||
(unless .isEmpty (mzu.intersection mzd)
|
(unless .isEmpty (mzu.intersection mzd)
|
||||||
(connectPiece id s toDown)))))
|
(connectPiece id s toDown mzd mzu)))))
|
||||||
|
|
||||||
(method :Array<FlxExtendedSprite> recursivelyConnectedPieces [s &opt :Array<FlxExtendedSprite> collected]
|
(method :Array<FlxExtendedSprite> recursivelyConnectedPieces [s &opt :Array<FlxExtendedSprite> collected]
|
||||||
(unless collected (set collected []))
|
(unless collected (set collected []))
|
||||||
|
Reference in New Issue
Block a user