fix snapping errors!
This commit is contained in:
@@ -248,7 +248,7 @@
|
|||||||
(set s.priorityID (+ 1 .priorityID (last (the kiss.List<KissExtendedSprite> rewardSprites.members))))
|
(set s.priorityID (+ 1 .priorityID (last (the kiss.List<KissExtendedSprite> rewardSprites.members))))
|
||||||
(let [connectedPieces (recursivelyConnectedPieces s)]
|
(let [connectedPieces (recursivelyConnectedPieces s)]
|
||||||
// Bring currently held pieces to the front:
|
// Bring currently held pieces to the front:
|
||||||
(rewardSprites.bringAllToFront (cast (concat [s] connectedPieces)))
|
(rewardSprites.bringAllToFront connectedPieces)
|
||||||
(set s.connectedSprites connectedPieces))
|
(set s.connectedSprites connectedPieces))
|
||||||
(set draggingSprite s)
|
(set draggingSprite s)
|
||||||
(set draggingLastPos (new FlxPoint s.x s.y))))
|
(set draggingLastPos (new FlxPoint s.x s.y))))
|
||||||
@@ -256,11 +256,13 @@
|
|||||||
->:Void [s x y]
|
->:Void [s x y]
|
||||||
(let [s (cast s KissExtendedSprite)]
|
(let [s (cast s KissExtendedSprite)]
|
||||||
(set draggingSprite null)
|
(set draggingSprite null)
|
||||||
(checkMatches i)
|
|
||||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) i (new FlxPoint s.x s.y))
|
(let [connectedPieces (recursivelyConnectedPieces s)]
|
||||||
(doFor connected (recursivelyConnectedPieces s)
|
(doFor connected connectedPieces
|
||||||
(checkMatches (dictGet indexMap connected))
|
(checkMatches (dictGet indexMap connected)))
|
||||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) (dictGet indexMap connected) (new FlxPoint connected.x connected.y)))
|
|
||||||
|
(doFor connected connectedPieces
|
||||||
|
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) (dictGet indexMap connected) (new FlxPoint connected.x connected.y))))
|
||||||
|
|
||||||
(pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN)
|
(pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN)
|
||||||
(save.flush)))
|
(save.flush)))
|
||||||
@@ -363,7 +365,8 @@
|
|||||||
(method _makeText [:String s :Int points &opt :Action action]
|
(method _makeText [:String s :Int points &opt :Action action]
|
||||||
(entryWindow.makeText (+ s (pointsStr points)) action))
|
(entryWindow.makeText (+ s (pointsStr points)) action))
|
||||||
|
|
||||||
(method log [message]
|
(method log [:String message]
|
||||||
|
(trace message)
|
||||||
(prop &mut logTextY 0)
|
(prop &mut logTextY 0)
|
||||||
(#when debug
|
(#when debug
|
||||||
(when (> logTextY FlxG.height)
|
(when (> logTextY FlxG.height)
|
||||||
@@ -402,19 +405,24 @@
|
|||||||
(matchZone s SOUTH))
|
(matchZone s SOUTH))
|
||||||
|
|
||||||
(prop &mut c 0)
|
(prop &mut c 0)
|
||||||
(method :Void connectPiece [id self toSprite selfMatchZone toSpriteMatchZone]
|
(method :Bool 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))]
|
||||||
|
|
||||||
// Don't add duplicates or snap for pieces alread connected
|
// Don't add duplicates or snap for pieces alread connected
|
||||||
(when (contains thisConnectedPieces toSprite)
|
(when (contains thisConnectedPieces toSprite)
|
||||||
(return))
|
(return false))
|
||||||
(+= c 1)
|
(+= c 1)
|
||||||
|
|
||||||
// Snap the pieces together
|
// Snap the pieces together
|
||||||
(let [offsetX (- toSpriteMatchZone.x selfMatchZone.x)
|
(let [offsetX (- toSpriteMatchZone.x selfMatchZone.x)
|
||||||
offsetY (- toSpriteMatchZone.y selfMatchZone.y)]
|
offsetY (- toSpriteMatchZone.y selfMatchZone.y)
|
||||||
(doFor piece (.concat (recursivelyConnectedPieces self) [self])
|
selfAndAttached (recursivelyConnectedPieces self)
|
||||||
|
indices (for s selfAndAttached (dictGet indexMap s))
|
||||||
|
otherAndAttached (recursivelyConnectedPieces toSprite)
|
||||||
|
otherIndices (for s otherAndAttached (dictGet indexMap s))]
|
||||||
|
//(print "attaching $indices to $otherIndices")
|
||||||
|
(doFor piece selfAndAttached
|
||||||
(+= piece.x offsetX)
|
(+= piece.x offsetX)
|
||||||
(+= piece.y offsetY))
|
(+= piece.y offsetY))
|
||||||
// TODO check for matches created by snapping all the pieces?
|
// TODO check for matches created by snapping all the pieces?
|
||||||
@@ -423,7 +431,8 @@
|
|||||||
|
|
||||||
|
|
||||||
(thisConnectedPieces.push toSprite)
|
(thisConnectedPieces.push toSprite)
|
||||||
(toConnectedPieces.push self)))
|
(toConnectedPieces.push self)
|
||||||
|
true))
|
||||||
|
|
||||||
(defMacro _checkMatch [side otherSide]
|
(defMacro _checkMatch [side otherSide]
|
||||||
(let [sideStr (symbolNameValue side)
|
(let [sideStr (symbolNameValue side)
|
||||||
@@ -438,8 +447,8 @@
|
|||||||
(unless .isEmpty (mz1.intersection mz2)
|
(unless .isEmpty (mz1.intersection mz2)
|
||||||
(connectPiece id s ,to mz1 mz2)))))
|
(connectPiece id s ,to mz1 mz2)))))
|
||||||
|
|
||||||
(method :Void checkMatches [id]
|
(method :Bool checkMatches [id]
|
||||||
(when !(pieceData.exists id) (return))
|
(when !(pieceData.exists id) (return false))
|
||||||
(let [s (dictGet spriteMap id)
|
(let [s (dictGet spriteMap id)
|
||||||
jig (dictGet pieceData id)
|
jig (dictGet pieceData id)
|
||||||
row jig.row
|
row jig.row
|
||||||
@@ -447,10 +456,11 @@
|
|||||||
(_checkMatch Left Right)
|
(_checkMatch Left Right)
|
||||||
(_checkMatch Right Left)
|
(_checkMatch Right Left)
|
||||||
(_checkMatch Up Down)
|
(_checkMatch Up Down)
|
||||||
(_checkMatch Down Up)))
|
(_checkMatch Down Up))
|
||||||
|
false)
|
||||||
|
|
||||||
(method :Array<KissExtendedSprite> recursivelyConnectedPieces [s &opt :Array<KissExtendedSprite> collected]
|
(method :Array<KissExtendedSprite> recursivelyConnectedPieces [s &opt :Array<KissExtendedSprite> collected]
|
||||||
(unless collected (set collected []))
|
(unless collected (set collected [s]))
|
||||||
(whenLet [directlyConnected (dictGet connectedPieces (dictGet indexMap s))]
|
(whenLet [directlyConnected (dictGet connectedPieces (dictGet indexMap s))]
|
||||||
(doFor piece directlyConnected
|
(doFor piece directlyConnected
|
||||||
(unless (contains collected piece)
|
(unless (contains collected piece)
|
||||||
|
Reference in New Issue
Block a user