From df67fa06e0fbe7b84920762b58db8993c82444a2 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 17 Aug 2022 00:40:36 +0000 Subject: [PATCH] prompt for puzzle size and piecesPerPoint --- .../source/HabitState.hx | 2 + .../source/HabitState.kiss | 64 ++++++++++++++----- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx index 22a04187..9deba3d5 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx @@ -40,6 +40,8 @@ import jigsawx.JigsawPiece; import jigsawx.Jigsawx; import jigsawx.math.Vec2; +typedef StartPuzzleFunc = (Int, Int) -> Void; + @:build(kiss.Kiss.build()) class HabitState extends FlxState { public function drawPieceShape( surface: FlxSprite, jig: JigsawPiece, scale:Float, c: FlxColor ) diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index 98b6cb7b..2840c1e1 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -174,7 +174,7 @@ // Main.hx sets off 99% of the app's logic by parsing the model file and calling setModel on startup and on a 30s loop: -(method setModel [m &opt :RewardFile currentRewardFile] +(method :Void setModel [m &opt :RewardFile currentRewardFile] (set model m) (set shortcutHandler (new FlxKeyShortcutHandler)) @@ -538,7 +538,6 @@ (prop &mut :FlxGroup nextPuzzleChoiceGroup null) -(var BASE_PUZZLE_SIZE 5) (method startPuzzlePackChoice [nextStartingPoints] (unless nextPuzzleChoiceGroup (set nextPuzzleChoiceGroup (new FlxGroup)) @@ -553,23 +552,56 @@ (set text.color FlxColor.LIME) (nextPuzzleChoiceGroup.add text) (whenLet [(Some np) pack.nextPuzzle] - (nextPuzzleChoiceGroup.add (new FlxButton (+ x text.width) y "CHOOSE" ->:Void { - (remove nextPuzzleChoiceGroup) - (set nextPuzzleChoiceGroup null) - (let [bmd (BitmapData.fromFile np.path) - aspectRatioX (/ bmd.width bmd.height) - aspectRatioY (/ bmd.height bmd.width) - w (max 1 (Math.round (* aspectRatioX BASE_PUZZLE_SIZE))) - h (max 1 (Math.round (* aspectRatioY BASE_PUZZLE_SIZE)))] - (model.addRewardFile np.path nextStartingPoints w h 1)) - - - (setModel model) - - })))) + (nextPuzzleChoiceGroup.add + (new FlxButton (+ x text.width) y "CHOOSE" ->:Void { + (remove nextPuzzleChoiceGroup) + (set nextPuzzleChoiceGroup null) + (startPuzzleSizeChoice + ->[chosenSize pointsPerPiece] + (let [bmd (BitmapData.fromFile np.path) + aspectRatioX (/ bmd.width bmd.height) + aspectRatioY (/ bmd.height bmd.width) + w (max 1 (Math.round (* aspectRatioX chosenSize))) + h (max 1 (Math.round (* aspectRatioY chosenSize)))] + (model.addRewardFile np.path nextStartingPoints w h pointsPerPiece) + (setModel model))) + })))) (+= y textSize))) (add nextPuzzleChoiceGroup))) +(var MIN_PUZZLE_SIZE 5) +(var MAX_PUZZLE_SIZE 32) +(var PUZZLE_SIZE_OPTIONS (collect (range MIN_PUZZLE_SIZE MAX_PUZZLE_SIZE 2))) +(method startPuzzleSizeChoice [:StartPuzzleFunc startPuzzle] + (set nextPuzzleChoiceGroup (new FlxGroup)) + (set nextPuzzleChoiceGroup.cameras [uiCamera]) + (add nextPuzzleChoiceGroup) + (let [x 0 &mut y 0 &mut :FlxButton b null] + // TODO also limit puzzle size by rewardSprite dimensions + (doFor size PUZZLE_SIZE_OPTIONS + (set b (new FlxButton x y "$(* size size)" ->:Void { + (remove nextPuzzleChoiceGroup) + (startPiecesPerPointChoice size startPuzzle) + })) + (nextPuzzleChoiceGroup.add b) + (+= y b.height)))) + +(method startPiecesPerPointChoice [size :StartPuzzleFunc startPuzzle] + (set nextPuzzleChoiceGroup (new FlxGroup)) + (set nextPuzzleChoiceGroup.cameras [uiCamera]) + (add nextPuzzleChoiceGroup) + (let [x 0 &mut y 0 maxPPP (Math.round (/ (* size size) (* MIN_PUZZLE_SIZE MIN_PUZZLE_SIZE))) &mut :FlxButton b null] + (when (= maxPPP 1) + (startPuzzle size 1) + (return)) + (doFor points (range 1 maxPPP) + (set b (new FlxButton x y "$points" ->:Void { + (remove nextPuzzleChoiceGroup) + (startPuzzle size points) + })) + (nextPuzzleChoiceGroup.add b) + (+= y b.height)))) + (function pointsStr [points] (let [tallyUnit 5] (+ (* "*" (Math.floor (/ points tallyUnit)))