diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index 8ded96a2..9e0ef7d3 100644 Binary files a/desktop/resources/cursor.png and b/desktop/resources/cursor.png differ diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 527d116b..80b35bad 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -9,6 +9,7 @@ [advent.pathfind] [advent.actions :as actions] [advent.screens.dialogue :as dialogue] + [advent.utils :as utils] [clojure.core.async :refer [put! ! >!! chan go thread take! alts!!]]) (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter] [com.badlogic.gdx.graphics.g2d TextureRegion] @@ -53,11 +54,6 @@ (update-in entities [:room :entities target-id] #(start-animation screen % :stand))) -(defn dist [x1 y1 x2 y2] - (let [dx (- x1 x2) - dy (- y1 y2)] - (Math/sqrt (+ (* dx dx) (* dy dy))))) - (defmacro run-action [entities & forms] `(let [c# (chan)] (do @@ -79,7 +75,7 @@ (let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])] (let [delta-x (- final-x from-x) delta-y (- final-y from-y) - distance (dist from-x from-y final-x final-y) + distance (utils/dist from-x from-y final-x final-y) speed (* (or scale-x 1.0) 1.5) moved-x (if (= 0.0 distance) 0 @@ -102,7 +98,7 @@ (done? [this screen entities] (let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])] - (< (dist final-x final-y from-x from-y) 1))) + (< (utils/dist final-x final-y from-x from-y) 1))) (terminate [this screen entities] (stop screen entities target-id)) @@ -131,7 +127,7 @@ [[target-x target-y] remainder] @targets-left] (let [delta-x (- target-x from-x) delta-y (- target-y from-y) - distance (dist from-x from-y target-x target-y) + distance (utils/dist from-x from-y target-x target-y) speed (* (or scale-x 1.0) 1.5) moved-x (if (= 0.0 distance) 0 @@ -155,7 +151,7 @@ (done? [this screen entities] (let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])] - (< (dist final-x final-y from-x from-y) 1))) + (< (utils/dist final-x final-y from-x from-y) 1))) (terminate [this screen entities] (stop screen entities target-id)) diff --git a/desktop/src-common/advent/screens/rooms/outside_house.clj b/desktop/src-common/advent/screens/rooms/outside_house.clj index 81657eef..79e813a0 100644 --- a/desktop/src-common/advent/screens/rooms/outside_house.clj +++ b/desktop/src-common/advent/screens/rooms/outside_house.clj @@ -8,6 +8,16 @@ [play-clj.utils :refer :all] [play-clj.g2d :refer :all])) +(def ego-sheep-loc + [132 140]) + +(defn dist-to-sheep [entities] + (apply utils/dist (get-in entities [:room :entities :sheep :x]) (get-in entities [:room :entities :sheep :y]) + ego-sheep-loc)) + +(defn is-sheep-close? [entities] + (< (dist-to-sheep entities) 45)) + (defn wizard-dialogue [entities] (actions/do-dialogue entities :ego "Hello there Mr. Fangald!" :wizard "Oh no, not you again!") (actions/present-choices entities @@ -152,19 +162,27 @@ :box [38 160 71 181] :script (actions/get-script entities + + (if ((get-in @entities [:state :inventory]) :wool) (actions/talk entities :ego "The sheep has given me enough wool.") - (do (actions/give entities :wool) - (actions/talk entities :ego "I guess her wool is shedding.")))) + (if (is-sheep-close? @entities) + (do (actions/walk-to entities :ego ego-sheep-loc) + (actions/give entities :wool) + (actions/talk entities :ego "I guess her wool is shedding.")) + (actions/talk entities :ego "She's too far away for me to pet her.")))) :scripts {:wool (actions/get-script entities (actions/talk entities :ego "She doesn't need it back.")) :carrot (actions/get-script entities - (actions/walk-to entities :ego [132 140]) + (actions/walk-to entities :ego ego-sheep-loc) (actions/talk entities :ego "Come on girl, get the carrot!") (actions/walk-straight-to entities :sheep [95 150])) :flask (actions/get-script entities - (actions/give entities :flask-with-contents) - (actions/talk entities :ego "Sheeps milk."))} + (if (is-sheep-close? @entities) + (do (actions/walk-to entities :ego ego-sheep-loc) + (actions/give entities :flask-with-contents) + (actions/talk entities :ego "Sheeps milk.")) + (actions/talk entities :ego "She's too far away.")))} :left {:walk (utils/flip sheep-walk) :stand (utils/flip sheep-stand)} :right {:walk sheep-walk diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index e21aa86c..5c9c8a5e 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -133,7 +133,7 @@ (update! screen :renderer (stage) :camera (orthographic)) (let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) music (sound "town-music.mp3") - _ (sound! music :loop 0.80) + ;; _ (sound! music :loop 0.80) rooms {:inside-house (rooms.inside-house/make screen) :outside-house (rooms.outside-house/make screen) :behind-house (rooms.behind-house/make screen) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index bac04070..f4d5c165 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -44,6 +44,12 @@ range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)] range))))) +(defn dist [x1 y1 x2 y2] + (let [dx (- x1 x2) + dy (- y1 y2)] + (Math/sqrt (+ (* dx dx) (* dy dy))))) + + (defn flip [anim] (animation (animation! anim :get-frame-duration) (for [src-frame (animation! anim :get-key-frames)