From b300ff109cf01932caa1e8eb8580a6c1feef4e6f Mon Sep 17 00:00:00 2001 From: = Date: Wed, 3 Sep 2014 12:49:01 -0700 Subject: [PATCH] simple scaling. --- desktop/resources/cursor.png | Bin 1790 -> 1796 bytes desktop/src-common/advent/core.clj | 60 ++++++++++++++++++----------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index a2f14807170fcd6ed80211bbb9361e9c71422882..b4f7d0ced4cb74d5730589c2403adb61bf453b6b 100644 GIT binary patch delta 701 zcmV;u0z&=%4TKJ`R0MyUNklzM5;|2>D~M$zHyj4bKf0$ zzH;EbbMBdQ=FInv>j(j=lVLvx8;4IwO z_;~uhKmb4-@7}Iu$c7P15<=o?=?n02rQ-aNn1*Tz?_9g2TqvvgbAILVGpheY0${ON z^ybDKe7r|s@WygfJ|U`o0H*P1mv^!Cn)tTx+}Xa!*S!01dJ9{ddN4h$EvNeWwC*JU z9ydEj#*}x#N&Dm4C^WV?#Q7Z~tedFHb#{*Ol|~<2H7JLTU^Xe7t%xuGa3ZJAm=H1aS|b3ozIT&;cHIKw3Qf_}06gLlAO0my1%t zfB=BUVi+KyUIZXtt)9V|QYq#U0PwMi31NqLUjb~uH9|-*Z+v^LYSn{(=v!~+AaH;# z6bfpZ!0D^2O9Q3Z{rMjT zakp(m9=<&+(y@Q}@pDcGRYL*zU!Rtpsc^h}?iYeKiNNAc0&cvk3l(@{3yqlr;kUvE zFXpjPvx7|C1_1uMTaQa!@we+a*I6Tcl}|9N$Y8UBFIY z?ic}B6qR4S@FG@eRR86ncE)at1bBeM012%8%JLCq0||@MquQ>Fjz6>NQQ!=T5rDR| zfoH(}k@*-goU4RH2mE-yb@o~H#;;@2+O$^z@9rNK*pmj|d6GaGjY$O4on2M!zBtns z9F_Y@e%s~-G)-}-0{0te_^ zE~lmmoW8ocG*FuDPaC8U0XPO`EOZ=;G~lCgzTYowf5t_D)9#d4v-Ppf!x?thoO7|A dIPt##-2lFaFp>kI54!*W002ovPDHLkV1m)$SiArL diff --git a/desktop/src-common/advent/core.clj b/desktop/src-common/advent/core.clj index 67805f86..653f268b 100644 --- a/desktop/src-common/advent/core.clj +++ b/desktop/src-common/advent/core.clj @@ -27,16 +27,17 @@ resized )) (defn right-click [screen entities] - (let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %))))] - (input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0 ) + (let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %)) :hotspot [63 63]))] + (input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0) entities)) (defn left-click [screen entities] - (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] - (assoc-in entities [:ego :target-path] (take-nth 2 (advent.pathfind/visit-all - (:collision (:background entities)) - [(int (:x (:ego entities))) (int (:y (:ego entities)))] - [(int x) (int y)]))))) + (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)}) + path (vec (take-nth 2 (advent.pathfind/visit-all + (:collision (:background entities)) + [(int (:x (:ego entities))) (int (:y (:ego entities)))] + [(int x) (int y)])))] + (assoc-in entities [:ego :target-path] (when (seq path) (conj path [x y]))))) (defn get-ego [screen] (let [player-sheet (texture! (texture "player.png") :split 18 36) @@ -47,7 +48,9 @@ :anim (animation 0.075 (for [i (range 8)] (texture (aget player-sheet 0 i)))) :baseline 95 - :x 150 :y 95 :x-velocity 1 + :origin-x 16 + :x 150 :y 95 :x-velocity 1 + :character-x 158 :character-y 95 :id "ego"}] (merge (animation->texture screen (:anim ego)) ego))) @@ -57,23 +60,28 @@ [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) (:x ego)) - delta-y (- (:y target) (:y ego)) + (let [delta-x (- (:x target) (:character-x ego)) + delta-y (- (:y target) (:character-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 (-> ego - (update-in [:x] #(+ % vector-x)) - (update-in [:y] #(+ % vector-y)) - (assoc-in [:baseline] (- 240 (:y ego))) - (assoc-in [:anim] (if (< vector-x 0) - (:left ego) - (:right ego)))) + (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))))) - (dissoc ego :target-path)))) + (merge (dissoc ego :target-path) (texture (animation! (:anim ego) :get-key-frame 0.6)))))) (defscreen main-screen :on-show (fn [screen entities] @@ -82,8 +90,11 @@ _ (input! :set-cursor-image (cursor "cursor.png" 0) 0 0) background (texture "bg5.png") house (texture "house.png") - overdirt (texture "overdirt.png")] - {:cursor {:id "cursor" :cursor-index 0} + overdirt (texture "overdirt.png") + music (sound "outside-house.mp3") + _ (sound! music :loop)] + { + :cursor {:id "cursor" :cursor-index 0 :hotspot [63 63]} :background (assoc background :id "background" :x 0 :y 0 :collision (advent.pathfind/map-from-resource "pathfind-test-big.png") @@ -109,9 +120,12 @@ :on-touch-down (fn [screen [entities]] - (if (= (button-code :right) (:button screen)) - (right-click screen entities) - (left-click screen entities)))) + (let [screen (-> screen + (update-in [:input-x] #(+ % (first (:hotspot (:cursor entities))))) + (update-in [:input-y] #(+ % (second (:hotspot (:cursor entities))))))] + (if (= (button-code :right) (:button screen)) + (right-click screen entities) + (left-click screen entities))))) (defgame advent :on-create