faster scroll speed for bigger jigsaw images
This commit is contained in:
@@ -22,7 +22,9 @@
|
||||
(set bgColor FlxColor.TRANSPARENT)
|
||||
(super.create))
|
||||
|
||||
(var KEYBOARD_SCROLL_SPEED 200)
|
||||
(defAlias &ident KEYBOARD_SCROLL_SPEED (keyboardScrollSpeed))
|
||||
(method keyboardScrollSpeed []
|
||||
(/ 200 rewardSprite.scale.x))
|
||||
|
||||
(prop &mut :EntryType typeAdding Todo)
|
||||
(prop &mut :FlxInputText entryNameText)
|
||||
@@ -114,6 +116,7 @@
|
||||
(var PUZZLE_WIDTH 6)
|
||||
(var PUZZLE_HEIGHT 5)
|
||||
(var TOTAL_PIECES (* PUZZLE_WIDTH PUZZLE_HEIGHT))
|
||||
(prop &mut :FlxSprite rewardSprite null)
|
||||
(prop &mut :FlxTypedGroup<FlxExtendedSprite> rewardSprites null)
|
||||
(prop &mut :Map<Int,FlxExtendedSprite> matchingPiecesLeft (new Map))
|
||||
(prop &mut :Map<Int,FlxExtendedSprite> matchingPiecesRight (new Map))
|
||||
@@ -160,109 +163,109 @@
|
||||
(set pieceCamera.bgColor (nth backgroundOptions save.data.backgroundIndex))
|
||||
|
||||
(unless (= lastRewardFileIndex rewardFileIndex)
|
||||
(let [rewardSprite
|
||||
(set rewardSprite
|
||||
(new FlxSprite 0 0
|
||||
(BitmapData.fromFile
|
||||
currentRewardFile.path))]
|
||||
(when rewardSprites
|
||||
(remove rewardSprites))
|
||||
(rewardSprite.setGraphicSize FlxG.width 0)
|
||||
(rewardSprite.updateHitbox)
|
||||
(when (> rewardSprite.height FlxG.height)
|
||||
(rewardSprite.setGraphicSize 0 FlxG.height))
|
||||
(rewardSprite.updateHitbox)
|
||||
(rewardSprite.screenCenter)
|
||||
currentRewardFile.path)))
|
||||
(when rewardSprites
|
||||
(remove rewardSprites))
|
||||
(rewardSprite.setGraphicSize FlxG.width 0)
|
||||
(rewardSprite.updateHitbox)
|
||||
(when (> rewardSprite.height FlxG.height)
|
||||
(rewardSprite.setGraphicSize 0 FlxG.height))
|
||||
(rewardSprite.updateHitbox)
|
||||
(rewardSprite.screenCenter)
|
||||
|
||||
(set pieceCamera.zoom rewardSprite.scale.x)
|
||||
(set pieceCamera.zoom rewardSprite.scale.x)
|
||||
|
||||
(set rewardSprites (new FlxTypedGroup))
|
||||
|
||||
(doFor map [matchingPiecesLeft matchingPiecesRight matchingPiecesUp matchingPiecesDown]
|
||||
(map.clear))
|
||||
(connectedPieces.clear)
|
||||
(doFor i (range TOTAL_PIECES) (dictSet connectedPieces i []))
|
||||
(indexMap.clear)
|
||||
(set rewardSprites (new FlxTypedGroup))
|
||||
|
||||
(doFor map [matchingPiecesLeft matchingPiecesRight matchingPiecesUp matchingPiecesDown]
|
||||
(map.clear))
|
||||
(connectedPieces.clear)
|
||||
(doFor i (range TOTAL_PIECES) (dictSet connectedPieces i []))
|
||||
(indexMap.clear)
|
||||
|
||||
(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 BUBBLE_SIZE PUZZLE_HEIGHT PUZZLE_WIDTH r)
|
||||
PIECE_WIDTH
|
||||
(/ rewardSprite.width PUZZLE_WIDTH)
|
||||
PIECE_HEIGHT
|
||||
(/ rewardSprite.height PUZZLE_HEIGHT)
|
||||
:Array<FlxPoint> startingPoints []]
|
||||
(let [&mut i 0]
|
||||
(doFor y (range PUZZLE_HEIGHT)
|
||||
(doFor x (range PUZZLE_WIDTH)
|
||||
(startingPoints.push
|
||||
(new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))
|
||||
(+= i 1))))
|
||||
(r.shuffle startingPoints)
|
||||
(set jigsaw j)
|
||||
(r.shuffle jigsaw.jigs)
|
||||
(localVar spriteGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) null)))
|
||||
(localVar indexGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) 0)))
|
||||
(doFor i (range (min TOTAL_PIECES (- p currentRewardFile.startingPoints)))
|
||||
(let [jig (nth jigsaw.jigs i)
|
||||
pos (ifLet [point (dictGet (the Map<Int,FlxPoint> save.data.storedPositions) i)]
|
||||
point
|
||||
(nth startingPoints i))
|
||||
s (new FlxExtendedSprite pos.x pos.y)
|
||||
source (new FlxSprite)
|
||||
mask (new FlxSprite)
|
||||
sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)]
|
||||
(set s.priorityID i)
|
||||
(setNth spriteGrid jig.row jig.col s)
|
||||
(setNth indexGrid jig.row jig.col i)
|
||||
(dictSet pieceData i jig)
|
||||
(dictSet indexMap s i)
|
||||
(dictSet spriteMap i s)
|
||||
(set s.draggable true)
|
||||
(s.enableMouseDrag false true)
|
||||
(set s.mouseStartDragCallback
|
||||
->:Void [s x y]
|
||||
{
|
||||
// Bring currently held pieces to the front:
|
||||
(rewardSprites.bringToFront s)
|
||||
(set s.priorityID (+ 1 .priorityID (last (the kiss.List<FlxExtendedSprite> rewardSprites.members))))
|
||||
(doFor connected (recursivelyConnectedPieces s)
|
||||
(rewardSprites.bringToFront connected))
|
||||
(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 BUBBLE_SIZE PUZZLE_HEIGHT PUZZLE_WIDTH r)
|
||||
PIECE_WIDTH
|
||||
(/ rewardSprite.width PUZZLE_WIDTH)
|
||||
PIECE_HEIGHT
|
||||
(/ rewardSprite.height PUZZLE_HEIGHT)
|
||||
:Array<FlxPoint> startingPoints []]
|
||||
(let [&mut i 0]
|
||||
(doFor y (range PUZZLE_HEIGHT)
|
||||
(doFor x (range PUZZLE_WIDTH)
|
||||
(startingPoints.push
|
||||
(new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))
|
||||
(+= i 1))))
|
||||
(r.shuffle startingPoints)
|
||||
(set jigsaw j)
|
||||
(r.shuffle jigsaw.jigs)
|
||||
(localVar spriteGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) null)))
|
||||
(localVar indexGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) 0)))
|
||||
(doFor i (range (min TOTAL_PIECES (- p currentRewardFile.startingPoints)))
|
||||
(let [jig (nth jigsaw.jigs i)
|
||||
pos (ifLet [point (dictGet (the Map<Int,FlxPoint> save.data.storedPositions) i)]
|
||||
point
|
||||
(nth startingPoints i))
|
||||
s (new FlxExtendedSprite pos.x pos.y)
|
||||
source (new FlxSprite)
|
||||
mask (new FlxSprite)
|
||||
sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)]
|
||||
(set s.priorityID i)
|
||||
(setNth spriteGrid jig.row jig.col s)
|
||||
(setNth indexGrid jig.row jig.col i)
|
||||
(dictSet pieceData i jig)
|
||||
(dictSet indexMap s i)
|
||||
(dictSet spriteMap i s)
|
||||
(set s.draggable true)
|
||||
(s.enableMouseDrag false true)
|
||||
(set s.mouseStartDragCallback
|
||||
->:Void [s x y]
|
||||
{
|
||||
// Bring currently held pieces to the front:
|
||||
(rewardSprites.bringToFront s)
|
||||
(set s.priorityID (+ 1 .priorityID (last (the kiss.List<FlxExtendedSprite> rewardSprites.members))))
|
||||
(doFor connected (recursivelyConnectedPieces s)
|
||||
(rewardSprites.bringToFront connected))
|
||||
|
||||
(set draggingSprite s)
|
||||
(set draggingLastPos (new FlxPoint s.x s.y))
|
||||
})
|
||||
(set s.mouseStopDragCallback
|
||||
->:Void [s x y]
|
||||
{
|
||||
(set draggingSprite null)
|
||||
(checkMatches i)
|
||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) i (new FlxPoint s.x s.y))
|
||||
(doFor connected (recursivelyConnectedPieces s)
|
||||
(checkMatches (dictGet indexMap connected))
|
||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) (dictGet indexMap connected) (new FlxPoint connected.x connected.y)))
|
||||
|
||||
(set draggingSprite s)
|
||||
(set draggingLastPos (new FlxPoint s.x s.y))
|
||||
})
|
||||
(set s.mouseStopDragCallback
|
||||
->:Void [s x y]
|
||||
{
|
||||
(set draggingSprite null)
|
||||
(checkMatches i)
|
||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) i (new FlxPoint s.x s.y))
|
||||
(doFor connected (recursivelyConnectedPieces s)
|
||||
(checkMatches (dictGet indexMap connected))
|
||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) (dictGet indexMap connected) (new FlxPoint connected.x connected.y)))
|
||||
|
||||
(pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN)
|
||||
(save.flush)
|
||||
})
|
||||
|
||||
(source.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
||||
(source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))
|
||||
|
||||
(mask.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
||||
(drawPieceShape mask jig FlxColor.BLACK)
|
||||
(FlxSpriteUtil.alphaMask s source.pixels mask.pixels)
|
||||
(pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN)
|
||||
(save.flush)
|
||||
})
|
||||
|
||||
(source.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
||||
(source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))
|
||||
|
||||
(mask.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
||||
(drawPieceShape mask jig FlxColor.BLACK)
|
||||
(FlxSpriteUtil.alphaMask s source.pixels mask.pixels)
|
||||
|
||||
(set s.cameras [pieceCamera])
|
||||
(set s.cameras [pieceCamera])
|
||||
|
||||
(#when debug
|
||||
(let [matchZones [(matchZoneLeft s) (matchZoneRight s)(matchZoneUp s)(matchZoneDown s)]]
|
||||
(doFor z matchZones
|
||||
(FlxSpriteUtil.drawRect s (- z.x s.x) (- z.y s.y) z.width z.height FlxColor.TRANSPARENT (object thickness 1 color FlxColor.RED)))))
|
||||
(#when debug
|
||||
(let [matchZones [(matchZoneLeft s) (matchZoneRight s)(matchZoneUp s)(matchZoneDown s)]]
|
||||
(doFor z matchZones
|
||||
(FlxSpriteUtil.drawRect s (- z.x s.x) (- z.y s.y) z.width z.height FlxColor.TRANSPARENT (object thickness 1 color FlxColor.RED)))))
|
||||
|
||||
(rewardSprites.add s)))
|
||||
(rewardSprites.add s)))
|
||||
(doFor row (range PUZZLE_HEIGHT)
|
||||
(doFor col (range PUZZLE_WIDTH)
|
||||
(let [id (nth indexGrid row col)]
|
||||
@@ -279,7 +282,7 @@
|
||||
(dictSet matchingPiecesDown id toDown)) (catch [e] null)))))
|
||||
(add rewardSprites)
|
||||
(doFor i (range TOTAL_PIECES)
|
||||
(checkMatches i)))))
|
||||
(checkMatches i))))
|
||||
(set lastRewardFileIndex rewardFileIndex)
|
||||
|
||||
(pieceCamera.calculateScrollBounds rewardSprites uiCamera SCROLL_BOUND_MARGIN)
|
||||
|
Reference in New Issue
Block a user