diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index b4f7d0ce..edfee0fc 100644 Binary files a/desktop/resources/cursor.png and b/desktop/resources/cursor.png differ diff --git a/desktop/resources/pathfind-test-big.png b/desktop/resources/pathfind-test-big.png index d502853d..d6ae88dc 100644 Binary files a/desktop/resources/pathfind-test-big.png and b/desktop/resources/pathfind-test-big.png differ diff --git a/desktop/src-common/advent/core.clj b/desktop/src-common/advent/core.clj index 653f268b..326d751f 100644 --- a/desktop/src-common/advent/core.clj +++ b/desktop/src-common/advent/core.clj @@ -27,7 +27,7 @@ resized )) (defn right-click [screen entities] - (let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %)) :hotspot [63 63]))] + (let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %)) :hotspot [0 0 ]))] (input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0) entities)) @@ -48,9 +48,9 @@ :anim (animation 0.075 (for [i (range 8)] (texture (aget player-sheet 0 i)))) :baseline 95 - :origin-x 16 + :origin-x 0 + :origin-y 0 :x 150 :y 95 :x-velocity 1 - :character-x 158 :character-y 95 :id "ego"}] (merge (animation->texture screen (:anim ego)) ego))) @@ -60,28 +60,37 @@ [target-x target-y] (first target-path) target {:x target-x :y target-y}] (if (and target (seq target-path)) - (let [delta-x (- (:x target) (:character-x ego)) - delta-y (- (:y target) (:character-y ego)) + (let [scale-fn (-> entities :background :scale-fn) + delta-x (- (:x target) (:x ego)) + delta-y (- (:y target) (:y ego)) mag (Math/sqrt (+ (* delta-x delta-x) (* delta-y delta-y))) vector-x (* 1.5 (/ delta-x mag)) vector-y (* 1.5 (/ delta-y mag))] (if (< mag 1) (update-in ego [:target-path] rest) - (merge (as-> ego _ - (update-in _ [:x] #(+ % vector-x)) - (update-in _ [:y] #(+ % vector-y)) - (assoc-in _ [:character-x] (+ 8 (:x _))) - (assoc-in _ [:character-y] (:y _)) - (assoc-in _ [:baseline] (- 240 (:y _))) - (assoc-in _ [:anim] (if (< vector-x 0) - (:left _) - (:right _))) - (assoc-in _ [:scale-x] (/ 1 (/ 240 (- 310 (:y _))))) - (assoc-in _ [:scale-y] (/ 1 (/ 240 (- 310 (:y _)))))) - - (animation->texture screen (:anim ego))))) + (do + (merge (as-> ego _ + (update-in _ [:x] #(+ % vector-x)) + (update-in _ [:y] #(+ % vector-y)) + (assoc-in _ [:baseline] (- 240 (:y _))) + (assoc-in _ [:anim] (if (< vector-x 0) + (:left _) + (:right _))) + (assoc-in _ [:scale-x] (scale-fn (:y _))) + (assoc-in _ [:scale-y] (scale-fn (:y _)))) + + (animation->texture screen (:anim ego)))))) (merge (dissoc ego :target-path) (texture (animation! (:anim ego) :get-key-frame 0.6)))))) + +(defn scaler-fn-with-baseline [baseline minimum-size & [maximum-size]] + (let [maximum-size (or maximum-size 1.0)] + (fn [y] + (if (< y baseline) maximum-size + (let [percent-complete (- 1.0 (/ (- y baseline) (- +screen-height+ baseline))) + range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)] + range))))) + (defscreen main-screen :on-show (fn [screen entities] @@ -98,7 +107,8 @@ :background (assoc background :id "background" :x 0 :y 0 :collision (advent.pathfind/map-from-resource "pathfind-test-big.png") - :baseline 0) + :baseline 0 + :scale-fn (scaler-fn-with-baseline 110 0.10 1.10)) :house (assoc house :x 0 :y 0 :baseline 122)